Skip to content

allow reading of alternative files (for testing) #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/package.pl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

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

my $fh_packages = read_02packages_fh(1);
my $fh_packages = read_02packages_fh( log_meta => 1 );
while ( my $line = <$fh_packages> ) {
next unless $line;
chomp($line);
Expand Down
52 changes: 37 additions & 15 deletions lib/MetaCPAN/Ingest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ sub extract_section ( $pod, $section ) {
return $out;
}

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

my $data = XMLin(
$authors_file,
Expand Down Expand Up @@ -330,10 +330,18 @@ sub read_00whois () {
}

# TODO: replace usage with read_02packages
sub read_02packages_fh ( $log_meta = 0 ) {
my $cpan = cpan_dir();
my $fh = $cpan->child(qw< modules 02packages.details.txt.gz >)
->openr(':gzip');
sub read_02packages_fh ( %args ) {
my $log_meta = $args{log_meta} // 0;
my $file = $args{file};

my $fh;
if ( $file ) {
$fh = path($file)->openr(':gzip');
} else {
my $cpan = cpan_dir();
$fh = $cpan->child(qw< modules 02packages.details.txt.gz >)
->openr(':gzip');
}

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

sub read_02packages () {
my $cpan = cpan_dir();
return Parse::CPAN::Packages::Fast->new(
$cpan->child(qw< modules 02packages.details.txt.gz >)->stringify );
sub read_02packages ( $file = undef ) {
my $content;
if ( $file ) {
$content = path($file)->stringify;
} else {
my $cpan = cpan_dir();
$content = $cpan->child(qw< modules 02packages.details.txt.gz >)->stringify;
}

return Parse::CPAN::Packages::Fast->new($content);
}

# TODO: replace usage with unified read_06perms
sub read_06perms_fh () {
sub read_06perms_fh ( $file = undef ) {
return path($file)->openr if $file;

my $cpan = cpan_dir();
return $cpan->child(qw< modules 06perms.txt >)->openr;
}

sub read_06perms_iter () {
my $cpan = cpan_dir();
my $file_path = $cpan->child(qw< modules 06perms.txt >)->absolute;
my $pp = PAUSE::Permissions->new( path => $file_path );
sub read_06perms_iter ( $file = undef ) {
my $file_path;
if ( $file ) {
$file_path = path($file)->absolute;
} else {
my $cpan = cpan_dir();
$file_path = $cpan->child(qw< modules 06perms.txt >)->absolute;
}

my $pp = PAUSE::Permissions->new( path => $file_path );
return $pp->module_iterator;
}

Expand Down