Skip to content

Commit 9c02a2d

Browse files
authored
Merge pull request #70 from metacpan/mickey/reads
allow reading of alternative files (for testing)
2 parents 026f6f2 + b716024 commit 9c02a2d

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

bin/package.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
# read the rest of the file line-by-line (too big to slurp)
2929

30-
my $fh_packages = read_02packages_fh(1);
30+
my $fh_packages = read_02packages_fh( log_meta => 1 );
3131
while ( my $line = <$fh_packages> ) {
3232
next unless $line;
3333
chomp($line);

lib/MetaCPAN/Ingest.pm

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,9 @@ sub extract_section ( $pod, $section ) {
294294
return $out;
295295
}
296296

297-
sub read_00whois () {
297+
sub read_00whois ( $file = undef ) {
298298
my $cpan = cpan_dir();
299-
my $authors_file = sprintf( "%s/%s", $cpan, 'authors/00whois.xml' );
299+
my $authors_file = $file || sprintf( "%s/%s", $cpan, 'authors/00whois.xml' );
300300

301301
my $data = XMLin(
302302
$authors_file,
@@ -330,10 +330,18 @@ sub read_00whois () {
330330
}
331331

332332
# TODO: replace usage with read_02packages
333-
sub read_02packages_fh ( $log_meta = 0 ) {
334-
my $cpan = cpan_dir();
335-
my $fh = $cpan->child(qw< modules 02packages.details.txt.gz >)
336-
->openr(':gzip');
333+
sub read_02packages_fh ( %args ) {
334+
my $log_meta = $args{log_meta} // 0;
335+
my $file = $args{file};
336+
337+
my $fh;
338+
if ( $file ) {
339+
$fh = path($file)->openr(':gzip');
340+
} else {
341+
my $cpan = cpan_dir();
342+
$fh = $cpan->child(qw< modules 02packages.details.txt.gz >)
343+
->openr(':gzip');
344+
}
337345

338346
# read first 9 lines (meta info)
339347
my $meta = "Meta info:\n";
@@ -347,22 +355,36 @@ sub read_02packages_fh ( $log_meta = 0 ) {
347355
return $fh;
348356
}
349357

350-
sub read_02packages () {
351-
my $cpan = cpan_dir();
352-
return Parse::CPAN::Packages::Fast->new(
353-
$cpan->child(qw< modules 02packages.details.txt.gz >)->stringify );
358+
sub read_02packages ( $file = undef ) {
359+
my $content;
360+
if ( $file ) {
361+
$content = path($file)->stringify;
362+
} else {
363+
my $cpan = cpan_dir();
364+
$content = $cpan->child(qw< modules 02packages.details.txt.gz >)->stringify;
365+
}
366+
367+
return Parse::CPAN::Packages::Fast->new($content);
354368
}
355369

356370
# TODO: replace usage with unified read_06perms
357-
sub read_06perms_fh () {
371+
sub read_06perms_fh ( $file = undef ) {
372+
return path($file)->openr if $file;
373+
358374
my $cpan = cpan_dir();
359375
return $cpan->child(qw< modules 06perms.txt >)->openr;
360376
}
361377

362-
sub read_06perms_iter () {
363-
my $cpan = cpan_dir();
364-
my $file_path = $cpan->child(qw< modules 06perms.txt >)->absolute;
365-
my $pp = PAUSE::Permissions->new( path => $file_path );
378+
sub read_06perms_iter ( $file = undef ) {
379+
my $file_path;
380+
if ( $file ) {
381+
$file_path = path($file)->absolute;
382+
} else {
383+
my $cpan = cpan_dir();
384+
$file_path = $cpan->child(qw< modules 06perms.txt >)->absolute;
385+
}
386+
387+
my $pp = PAUSE::Permissions->new( path => $file_path );
366388
return $pp->module_iterator;
367389
}
368390

0 commit comments

Comments
 (0)