A quick and dirty script to interrogate Module::CoreList and find out what version of a module is included in the core for each major version of perl. Good for figuring out Which version to target for module dependencies?
#!/usr/bin/perl use warnings; use strict; use Module::CoreList; # find the highest subversion of perl in a family: e.g. 5.008007 for 5 +.008 sub highest_subversion { my ($perl_version, $module) = @_; # find the highest perl release for this version of perl return [reverse sort @{$Module::CoreList::families{$perl_version}} +]->[0]; } # find what version of a module is in a specific version of perl sub core_version { my ($perl_version, $module) = @_; if ( exists $Module::CoreList::version{$perl_version}{$module} ) { return $Module::CoreList::version{$perl_version}{$module}; } else { return; } } # print out the history of when a module was included in various perl +releases sub module_history { my ($module) = @_; my $in_core = Module::CoreList->first_release($module); if ($in_core) { print "$module version(s): \n"; for my $version (qw( 5.004 5.005 5.006 5.008 )) { my $subversion = highest_subversion( $version ); my $core_version = core_version( $subversion, $module); $core_version = "unknown version" unless $core_version; print " $core_version in perl $subversion\n"; } } else { print "$module: never released in core\n" } } module_history(shift @ARGV);

Replies are listed 'Best First'.
Re: Find version of a module included in perl core
by merlyn (Sage) on Aug 18, 2005 at 15:59 UTC
    Are you rewriting the corelist commandline tool that comes with Module::CoreList for any particular reason?
    $ corelist File::Spec File::Spec was first released with perl 5.005 $ corelist File::Spec 0.83 File::Spec 0.83 was released with perl 5.007003 $ corelist File::Spec 0.89 File::Spec 0.89 was not in CORE (or so I think) $ corelist File::Spec::Aliens File::Spec::Aliens was not in CORE (or so I think)

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Yes, though I'd forgotten about corelist as I'd stopped using it. I wrote a more specialized version because I'm interested in the history of the module, not when it was first released, and then only for particular versions of perl that I might be targeting. (I actually use a variant to spit out my "require" lines for Build.PL with comments about when various versions became available.) Using 'corelist -a File::Spec' to give the full history is another option of course. E.g. (and note the "off-by-one" bug):

      $ corelist -a File::Spec File::Spec was first released with perl 5.005 5.00405 0.6 5.005 0.6 5.00503 0.6 5.00504 0.8 5.006 0.8 5.006001 0.82 5.006002 0.86 5.007003 0.83 5.008 0.83 5.008001 0.86 5.008002 0.86 5.008003 0.87 5.008004 0.87 5.008005 0.87 5.008006 3.01 5.008007 3.05 5.009 0.86 5.009001 0.87 5.009002 3.05 $ ./coremodule-history.pl File::Spec File::Spec version(s): 0.6 in perl 5.00405 0.8 in perl 5.00504 0.86 in perl 5.006002 3.05 in perl 5.008007

      The other thing is that corelist only shows where a module was included and had a version, and not all core modules had versions until recently. My snippet handles that.

      $ corelist -a Test::Simple Test::Simple was first released with perl 5.007003 5.006002 0.47 5.007003 0.41 5.008 0.45 5.008001 0.47 5.008002 0.47 5.008003 0.47 5.008004 0.47 5.008005 0.47 5.008006 0.47 5.008007 0.54 5.009 0.47 5.009001 0.47 5.009002 0.54 $ ./coremodule-history.pl Test::Simple Test::Simple version(s): unknown version in perl 5.00405 unknown version in perl 5.00504 0.47 in perl 5.006002 0.54 in perl 5.008007

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.