Skip to content

Commit 593a3f9

Browse files
haargoalders
authored andcommitted
split examples into paths and files
The list of things we're trying to list for examples included 'ex' and 'examples'. These don't both make sense to match in the same way. Split the file and path matching. Match directories at the top level, not just the path prefix. This prevents matching a /ext/ directory. And match files starting with examples, but not ex.
1 parent 336e36b commit 593a3f9

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

lib/MetaCPAN/Query/File.pm

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,19 @@ my %perl_files = (
141141
)
142142
],
143143
);
144-
my %prefix_files = (
144+
145+
my %path_files = (
145146
example => [
146147
qw(
147148
eg
148149
ex
150+
)
151+
],
152+
);
153+
154+
my %prefix_files = (
155+
example => [
156+
qw(
149157
example
150158
Example
151159
sample
@@ -219,13 +227,35 @@ for my $type ( keys %special_files ) {
219227
for my $type ( keys %prefix_files ) {
220228
my @prefixes = @{ $prefix_files{$type} };
221229

222-
my @parts = map +( { prefix => { 'name' => $_ } },
223-
{ prefix => { 'path' => $_ } }, ), @prefixes;
230+
my @parts = map +{ prefix => { 'name' => $_ } }, @prefixes;
231+
232+
push @{ $query_parts{$type} }, @parts;
224233

225-
my ($regex) = map qr/\A(?:$_)/, join '|', @prefixes;
234+
my ($regex) = map qr{(?:\A|/)(?:$_)[^/]*\z}, join '|', @prefixes;
235+
236+
if ( $type_to_regex{$type} ) {
237+
$type_to_regex{$type} = qr{$type_to_regex{$type}|$regex};
238+
}
239+
else {
240+
$type_to_regex{$type} = $regex;
241+
}
242+
}
243+
244+
for my $type ( keys %path_files ) {
245+
my @prefixes = @{ $path_files{$type} };
246+
247+
my @parts = map +{ prefix => { 'path' => "$_/" } }, @prefixes;
226248

227-
$type_to_regex{$type} = $regex;
228249
push @{ $query_parts{$type} }, @parts;
250+
251+
my ($regex) = map qr{\A(?:$_)/}, join '|', @prefixes;
252+
253+
if ( $type_to_regex{$type} ) {
254+
$type_to_regex{$type} = qr{$type_to_regex{$type}|$regex};
255+
}
256+
else {
257+
$type_to_regex{$type} = $regex;
258+
}
229259
}
230260

231261
sub interesting_files {
@@ -302,8 +332,7 @@ sub interesting_files {
302332
my $category = $file_to_type{ $file->{name} };
303333
if ( !$category ) {
304334
for my $type ( keys %type_to_regex ) {
305-
my $re = $type_to_regex{$type};
306-
if ( $file->{name} =~ $re || $file->{path} =~ $re ) {
335+
if ( $file->{path} =~ $type_to_regex{$type} ) {
307336
$category = $type;
308337
last;
309338
}

0 commit comments

Comments
 (0)