Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Run-time equivalent of "use Module VERSION"?

by Anonymous Monk
on Jul 04, 2014 at 07:38 UTC ( #1092253=perlquestion: print w/replies, xml ) Need Help??

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

Greetings Monks,

What is the best run-time equivalent of use Module VERSION? eval "use Module 1.23" works but it involves string eval. require Module; Module->import(1.23) doesn't work. require Module; Module->VERSION(1.23) works only for modules which install a VERSION() method.

Replies are listed 'Best First'.
Re: Run-time equivalent of "use Module VERSION"?
by Corion (Patriarch) on Jul 04, 2014 at 07:50 UTC

    VERSION is magic and always there for you:

    > perl -wle "package VersionTest; use vars qw($VERSION); $VERSION=666; + package main; print VersionTest->VERSION(666); print VersionTest->VE +RSION(667);" 666 VersionTest verion 667 required--this is only version 666 at -e line 1 +.
      > VERSION is magic and always there for you:

      elaborating a bit from perlobj#VERSION($need) :)

      UNIVERSAL::VERSION() is like ->can() a "universal" method and ...

      This method is called automatically by the "VERSION" form of "use".
      use A 1.2 qw(some imported subs); # implies: A->VERSION(1.2);

      Cheers Rolf

      (addicted to the Perl Programming Language)

      ) All classes automatically inherit from the UNIVERSAL class, which is built-in to the Perl core.

Re: Run-time equivalent of "use Module VERSION"?
by CountZero (Bishop) on Jul 04, 2014 at 13:50 UTC
    Module->VERSION(1.23) works only for modules which install a VERSION() method.

    That is not entirely true as LanX already explained. However, it assumes that the module provides in some standard way a version number that can be understood and compared. In that respect nothing is guaranteed.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
Re: Run-time equivalent of "use Module VERSION"?
by DrHyde (Prior) on Jul 04, 2014 at 12:10 UTC
    So what if it involves string eval?
Re: Run-time equivalent of "use Module VERSION"?
by McA (Priest) on Jul 04, 2014 at 09:54 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2023-02-08 16:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (42 votes). Check out past polls.

    Notices?