Skip to content

Commit 1a61458

Browse files
authored
Merge pull request #1384 from metacpan/haarg/no-special-package-parsing
remove special check for hidden packages
2 parents 52e83f9 + 08bd7ef commit 1a61458

File tree

8 files changed

+23
-123
lines changed

8 files changed

+23
-123
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-
subhide_from_pause{
115-
my ( $self, $content, $file_name ) = @_;
116-
return 0 ifdefined($file_name) && $file_name =~ m{\.pm\.PL\z};
117-
my$pkg = $self->name;
118-
my$pkg_match = joinq[(?:::|')], mapquotemeta, splitm{::}, $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
=head2set_associated_pod
140115
141116
Expects an instance C<$file> of L<MetaCPAN::Document::File> as first parameter

‎lib/MetaCPAN/Model/Release.pm‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,15 +481,16 @@ sub _modules_from_meta{
481481

482482
my$provides = $self->metadata->provides;
483483
my$files = $self->files;
484+
my%files = map +( $_->path=>$_ ), @$files;
484485
foreachmy$module ( sortkeys%$provides ){
485486
my$data = $provides->{$module};
486487
my$path = File::Spec->canonpath( $data->{file} );
487488

488-
# Obey no_index and take the shortest path if multiple files match.
489-
my ($file) = sort{length( $a->path ) <=>length( $b->path ) }
490-
grep{$_->indexed && $_->path =~ /\Q$path\E$/ } @$files;
489+
my$file = $files{$path}
490+
ornext;
491+
492+
nextunless$file->indexed;
491493

492-
nextunless$file;
493494
$file->add_module({
494495
name=>$module,
495496
version=>$data->{version},

‎lib/MetaCPAN/Util.pm‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,21 @@ use Sub::Exporter -setup =>{
3737
true
3838
false
3939
is_bool
40+
to_bool
4041
MAX_RESULT_WINDOW
4142
) ]
4243
};
4344

4445
# Limit the maximum result window to 1000, really should be enough!
4546
use constant MAX_RESULT_WINDOW=> 1000;
4647

47-
*true = \&Cpanel::JSON::XS::true;
48-
*false = \&Cpanel::JSON::XS::false;
48+
subtrue ();
49+
*true = \&Cpanel::JSON::XS::true;
50+
subfalse ();
51+
*false = \&Cpanel::JSON::XS::false;
52+
subis_bool ($);
4953
*is_bool = \&Cpanel::JSON::XS::is_bool;
54+
subto_bool ($){$_[0] ? true : false }
5055

5156
subroot_dir{
5257
Cwd::abs_path( File::Spec->catdir(

‎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-
foreachmy$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' );

‎t/lib/MetaCPAN/Tests/Release.pm‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,14 @@ test 'modules in Packages-1.103' => sub{
230230
= map{( $_->{path} =>$_->{module} ) } @{$self->module_files };
231231

232232
foreachmy$path ( sortkeys %{$self->modules } ){
233-
my$desc = "File '$path' has expected modules";
234-
if ( my$got = delete$module_files{$path} ){
235-
my$got= [ map +{%$_}, @$got ];
236-
$_->{associated_pod} //= undeffor@$got;
233+
my$desc= "File '$path' has expected modules";
234+
my$got_modules = delete$module_files{$path} || [];
235+
my$got= [ map +{%$_}, @$got_modules ];
236+
$_->{associated_pod} //= undeffor@$got;
237237

238238
# We may need to sort modules by name, I'm not sure if order is reliable.
239-
is_deeply $got, $self->modules->{$path}, $desc
240-
or diag Test::More::explain($got);
241-
}
242-
else{
243-
ok( 0, $desc );
244-
}
239+
is_deeply $got, $self->modules->{$path}, $desc
240+
or diag Test::More::explain($got);
245241
}
246242

247243
is( scalarkeys%module_files, 0, 'all module files tested' )

‎t/release/file-duplicates.t‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,7 @@ test_release(
2828
indexed=> true,
2929
associated_pod=>undef,
3030
} ],
31-
'lib/Dupe.pm'=> [{
32-
name=>'Dupe',
33-
version=>'0.993',
34-
version_numified=>'0.993',
35-
authorized=> true,
36-
indexed=> false,
37-
associated_pod=>undef,
38-
} ],
31+
'lib/Dupe.pm'=> [],
3932
'DupeX/Dupe.pm'=> [
4033
{
4134
name=>'DupeX::Dupe',

0 commit comments

Comments
(0)