Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

How do I require a specific version?

by jk2addict (Chaplain)
on Jul 26, 2005 at 23:26 UTC ( #478411=perlquestion: print w/replies, xml ) Need Help??

jk2addict has asked for the wisdom of the Perl Monks concerning the following question:

I'm currently between a rock and a hard place and I want to do something e-vil to work around the problem.

I'm currently using Module::Pluggable in Handel to load plugins for the checkout process. It currently loads all available plugins in any given namespace, but I'm tweaking the config to ignore specified plugins, or also to load just the listed plugins. Module::Pluggable currently has the except and only options available in its use statement.

Normally, this would be a no brainer...change my use statement in the begin block to a require/import during new() and pass the appropriate oprions from the config into except/only.

However, currently my use statement also specifies a minimum version of M::P of 2.9. Is there some special encantation whereby you can pass the version into require or into import()?

Sure, I suppose I could just die after require if M::P->VERSION is lower than 2.9, but I was looking for something cleaner, something closer to use Module::Pluggable 2.9;

Replies are listed 'Best First'.
Re: How do I require a specific version?
by ikegami (Patriarch) on Jul 27, 2005 at 01:14 UTC

    Exporter provides import for most modules, and Exporter's import has support for version checking. However, Module::Pluggable does not use Exporter. It has a custom import which doesn't provide support for version checking.

    Looking into Exporter, I see it calls the function VERSION from UNIVERSAL, so all you have to do is:

    BEGIN { require Module::Pluggable; Module::Pluggable->VERSION(2.9); } use Module::Pluggable ...your usual args...;

    That's the first I've heard of the UNIVERSAL::VERSION function. neat!

      Big duh. I never though that VERSION took an argument.

      VERSION ( [ REQUIRE ] )
      VERSION will return the value of the variable $VERSION in the package the object is blessed into. If REQUIRE is given then it will do a comparison and die if the package version is not greater than or equal to REQUIRE. VERSION can be called as either a class (static) method, an object method or a function.
Re: How do I require a specific version?
by jk2addict (Chaplain) on Jul 27, 2005 at 01:20 UTC

    "Reputation: -1"? Sigh. :-)

    I went another route. I submitted a patch to M::P to create only/except subs. I'm working on patching the *.t files now. Now I'll have to wait on that feature to hopefully make it into a M::P release before I can release, but it will be worth it in the end.

Re: How do I require a specific version?
by bsb (Priest) on Jul 27, 2005 at 06:57 UTC
    The only module may help:
    only - Load specific module versions; Install many
Re: How do I require a specific version?
by data64 (Chaplain) on Jul 30, 2005 at 23:04 UTC

    You could put the "use" statement inside an eval block. This will let you conditionally include the module and also let you do the version checking.

    Update:

    I didn't realize that op had not tried the version argument to use. I assumed that op wanted to do more things and handle the error. In hindsight, bad assumption.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://478411]
Front-paged by bradcathey
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2022-01-21 06:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (57 votes). Check out past polls.

    Notices?