summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MANIFEST1
-rw-r--r--dist/Module-CoreList/Changes3
-rw-r--r--dist/Module-CoreList/MANIFEST1
-rw-r--r--dist/Module-CoreList/lib/Module/CoreList.pm42
-rw-r--r--dist/Module-CoreList/lib/Module/CoreList.pod17
-rw-r--r--dist/Module-CoreList/t/is_core.t52
-rw-r--r--pod/perldelta.pod7
7 files changed, 121 insertions, 2 deletions
diff --git a/MANIFEST b/MANIFEST
index 66cadf144f..a0e1c4a166 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -3357,6 +3357,7 @@ dist/Module-CoreList/README Module::CoreList
dist/Module-CoreList/t/corelist.t Module::CoreList tests
dist/Module-CoreList/t/deprecated.t Module::CoreList tests
dist/Module-CoreList/t/find_modules.t Module::CoreList tests
+dist/Module-CoreList/t/is_core.t Module::CoreList tests
dist/Module-CoreList/t/pod.t Module::CoreList tests
dist/Module-CoreList/t/utils.t Module::CoreList tests
dist/Net-Ping/Changes Net::Ping
diff --git a/dist/Module-CoreList/Changes b/dist/Module-CoreList/Changes
index fecb700cea..1c7272a142 100644
--- a/dist/Module-CoreList/Changes
+++ b/dist/Module-CoreList/Changes
@@ -1,6 +1,9 @@
2.99
- fixed Module::Build core deprecation
- changes_between now has the same API as all other functions
+ - added is_core() which returns true if a module is/was core
+ in a specific version of Perl. Can optionally specify minimum
+ version of the module.
2.98 Wed Aug 21 2013
- Prepared for v5.19.4
diff --git a/dist/Module-CoreList/MANIFEST b/dist/Module-CoreList/MANIFEST
index ec9ea020f2..9b2b2020e6 100644
--- a/dist/Module-CoreList/MANIFEST
+++ b/dist/Module-CoreList/MANIFEST
@@ -12,6 +12,7 @@ META.yml
t/corelist.t
t/deprecated.t
t/find_modules.t
+t/is_core.t
t/pod.t
t/utils.t
META.json Module JSON meta-data (added by MakeMaker)
diff --git a/dist/Module-CoreList/lib/Module/CoreList.pm b/dist/Module-CoreList/lib/Module/CoreList.pm
index b182c854d3..7e18c93802 100644
--- a/dist/Module-CoreList/lib/Module/CoreList.pm
+++ b/dist/Module-CoreList/lib/Module/CoreList.pm
@@ -3,7 +3,7 @@ use strict;
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 {
@@ -8651,6 +8651,46 @@ my %delta = (
},
);
+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};
diff --git a/dist/Module-CoreList/lib/Module/CoreList.pod b/dist/Module-CoreList/lib/Module/CoreList.pod
index 72fc5e3413..55f46d9ece 100644
--- a/dist/Module-CoreList/lib/Module/CoreList.pod
+++ b/dist/Module-CoreList/lib/Module/CoreList.pod
@@ -12,6 +12,10 @@ Module::CoreList - what modules shipped with versions of perl
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);
@@ -71,6 +75,19 @@ you may provide a list of perl versions to limit the regex search.
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.
diff --git a/dist/Module-CoreList/t/is_core.t b/dist/Module-CoreList/t/is_core.t
new file mode 100644
index 0000000000..a14531550e
--- /dev/null
+++ b/dist/Module-CoreList/t/is_core.t
@@ -0,0 +1,52 @@
+#!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)");
+
diff --git a/pod/perldelta.pod b/pod/perldelta.pod
index 9cdf700483..217fa83e75 100644
--- a/pod/perldelta.pod
+++ b/pod/perldelta.pod
@@ -489,10 +489,15 @@ by using SSize_t instead of I32 for array indices.
=item *
-L<Module::CoreList> has been upgraded from version 2.97 to 2.98.
+L<Module::CoreList> has been upgraded from version 2.97 to 2.99.
The list of Perl versions covered has been updated.
+A function C<is_core()> has been added, which returns true if the
+specified module was bundled with Perl. Optionally you can specify
+a minimum version of the module, and the specific version of Perl
+you're interested in (defaults to C<$^V>, the running version of Perl).
+
=item *
L<Module::Load::Conditional> has been upgraded from version 0.54 to 0.58.