use vars qw/$VERSION %released %version %families %upstream
%bug_tracker %deprecated/;
use Module::CoreList::TieHashDelta;
-$VERSION = '2.98';
+$VERSION = '2.99';
my $dumpinc = 0;
sub import {
},
);
+sub is_core
+{
+ my $module = shift;
+ $module = shift if eval { $module->isa(__PACKAGE__) } && @_ > 0 && defined($_[0]) && $_[0] =~ /^\w/;
+ my ($module_version, $perl_version);
+
+ $module_version = shift if @_ > 0;
+ $perl_version = @_ > 0 ? shift : $^V;
+
+ my $first_release = first_release($module);
+
+ return 0 if !defined($first_release) || $first_release > $perl_version;
+
+ my $final_release = removed_from($module);
+
+ return 0 if defined($final_release) && $perl_version > $final_release;
+
+ # If a minimum version of the module was specified:
+ # Step through all perl release numbers ($prn)
+ # in order, so we can find what version of the module
+ # was included in the specified version of perl.
+ # On the way if we pass the required module version, we can
+ # short-circuit and return true
+ if (defined($module_version)) {
+ RELEASE:
+ foreach my $prn (sort keys %delta) {
+ next RELEASE if $prn <= $first_release;
+ last RELEASE if $prn > $perl_version;
+ next unless defined(my $next_module_version
+ = $delta{$prn}->{changed}->{$module});
+ return 1 if $next_module_version >= $module_version;
+ }
+ return 0;
+ }
+
+ return 1 if !defined($final_release);
+
+ return $perl_version <= $final_release;
+}
+
for my $version (sort { $a <=> $b } keys %delta) {
my $data = $delta{$version};
print Module::CoreList->first_release_by_date('File::Spec'); # prints 5.005
print Module::CoreList->first_release('File::Spec', 0.82); # prints 5.006001
+ if (Module::CoreList::is_core('File::Spec')) {
+ print "File::Spec is a core module\n";
+ }
+
print join ', ', Module::CoreList->find_modules(qr/Data/);
# prints 'Data::Dumper'
print join ', ', Module::CoreList->find_modules(qr/test::h.*::.*s/i, 5.008008);
Takes a perl version as an argument. Returns that perl version if it exists or C<undef>
otherwise.
+=item C<is_core( MODULE, [ MODULE_VERSION, [ PERL_VERSION ] ] )>
+
+Available in version 2.99 and above.
+
+Returns true if MODULE was bundled with the specified version of Perl.
+You can optionally specify a minimum version of the module,
+and can also specify a version of Perl.
+If a version of Perl isn't specified,
+C<is_core()> will use the version of Perl that is running (ie C<$^V>).
+
+If you want to specify the version of Perl, but don't care about
+the version of the module, pass C<undef> for the module version:
+
=item C<is_deprecated( MODULE, PERL_VERSION )>
Available in version 2.22 and above.
--- /dev/null
+#!perl -w
+use strict;
+use Module::CoreList;
+use Test::More tests => 23;
+
+BEGIN { require_ok('Module::CoreList'); }
+
+ok(!Module::CoreList::is_core('Module::Path'), 'Module::Path has never been in core');
+ok(!Module::CoreList::is_core('Module::Path', undef, '5.016003'), 'Module::Path has never been in core');
+ok(!Module::CoreList::is_core('Module::Path', undef), 'Module::Path has never been in core');
+
+# List::Util::PP was added in 5.010001 and removed in 5.017001
+ok(!Module::CoreList::is_core('List::Util::PP', undef, '5.002'), 'List::Util::PP was added in 5.10.1 so not in core in 5.002');
+ok(Module::CoreList::is_core('List::Util::PP', undef, '5.016003'), 'List::Util::PP was in core in 5.16.3');
+ok(!Module::CoreList::is_core('List::Util::PP', undef, '5.018001'), 'List::Util::PP was removed in 5.17.1 so not in core in 5.18.1');
+
+# Carp has always been a core module
+ok(Module::CoreList::is_core('Carp', undef, '5'), 'Carp was a core module in first release of perl 5');
+ok(Module::CoreList::is_core('Carp', undef, '5.019004'), 'Carp was still a core module in 5.19.4');
+ok(Module::CoreList::is_core('Carp'), "Carp should be a core module whatever version of perl you're running");
+
+ok(Module::CoreList::is_core('attributes', undef, '5.00503') == 0, "attributes weren't in 5.00503");
+ok(Module::CoreList::is_core('attributes', undef, '5.006001') == 1, "attributes were in 5.6.1");
+ok(Module::CoreList::is_core('Pod::Plainer', undef, '5.012001') == 1, "Pod::Plainer was core in 5.12.1");
+ok(Module::CoreList::is_core('Pod::Plainer', undef, '5.016003') == 0, "Pod::Plainer was removed in 5.13.1");
+
+# history of module 'encoding' in core
+# version 1.00 included in 5.007003
+# version 1.35 included in 5.008
+# version 1.47 included in 5.008001
+# version 1.48 included in 5.008003
+# version 2.00 included in 5.008005
+# version 2.01 included in 5.008006
+# version 2.02 included in 5.008008
+# version 2.6_01 included in 5.008009
+# version 2.04 included in 5.009004
+# version 2.06 included in 5.009005
+# version 2.6_01 included in 5.010001
+# version 2.12 included in 5.019001
+
+ok(!Module::CoreList::is_core('encoding', undef, '5'), "encoding wasn't in core in first release of perl 5");
+ok(!Module::CoreList::is_core('encoding', '1.00', '5'), "encoding 1.00 wasn't in core in first release of perl 5");
+ok(!Module::CoreList::is_core('encoding', '1.35', '5.007003'), "encoding 1.35 wasn't yet in core in perl 5.007003");
+ok(Module::CoreList::is_core('encoding', '1.35', '5.008'), "encoding 1.35 was first included in perl 5.008");
+ok(Module::CoreList::is_core('encoding', '1.35', '5.009004'), "encoding 2.04 (>1.35) was included in 5.009004");
+ok(Module::CoreList::is_core('encoding', '2.01', '5.008007'), "encoding 2.01 was first in core in perl 5.008006, so was core in 5.8.7");
+ok(Module::CoreList->is_core('encoding', '2.01', '5.008007'), "encoding 2.01 was first in core in perl 5.008006, so was core in 5.8.7");
+
+# Module::CoreList (2.17) was first included in 5.008009
+ok(!Module::CoreList::is_core('Module::CoreList', undef, '5.007003'), "Module::CoreList wasn't core in perl 5.7.3");
+ok(!Module::CoreList->is_core('Module::CoreList', undef, '5.007003'), "Module::CoreList wasn't core in perl 5.7.3 (class method)");
+