Repository/Packages.pm

filter: Statementstmt 94.3% 83 / 88 Branchbran 55.5% 10 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 89.4% 17 / 19 Podpod 0.0% 0 / 10 totaltotal 81.4% 110 / 135 SCAR 25.9
CC
13
Cov
88%
get_module
6.0
get_module_version
6.0
_build_modules
5.0
CRAP 13.3
« Repository/Perms.pm ↑ Summary Repository.pm »
1 package CPAN::Repository::Packages;
2 BEGIN {
3 2 ▶ $CPAN::Repository::Packages::AUTHORITY = 'cpan:GETTY';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 }
5 {
6 2 $CPAN::Repository::Packages::VERSION = '0.008';
7 }
8 # ABSTRACT: 02packages
9  
10 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 with qw(
13 CPAN::Repository::Role::File
14 );
15  
16 2 ▶use Dist::Data;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use File::Spec::Functions ':ALL';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use DateTime::Format::RFC3339;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use DateTime::Format::Epoch::Unix;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 27 ▶sub file_parts { 'modules', '02packages.details.txt' }
Subroutine file_parts: called CC=1 SCAR=0.0
Pod undocumented
23 5 ▶sub file_parts_stamp { 'modules', '02STAMP' }
Subroutine file_parts_stamp: called CC=1 SCAR=0.0
Pod undocumented
24  
25 2 has modules => (
26 is => 'ro',
27 lazy => 1,
28 builder => '_build_modules',
29 );
30  
31 sub _build_modules {
32 2 ▶ my ( $self ) = @_;
Subroutine _build_modules: called CC=5 SCAR=16.1
33 2 ▶ return {} unless $self->exist;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->exist 1 1 2
34 1 my @lines = $self->get_file_lines;
35 1 my %modules;
36 1 for (@lines) {
37 11 chomp($_);
38 11 ▶ next if ($_ =~ /[^:]:[ \t]/);
Branch: 1 branch
BranchTrueFalseTotal
if $_ =~ /[^:]:[ \t]/ 8 3 11
39 3 ▶ if ($_ =~ m/^([^ \t]+)[ \t]+([^ \t]+)[ \t]+([^ \t]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^([^ \t]+)[ \t]+([^ \t]+)[ \t]+([^ \t]+)$/) 2 1 3
40 # $1 = module
41 # $2 = version
42 # $3 = path (inside repository)
43 2 $modules{$1} = [ $2, $3 ];
44 }
45 }
46 1 return \%modules;
47 }
48  
49 2 has authorbase_path_parts => (
50 is => 'ro',
51 required => 1,
52 );
53  
54 2 has url => (
55 is => 'ro',
56 required => 1,
57 );
58  
59 2 has written_by => (
60 is => 'ro',
61 required => 1,
62 );
63  
64 sub get_module {
65 0 ▶ my ( $self, $module ) = @_;
Subroutine get_module: not called CC=2 SCAR=17.9
Pod undocumented
66 return defined $self->modules->{$module}
67 0 ▶ ? $self->modules->{$module}->[1]
Branch: 1 branch
BranchTrueFalseTotal
defined $self->modules->{$module} ? : 0 0 0
68 : ();
69 }
70  
71 sub get_module_version {
72 0 ▶ my ( $self, $module ) = @_;
Subroutine get_module_version: not called CC=2 SCAR=17.9
Pod undocumented
73 return defined $self->modules->{$module}
74 0 ▶ ? $self->modules->{$module}->[0]
Branch: 1 branch
BranchTrueFalseTotal
defined $self->modules->{$module} ? : 0 0 0
75 : ();
76 }
77  
78 sub set_module {
79 3 ▶ my ( $self, $module, $version, $path ) = @_;
Subroutine set_module: called CC=1 SCAR=0.0
Pod undocumented
80 3 return $self->modules->{$module} = [ $version, $path ];
81 }
82  
83 sub add_distribution {
84 3 ▶ my ( $self, $author_distribution_path ) = @_;
Subroutine add_distribution: called CC=2 SCAR=6.9
Pod undocumented
85 3 my $filename = catfile( $self->repository_root, @{$self->authorbase_path_parts}, splitdir( $author_distribution_path ) );
86 3 my $dist = Dist::Data->new( $filename );
87 3 for (keys %{$dist->packages}) {
88 3 $self->set_module($_, $dist->packages->{$_}->{version}, $author_distribution_path);
89 }
90 3 return $self;
91 }
92  
93 sub stamp_filename {
94 5 ▶ my ( $self ) = @_;
Subroutine stamp_filename: called CC=1 SCAR=0.0
Pod undocumented
95 5 catfile( $self->repository_root, $self->file_parts_stamp );
96 }
97  
98 after save => sub {
99 4 ▶ my ( $self ) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.0
100 4 ▶ my $stamp = IO::File->new($self->stamp_filename, "w") or die "cant write to ".$self->stamp_filename;
Branch: 1 branch
BranchTrueFalseTotal
my $stamp = "IO::File"->new($self->stamp_filename, "w") or die 'cant write to ' . $self->stamp_filename 0 4 4
101 4 my $now = DateTime->now;
102 4 print $stamp (DateTime::Format::Epoch::Unix->format_datetime($now).' '.DateTime::Format::RFC3339->new->format_datetime($now)."\n");
103 4 $stamp->close;
104 2 };
105  
106 sub timestamp {
107 1 ▶ my ( $self ) = @_;
Subroutine timestamp: called CC=3 SCAR=11.6
Pod undocumented
108 1 ▶ my $stamp = IO::File->new($self->stamp_filename, "r") or die "cant read ".$self->stamp_filename;
Branch: 1 branch
BranchTrueFalseTotal
my $stamp = "IO::File"->new($self->stamp_filename, "r") or die 'cant read ' . $self->stamp_filename 0 1 1
109 1 my ( $line ) = <$stamp>;
110 1 chomp($line);
111 1 ▶ if ($line =~ /^(\d+) /) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(\d+) /) { } 1 0 1
112 1 return DateTime::Format::Epoch::Unix->parse_datetime($1);
113 } else {
114 0 die "cant find unix timestamp from ".$self->stamp_filename;
115 }
116 }
117  
118 sub generate_content {
119 4 ▶ my ( $self ) = @_;
Subroutine generate_content: called CC=3 SCAR=11.0
Pod undocumented
120 4 my @file_parts = $self->file_parts;
121 4 my $content = "";
122 4 $content .= $self->generate_header_line('File:',(pop @file_parts));
123 4 $content .= $self->generate_header_line('URL:',$self->url.$self->path_inside_root);
124 4 $content .= $self->generate_header_line('Description:','Package names found in directory $CPAN/authors/id/');
125 4 $content .= $self->generate_header_line('Columns:','package name, version, path');
126 4 $content .= $self->generate_header_line('Intended-For:','Automated fetch routines, namespace documentation.');
127 4 $content .= $self->generate_header_line('Written-By:',$self->written_by);
128 4 $content .= $self->generate_header_line('Line-Count:',scalar keys %{$self->modules});
129 4 $content .= $self->generate_header_line('Last-Updated:',DateTime->now->strftime('%a, %e %b %y %T %Z'));
130 4 $content .= "\n";
131 4 for (sort { $a cmp $b } keys %{$self->modules}) {
132 5 ▶ $content .= sprintf("%-60s %-20s %s\n",$_,$self->modules->{$_}->[0] ? $self->modules->{$_}->[0] : 'undef',$self->modules->{$_}->[1]);
Branch: 1 branch
BranchTrueFalseTotal
$self->modules->{$_}[0] ? : 5 0 5
133 }
134 4 return $content;
135 }
136  
137 sub generate_header_line {
138 32 ▶ my ( $self, $key, $value ) = @_;
Subroutine generate_header_line: called CC=1 SCAR=0.0
Pod undocumented
139 32 return sprintf("%-13s %s\n",$key,$value);
140 }
141  
142 2 1;
143  
144  
145 __END__
146 =pod
147  
148 =head1 NAME
149  
150 CPAN::Repository::Packages - 02packages
151  
152 =head1 VERSION
153  
154 version 0.008
155  
156 =head1 SYNOPSIS
157  
158 use CPAN::Repository::Packages;
159  
160 my $packages = CPAN::Repository::Packages->new({
161 repository_root => $fullpath_to_root,
162 url => $url,
163 written_by => $written_by,
164 authorbase_path_parts => ['authors','id'],
165 });
166  
167 =encoding utf8
168  
169 =head1 SEE ALSO
170  
171 L<CPAN::Repository>
172  
173 =head1 SUPPORT
174  
175 IRC
176  
177 Join #duckduckgo on irc.freenode.net. Highlight Getty for fast reaction :).
178  
179 Repository
180  
181 http://github.com/Getty/p5-cpan-repository
182 Pull request and additional contributors are welcome
183  
184 Issue Tracker
185  
186 http://github.com/Getty/p5-cpan-repository/issues
187  
188 =head1 AUTHOR
189  
190 Torsten Raudssus <torsten@raudss.us> L<http://raudss.us/>
191  
192 =head1 COPYRIGHT AND LICENSE
193  
194 This software is copyright (c) 2012 by DuckDuckGo, Inc. L<http://duckduckgo.com/>.
195  
196 This is free software; you can redistribute it and/or modify it under
197 the same terms as the Perl 5 programming language system itself.
198  
199 =cut
200  
« Repository/Perms.pm ↑ Summary Repository.pm »