From: Karen Etheridge Date: Thu, 21 Nov 2013 00:53:32 +0000 (-0800) Subject: is_indexable( [ $package ] ) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=22553051a25f95731d78b2f12fef20cf58218a50;p=p5sagit%2FModule-Metadata.git is_indexable( [ $package ] ) --- diff --git a/Changes b/Changes index 54abdcf..41006d3 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Release history for Module-Metadata + - new is_indexable() object method (ether, RT#84357) + 1.000019 2013-10-06 - warnings now disabled inside during the evaluation of generated version sub (BinGOs, RT#89282) diff --git a/lib/Module/Metadata.pm b/lib/Module/Metadata.pm index 069abb4..d11c8c0 100644 --- a/lib/Module/Metadata.pm +++ b/lib/Module/Metadata.pm @@ -783,6 +783,18 @@ sub pod { } } +sub is_indexable { + my ($self, $package) = @_; + + my @indexable_packages = grep { $_ ne 'main' } $self->packages_inside; + + # check for specific package, if provided + return !! grep { $_ eq $package } @indexable_packages if $package; + + # otherwise, check for any indexable packages at all + return !! @indexable_packages; +} + 1; =head1 NAME @@ -993,6 +1005,13 @@ Returns true if there is any POD in the file. Returns the POD data in the given section. +=item C<< is_indexable($package) >> or C<< is_indexable() >> + +Returns a boolean indicating whether the package (if provided) or any package +(otherwise) is eligible for indexing by PAUSE, the Perl Authors Upload Server. +Note This only checks for valid C declarations, and does not take any +ownership information into account. + =back =head1 AUTHOR diff --git a/t/metadata.t b/t/metadata.t index 2c2eb9e..141cf8f 100644 --- a/t/metadata.t +++ b/t/metadata.t @@ -259,7 +259,7 @@ package Simple-Edward; ); my %pkg_names = reverse @pkg_names; -plan tests => 54 + (2 * keys( %modules )) + (2 * keys( %pkg_names )); +plan tests => 63 + (2 * keys( %modules )) + (2 * keys( %pkg_names )); require_ok('Module::Metadata'); @@ -724,6 +724,9 @@ $VERSION = '0.01'; is( $pm_info->version, undef, 'version for default package' ); is( $pm_info->version('simple'), '0.01', 'version for lower-case package' ); is( $pm_info->version('Simple'), undef, 'version for capitalized package' ); + ok( $pm_info->is_indexable(), 'an indexable package is found' ); + ok( $pm_info->is_indexable('simple'), 'the simple package is indexable' ); + ok( !$pm_info->is_indexable('Simple'), 'the Simple package would not be indexed' ); $dist->change_file( 'lib/Simple.pm', <<'---' ); package simple; @@ -741,4 +744,20 @@ $VERSION = '0.03'; is( $pm_info->version('simple'), '0.01', 'version for lower-case package' ); is( $pm_info->version('Simple'), '0.02', 'version for capitalized package' ); is( $pm_info->version('SiMpLe'), '0.03', 'version for mixed-case package' ); + ok( $pm_info->is_indexable('simple'), 'the simple package is indexable' ); + ok( $pm_info->is_indexable('Simple'), 'the Simple package is indexable' ); + + $dist->change_file( 'lib/Simple.pm', <<'---' ); +package ## hide from PAUSE + simple; +$VERSION = '0.01'; +--- + + $dist->regen; + + $pm_info = Module::Metadata->new_from_file('lib/Simple.pm'); + is( $pm_info->name, undef, 'no package names found' ); + ok( !$pm_info->is_indexable('simple'), 'the simple package would not be indexed' ); + ok( !$pm_info->is_indexable('Simple'), 'the Simple package would not be indexed' ); + ok( !$pm_info->is_indexable(), 'no indexable package is found' ); }