line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPAN::Repository::Packages; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GETTY'; |
3
|
|
|
|
|
|
|
# ABSTRACT: 02packages |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
10
|
use Moo; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
10
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.010'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with qw( |
10
|
|
|
|
|
|
|
CPAN::Repository::Role::File |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
2189
|
use Dist::Data; |
|
2
|
|
|
|
|
818143
|
|
|
2
|
|
|
|
|
83
|
|
14
|
2
|
|
|
2
|
|
23
|
use File::Spec::Functions ':ALL'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
484
|
|
15
|
2
|
|
|
2
|
|
11
|
use IO::File; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
331
|
|
16
|
2
|
|
|
2
|
|
1796
|
use DateTime::Format::RFC3339; |
|
2
|
|
|
|
|
2406
|
|
|
2
|
|
|
|
|
57
|
|
17
|
2
|
|
|
2
|
|
14
|
use DateTime::Format::Epoch::Unix; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
2227
|
|
18
|
|
|
|
|
|
|
|
19
|
27
|
|
|
27
|
0
|
521
|
sub file_parts { 'modules', '02packages.details.txt' } |
20
|
5
|
|
|
5
|
0
|
76
|
sub file_parts_stamp { 'modules', '02STAMP' } |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has modules => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
lazy => 1, |
25
|
|
|
|
|
|
|
builder => '_build_modules', |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _build_modules { |
29
|
2
|
|
|
2
|
|
429
|
my ( $self ) = @_; |
30
|
2
|
100
|
|
|
|
15
|
return {} unless $self->exist; |
31
|
1
|
|
|
|
|
16
|
my @lines = $self->get_file_lines; |
32
|
1
|
|
|
|
|
1313
|
my %modules; |
33
|
1
|
|
|
|
|
5
|
for (@lines) { |
34
|
11
|
|
|
|
|
16
|
chomp($_); |
35
|
11
|
100
|
|
|
|
44
|
next if ($_ =~ /[^:]:[ \t]/); |
36
|
3
|
100
|
|
|
|
21
|
if ($_ =~ m/^([^ \t]+)[ \t]+([^ \t]+)[ \t]+([^ \t]+)$/) { |
37
|
|
|
|
|
|
|
# $1 = module |
38
|
|
|
|
|
|
|
# $2 = version |
39
|
|
|
|
|
|
|
# $3 = path (inside repository) |
40
|
2
|
|
|
|
|
15
|
$modules{$1} = [ $2, $3 ]; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
1
|
|
|
|
|
14
|
return \%modules; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has authorbase_path_parts => ( |
47
|
|
|
|
|
|
|
is => 'ro', |
48
|
|
|
|
|
|
|
required => 1, |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has url => ( |
52
|
|
|
|
|
|
|
is => 'ro', |
53
|
|
|
|
|
|
|
required => 1, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
has written_by => ( |
57
|
|
|
|
|
|
|
is => 'ro', |
58
|
|
|
|
|
|
|
required => 1, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub get_module { |
62
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $module ) = @_; |
63
|
|
|
|
|
|
|
return defined $self->modules->{$module} |
64
|
0
|
0
|
|
|
|
0
|
? $self->modules->{$module}->[1] |
65
|
|
|
|
|
|
|
: (); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub get_module_version { |
69
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $module ) = @_; |
70
|
|
|
|
|
|
|
return defined $self->modules->{$module} |
71
|
0
|
0
|
|
|
|
0
|
? $self->modules->{$module}->[0] |
72
|
|
|
|
|
|
|
: (); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub set_module { |
76
|
3
|
|
|
3
|
0
|
58
|
my ( $self, $module, $version, $path ) = @_; |
77
|
3
|
|
|
|
|
95
|
return $self->modules->{$module} = [ $version, $path ]; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub add_distribution { |
81
|
3
|
|
|
3
|
0
|
36
|
my ( $self, $author_distribution_path ) = @_; |
82
|
3
|
|
|
|
|
11
|
my $filename = catfile( $self->repository_root, @{$self->authorbase_path_parts}, splitdir( $author_distribution_path ) ); |
|
3
|
|
|
|
|
17
|
|
83
|
3
|
|
|
|
|
93
|
my $dist = Dist::Data->new( $filename ); |
84
|
3
|
|
|
|
|
9715
|
for (keys %{$dist->packages}) { |
|
3
|
|
|
|
|
53
|
|
85
|
3
|
|
|
|
|
642489
|
$self->set_module($_, $dist->packages->{$_}->{version}, $author_distribution_path); |
86
|
|
|
|
|
|
|
} |
87
|
3
|
|
|
|
|
285
|
return $self; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub stamp_filename { |
91
|
5
|
|
|
5
|
0
|
13
|
my ( $self ) = @_; |
92
|
5
|
|
|
|
|
32
|
catfile( $self->repository_root, $self->file_parts_stamp ); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
after save => sub { |
96
|
|
|
|
|
|
|
my ( $self ) = @_; |
97
|
|
|
|
|
|
|
my $stamp = IO::File->new($self->stamp_filename, "w") or die "cant write to ".$self->stamp_filename; |
98
|
|
|
|
|
|
|
my $now = DateTime->now; |
99
|
|
|
|
|
|
|
print $stamp (DateTime::Format::Epoch::Unix->format_datetime($now).' '.DateTime::Format::RFC3339->new->format_datetime($now)."\n"); |
100
|
|
|
|
|
|
|
$stamp->close; |
101
|
|
|
|
|
|
|
}; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub timestamp { |
104
|
1
|
|
|
1
|
0
|
16
|
my ( $self ) = @_; |
105
|
1
|
50
|
|
|
|
6
|
my $stamp = IO::File->new($self->stamp_filename, "r") or die "cant read ".$self->stamp_filename; |
106
|
1
|
|
|
|
|
174
|
my ( $line ) = <$stamp>; |
107
|
1
|
|
|
|
|
5
|
chomp($line); |
108
|
1
|
50
|
|
|
|
11
|
if ($line =~ /^(\d+) /) { |
109
|
1
|
|
|
|
|
42
|
return DateTime::Format::Epoch::Unix->parse_datetime($1); |
110
|
|
|
|
|
|
|
} else { |
111
|
0
|
|
|
|
|
0
|
die "cant find unix timestamp from ".$self->stamp_filename; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub generate_content { |
116
|
4
|
|
|
4
|
0
|
11
|
my ( $self ) = @_; |
117
|
4
|
|
|
|
|
16
|
my @file_parts = $self->file_parts; |
118
|
4
|
|
|
|
|
17
|
my $content = ""; |
119
|
4
|
|
|
|
|
21
|
$content .= $self->generate_header_line('File:',(pop @file_parts)); |
120
|
4
|
|
|
|
|
44
|
$content .= $self->generate_header_line('URL:',$self->url.$self->path_inside_root); |
121
|
4
|
|
|
|
|
18
|
$content .= $self->generate_header_line('Description:','Package names found in directory $CPAN/authors/id/'); |
122
|
4
|
|
|
|
|
13
|
$content .= $self->generate_header_line('Columns:','package name, version, path'); |
123
|
4
|
|
|
|
|
14
|
$content .= $self->generate_header_line('Intended-For:','Automated fetch routines, namespace documentation.'); |
124
|
4
|
|
|
|
|
21
|
$content .= $self->generate_header_line('Written-By:',$self->written_by); |
125
|
4
|
|
|
|
|
12
|
$content .= $self->generate_header_line('Line-Count:',scalar keys %{$self->modules}); |
|
4
|
|
|
|
|
97
|
|
126
|
4
|
|
|
|
|
74
|
$content .= $self->generate_header_line('Last-Updated:',DateTime->now->strftime('%a, %e %b %y %T %Z')); |
127
|
4
|
|
|
|
|
45
|
$content .= "\n"; |
128
|
4
|
|
|
|
|
12
|
for (sort { $a cmp $b } keys %{$self->modules}) { |
|
2
|
|
|
|
|
29
|
|
|
4
|
|
|
|
|
113
|
|
129
|
5
|
50
|
|
|
|
204
|
$content .= sprintf("%-60s %-20s %s\n",$_,$self->modules->{$_}->[0] ? $self->modules->{$_}->[0] : 'undef',$self->modules->{$_}->[1]); |
130
|
|
|
|
|
|
|
} |
131
|
4
|
|
|
|
|
159
|
return $content; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub generate_header_line { |
135
|
32
|
|
|
32
|
0
|
3122
|
my ( $self, $key, $value ) = @_; |
136
|
32
|
|
|
|
|
158
|
return sprintf("%-13s %s\n",$key,$value); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
__END__ |