AnyPAN/Index.pm

filter: Statementstmt 96.4% 54 / 56 Branchbran 71.4% 10 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 2 totaltotal 90.1% 73 / 81 CC 11 SCAR 13.5
CC
11
Cov
91%
_write_to
6.3
parse
5.0
save
2.0
CRAP 3.8
« AnyPAN/Index/Merged.pm ↑ Summary AnyPAN/Merger/Algorithm/PreferLatestVersion.pm »
1 package AnyPAN::Index;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Class::Accessor::Lite ro => [qw/headers packages/], new => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use AnyPAN::PackageInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use IO::Compress::Gzip;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use IO::Uncompress::Gunzip;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 my @WELLKNOWN_HEADERS = qw/
13 File
14 URL
15 Description
16 Columns
17 Intended-For
18 Written-By
19 Line-Count
20 Last-Updated
21 /;
22  
23 4 ▶sub parse {
Subroutine parse: called CC=5 SCAR=16.1
Pod undocumented
24 4 my ($class, $index_path, $source) = @_;
25  
26 4 my $fh = IO::Uncompress::Gunzip->new($index_path->openr_raw);
27  
28 4 my %headers;
29 my @packages;
30  
31 4 my $context = 'header';
32 4 ▶ while (defined(my $line = <$fh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 41 4 45
33 41 chomp $line;
34 41 ▶ if ($line eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq "") 4 37 41
35 4 $context = 'index';
36 4 next;
37 }
38  
39 37 ▶ if ($context eq 'header') {
Branch: 2 branches
BranchTrueFalseTotal
if ($context eq 'header') { } 32 5 37
elsif ($context eq 'index') { } 5 0 5
40 32 my ($key, $value) = split /\s*:\s*/, $line;
41 32 $headers{$key} = $value;
42 } elsif ($context eq 'index') {
43 5 my ($module, $version, $path) = split /\s+/, $line;
44  
45 5 push @packages => AnyPAN::PackageInfo->new(
46 source => $source,
47 module => $module,
48 version => $version,
49 path => $path,
50 );
51 }
52 }
53  
54 4 return $class->new(
55 headers => \%headers,
56 packages => \@packages,
57 );
58 }
59  
60 1 ▶sub save {
Subroutine save: called CC=2 SCAR=7.0
Pod undocumented
61 1 my ($self, $storage) = @_;
62  
63 1 my $tempfile = Path::Tiny->tempfile(UNKINK => 1);
64  
65 # write index
66 1 my $fh = $tempfile->openw_raw();
67 1 $self->_write_to($fh);
68 1 ▶ close $fh or die "$!: $tempfile";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "$!: $tempfile" 1 0 1
69  
70 1 $storage->copy($tempfile, 'modules/02packages.details.txt.gz');
71 }
72  
73 1 ▶sub _write_to {
Subroutine _write_to: called CC=6 SCAR=18.5
74 1 my ($self, $raw_fh) = @_;
75 1 ▶ my $fh = IO::Compress::Gzip->new($raw_fh)
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::Compress::Gzip"->new($raw_fh) or die $IO::Compress::Gzip::GzipError 1 0 1
76 or die $IO::Compress::Gzip::GzipError;
77  
78 1 my %header = %{ $self->headers };
79 1 for my $name (@WELLKNOWN_HEADERS) {
80 8 my $value = delete $header{$name};
81 8 printf $fh "%-14s%s\n", "$name:", $value;
82 }
83 1 for my $name (sort keys %header) {
84 0 my $value = $header{$name};
85 0 printf $fh "%-14s%s\n", "$name:", $value;
86 }
87 1 print $fh "\n";
88  
89 1 for my $package_info (@{ $self->packages }) {
90 2 printf $fh "%-35s %6s %s\n", $package_info->module, $package_info->version, $package_info->path;
91 }
92  
93 1 ▶ close $fh
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die $IO::Compress::Gzip::GzipError 1 0 1
94 or die $IO::Compress::Gzip::GzipError;
95 }
96  
97 2 1;
98 __END__
« AnyPAN/Index/Merged.pm ↑ Summary AnyPAN/Merger/Algorithm/PreferLatestVersion.pm »