Skip to content

Commit 08bd7ef

Browse files
committed
don't scan module content ourselves to detect packages
Module::Metadata, Parse::PMFile, or provides metadata already tell us what modules exist in a file. They will not include packages hidden using the "hide from PAUSE" trick. This was possibly needed based on other metadata mishandling. Some of the tests were relying on this behavior and have been removed. They were expecting the data provided in the test to be overridden by the additional package check, but the module list would never have been given to them in our indexing code.
1 parent 3d68cb3 commit 08bd7ef

File tree

4 files changed

+4
-99
lines changed

4 files changed

+4
-99
lines changed

lib/MetaCPAN/Document/File.pm

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -917,11 +917,7 @@ sub set_indexed {
917917
next;
918918
}
919919

920-
$mod->_set_indexed(
921-
$mod->hide_from_pause( ${ $self->content }, $self->name )
922-
? false
923-
: true
924-
);
920+
$mod->_set_indexed(true);
925921
}
926922

927923
if ( my $doc_name = $self->documentation ) {

lib/MetaCPAN/Document/Module.pm

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -111,31 +111,6 @@ sub _build_version_numified {
111111
my $bom
112112
= qr/(?:\x00\x00\xfe\xff|\xff\xfe\x00\x00|\xfe\xff|\xff\xfe|\xef\xbb\xbf)/;
113113

114-
sub hide_from_pause {
115-
my ( $self, $content, $file_name ) = @_;
116-
return 0 if defined($file_name) && $file_name =~ m{\.pm\.PL\z};
117-
my $pkg = $self->name;
118-
my $pkg_match = join q[(?:::|')], map quotemeta, split m{::}, $pkg;
119-
120-
# This regexp is *almost* the same as $PKG_REGEXP in Module::Metadata.
121-
# [b] We need to allow/ignore a possible BOM since we read in binary mode.
122-
# Module::Metadata, for example, checks for a BOM and then sets the encoding.
123-
# [s] We change `\s` to `\h` because we want to verify that it's on one line.
124-
# [p] We replace $PKG_NAME_REGEXP with the specific package we're looking for.
125-
# [v] Simplify the optional whitespace/version group ($V_NUM_REGEXP).
126-
return $content =~ / # match a package declaration
127-
^ # start of line
128-
(?:\A$bom)? # possible BOM at the start of the file [b]
129-
[\h\{;]* # intro chars on a line [s]
130-
package # the word 'package'
131-
\h+ # whitespace [s]
132-
($pkg_match) # the package name [p]
133-
(\h+ v?[0-9._]+)? # optional version number (preceded by whitespace) [v]
134-
\h* # optional whitesapce [s]
135-
[;\{] # semicolon line terminator or block start
136-
/mx ? 0 : 1;
137-
}
138-
139114
=head2 set_associated_pod
140115
141116
Expects an instance C<$file> of L<MetaCPAN::Document::File> as first parameter

t/document/file.t

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,6 @@ END
227227
is( $file->abstract,
228228
'An object containing information about how to get access to teh Moby databases, resources, etc. from the mobycentral.config file'
229229
);
230-
is(
231-
$file->module->[0]
232-
->hide_from_pause( ${ $file->content }, $file->name ),
233-
0, 'indexed'
234-
);
235230
is( $file->documentation, 'MOBY::Config' );
236231
is( $file->level, 2 );
237232
test_attributes $file, {
@@ -302,13 +297,9 @@ AS-specific methods for Number::Phone
302297
303298
1;
304299
END
305-
my $file = new_file_doc(
306-
module => [ { name => 'Number::Phone::NANP::ASS', version => 1.1 } ],
307-
content => \$content,
308-
);
309-
is( $file->sloc, 8, '8 lines of code' );
310-
is( $file->slop, 4, '4 lines of pod' );
311-
is( $file->module->[0]->hide_from_pause($content), 1, 'not indexed' );
300+
my $file = new_file_doc( content => \$content, );
301+
is( $file->sloc, 8, '8 lines of code' );
302+
is( $file->slop, 4, '4 lines of pod' );
312303
is(
313304
$file->abstract,
314305
'AS-specific methods for Number::Phone',
@@ -322,8 +313,6 @@ END
322313
is( $file->documentation, 'Number::Phone::NANP::AS', 'document text' );
323314

324315
is_deeply( $file->pod_lines, [ [ 18, 7 ] ], 'correct pod_lines' );
325-
is( $file->module->[0]->version_numified,
326-
1.1, 'numified version has been calculated' );
327316

328317
is(
329318
${ $file->pod },

t/document/module.t

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,6 @@ use lib 't/lib';
55
use MetaCPAN::Document::Module ();
66
use Test::More;
77

8-
subtest hide_from_pause => sub {
9-
foreach my $test (
10-
11-
# The original:
12-
[ 'No::CommentNL' => "package # hide\n No::CommentNL;" ],
13-
14-
# I'm not sure how PAUSE handles this one but currently we ignore it.
15-
[ 'No::JustNL' => "package \n No::JustNL;" ],
16-
17-
# The good ones:
18-
[ 'Pkg' => 'package Pkg;' ],
19-
[ 'Pkg::Ver' => 'package Pkg::Ver v1.2.3;' ],
20-
[ 'Pkg::Block' => 'package Pkg::Block { our $var = 1 }' ],
21-
[
22-
'Pkg::VerBlock' => 'package Pkg::VerBlock 1.203 { our $var = 1 }'
23-
],
24-
[ 'Pkg::SemiColons' => '; package Pkg::SemiColons; $var' ],
25-
[ 'Pkg::InABlock' => '{ package Pkg::InABlock; $var }' ],
26-
27-
# This doesn't work as a BOM can only appear at the start of a file.
28-
#[ 'Pkg::AfterABOM' => "\xef\xbb\xbfpackage Pkg::AfterABOM" ],
29-
30-
[ 'No::JustVar' => qq["\n\$package No::JustVar;\n"] ],
31-
32-
# This shouldn't match, but there's only so much we can do...
33-
# we're not going to eval the whole file to figure it out.
34-
[ 'Pkg::InsideStr' => qq["\n package Pkg::InsideStr;\n"] ],
35-
36-
[ 'No::Comment' => qq[# package No::Comment;\n] ],
37-
[ 'No::Different' => q[package No::Different::Pkg;] ],
38-
[ 'No::PkgWithNum' => qq["\npackage No::PkgWithNumv2.3;\n"] ],
39-
[ 'No::CrazyChars' => qq["\npackage No::CrazyChars\[0\];\n"] ],
40-
)
41-
{
42-
my ( $name, $content ) = @$test;
43-
44-
subtest $name => sub {
45-
my $module = MetaCPAN::Document::Module->new( name => $name );
46-
47-
SKIP: {
48-
skip( 'Perl 5.14 needed for package block compilation', 1 )
49-
if $] < 5.014;
50-
## no critic
51-
ok eval "sub { no strict; $content }", "code compiles"
52-
or diag $@;
53-
}
54-
55-
my ($hidden) = ( $name =~ /^No::/ ? 1 : 0 );
56-
57-
is $module->hide_from_pause($content), $hidden,
58-
"hide_from_pause is $hidden";
59-
};
60-
}
61-
};
62-
638
subtest set_associated_pod => sub {
649
test_associated_pod( 'Squirrel', [qw( lib/Squirrel.pod )],
6510
'lib/Squirrel.pod' );

0 commit comments

Comments
 (0)