Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Installing a module that is perl-version specific

by SBECK (Chaplain)
on Mar 31, 2010 at 19:24 UTC ( [id://832130]=perlquestion: print w/replies, xml ) Need Help??

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

I recently released Date::Manip 6.xx which requires perl 5.10 (Date::Manip 5.xx works fine on perl 5.6 and probably earlier versions). NOTE: I'm still supporting the 5.xx releases for users who don't have perl 5.10 .

The problem is that now the automatic installers are failing. If you try to upgrade Date::Manip and you're running perl 5.6/5.8, it'll try the newest version which will fail, and it'll report that it couldn't install Date::Manip. Of course, you can manually specify to use the newest of the 5.xx releases, and that works fine, but I'd like to fix this problem in a better way.

I'm not interested in renaming the module to Date::Manip6 (or some other variation), but I'm considering packaging both the 5.xx and 6.xx releases in the 6.xx package and then fixing the Makefile.PL/Build.PL to install the correct one based on the perl version.

Is this a valid/good/poor/unacceptable solution to the problem? Will it solve one problem only to create another? If there's a better way to solve the problem please let me know. NOTE: backing out the changes that require 5.10 isn't an option that I'm willing to consider.

I'm not 100% sure how to do it, but I'm sure it won't be hard to figure it out, but if there's already a module out there that does this, I'd be interested in a note so that I can see an example of it already being done.

Thanks

  • Comment on Installing a module that is perl-version specific

Replies are listed 'Best First'.
Re: Installing a module that is perl-version specific
by ikegami (Patriarch) on Mar 31, 2010 at 20:08 UTC

    You could have a front end (interface) that loads the appropriate back end (work horse) based on $].

    BEGIN { my $backend; if ($] >= 5.010) { $backend = 'Data::Manip::Perl5010'; } elsif ($] >= 5.008) { $backend = 'Data::Manip::Perl5008'; } elsif ($] >= 5.006) { $backend = 'Data::Manip::Perl5006'; } else { die("Perl $] isn't supported\n"); } eval "require $backend" or die $@; our @ISA = $backend; }

    [ Oops, Date::Manip is a procedural module, so you'll have to use AUTOLOAD or use package Date::Manip; in each of the helper modules instead of using @ISA. ]

      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
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://832130]
Approved by GrandFather
Front-paged by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-19 06:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found