Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Installing a module that is perl-version specific

by chuckbutler (Prior)
on Apr 01, 2010 at 01:23 UTC ( #832177=note: print w/replies, xml ) Need Help??


in reply to Re: Installing a module that is perl-version specific
in thread Installing a module that is perl-version specific

Building on the submission by ikegami:

package Date::Manip; use warnings; use strict; use Carp; use Exporter; # our @ISA; our @EXPORT; my $backend; if ($] >= 5.010) { $backend = 'Date::Manip::Perl5010'; } elsif ($] >= 5.008) { $backend = 'Date::Manip::Perl5008'; } elsif ($] >= 5.006) { $backend = 'Date::Manip::Perl5006'; } else { croak("Perl $] isn't supported\n"); } my $backend_exp = $backend . "::EXPORT"; eval "require $backend; $backend->import(); return 1;" or croak "$@ +"; { no strict qq{refs}; @EXPORT = @{$backend_exp}; } unshift (@ISA, $backend); # 1;

We pick the correct version of the module to use. Then load the module file and import the symbols dynamically, with an eval. Then we setup the @EXPORT list so it is available when the ->import() subroutine runs as part of use, the symbols are imported into Main::.

Update and Postscript:

If the package statement in the per-version Date::Manip's are left as-is, the following code is preferred:

package Date::Manip; use warnings; use strict; use Carp; use Exporter; # my $backend; if ($] >= 5.010) { $backend = 'Date::Manip::Perl5010'; } elsif ($] >= 5.008) { $backend = 'Date::Manip::Perl5008'; } elsif ($] >= 5.006) { $backend = 'Date::Manip::Perl5006'; } else { croak("Perl $] isn't supported\n"); } eval "require $backend; " or croak "$@"; # 1;

This should work well.

Good luck. -c

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://832177]
help
Chatterbox?
[Corion]: Yeah, but the hope is that when I just delete it I won't receive any more mail from them
[Corion]: ... a faint hope, I know
[Discipulus]: ah ah you are still so optimist, Corion ? ;=)
[Discipulus]: here we are a bit late: i'll inject a ransomware to crypt everything and be compliant

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2018-05-25 07:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?