| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package CPAN::Repository::Role::File; |
|
2
|
|
|
|
|
|
|
BEGIN { |
|
3
|
2
|
|
|
2
|
|
27870
|
$CPAN::Repository::Role::File::AUTHORITY = 'cpan:GETTY'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
{ |
|
6
|
|
|
|
|
|
|
$CPAN::Repository::Role::File::VERSION = '0.008'; |
|
7
|
|
|
|
|
|
|
} |
|
8
|
|
|
|
|
|
|
# ABSTRACT: Role for file functions |
|
9
|
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
18
|
use Moo::Role; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
15
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
701
|
use File::Path qw( make_path ); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
140
|
|
|
13
|
2
|
|
|
2
|
|
11
|
use File::Spec::Functions ':ALL'; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
758
|
|
|
14
|
2
|
|
|
2
|
|
2811
|
use IO::Zlib; |
|
|
2
|
|
|
|
|
226796
|
|
|
|
2
|
|
|
|
|
17
|
|
|
15
|
2
|
|
|
2
|
|
97
|
use IO::File; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
1629
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
requires qw( file_parts generate_content ); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has repository_root => ( |
|
20
|
|
|
|
|
|
|
is => 'ro', |
|
21
|
|
|
|
|
|
|
required => 1, |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has generate_uncompressed => ( |
|
25
|
|
|
|
|
|
|
is => 'ro', |
|
26
|
|
|
|
|
|
|
lazy => 1, |
|
27
|
|
|
|
|
|
|
builder => '_build_generate_uncompressed', |
|
28
|
|
|
|
|
|
|
); |
|
29
|
|
|
|
|
|
|
|
|
30
|
4
|
|
|
4
|
|
990
|
sub _build_generate_uncompressed { 1 } |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub path_inside_root { |
|
33
|
4
|
|
|
4
|
0
|
9
|
my ( $self ) = @_; |
|
34
|
4
|
|
|
|
|
16
|
return join("/",$self->file_parts); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub compressed_path_inside_root { |
|
38
|
0
|
|
|
0
|
0
|
0
|
my ( $self ) = @_; |
|
39
|
0
|
|
|
|
|
0
|
return join("/",$self->file_parts).".gz"; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub full_filename { |
|
43
|
32
|
|
|
32
|
0
|
50
|
my ( $self ) = @_; |
|
44
|
32
|
|
|
|
|
202
|
return catfile( splitdir($self->repository_root), $self->file_parts ); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
24
|
|
|
24
|
0
|
91
|
sub full_compressed_filename { shift->full_filename.".gz" } |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub exist { |
|
50
|
11
|
|
|
11
|
0
|
1236
|
my ( $self ) = @_; |
|
51
|
11
|
100
|
|
|
|
45
|
return 0 unless -f $self->full_compressed_filename; |
|
52
|
6
|
|
|
|
|
101
|
return 1; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub save { |
|
56
|
8
|
|
|
8
|
0
|
11824
|
my ( $self ) = @_; |
|
57
|
8
|
|
|
|
|
74
|
my @pps = $self->file_parts; |
|
58
|
8
|
|
|
|
|
21
|
pop(@pps); |
|
59
|
8
|
100
|
|
|
|
353
|
$self->mkdir( splitdir( $self->repository_root ), @pps ) unless -d catdir( $self->repository_root, @pps ); |
|
60
|
8
|
|
|
|
|
55
|
my $content = $self->generate_content; |
|
61
|
8
|
50
|
|
|
|
51
|
my $gz = IO::Zlib->new($self->full_compressed_filename, "w") or die "cant write to ".$self->full_compressed_filename; |
|
62
|
8
|
|
|
|
|
16982
|
print $gz $content; |
|
63
|
8
|
|
|
|
|
1616
|
$gz->close; |
|
64
|
8
|
50
|
|
|
|
4833
|
if ($self->generate_uncompressed) { |
|
65
|
8
|
50
|
|
|
|
371
|
my $txt = IO::File->new($self->full_filename, "w") or die "cant write to ".$self->full_filename; |
|
66
|
8
|
|
|
|
|
1440
|
print $txt $content; |
|
67
|
8
|
|
|
|
|
35
|
$txt->close; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
8
|
|
|
|
|
660
|
return 1; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub get_file_lines { |
|
73
|
5
|
|
|
5
|
0
|
2355
|
my ( $self ) = @_; |
|
74
|
5
|
50
|
|
|
|
21
|
my $gz = IO::Zlib->new($self->full_compressed_filename, "r") or die "cant read ".$self->full_compressed_filename; |
|
75
|
5
|
|
|
|
|
9212
|
return <$gz>; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub mkdir { |
|
79
|
2
|
|
|
2
|
0
|
22
|
my ( $self, @path ) = @_; |
|
80
|
2
|
|
|
|
|
546
|
make_path(catdir(@path),{ error => \my $err }); |
|
81
|
2
|
50
|
|
|
|
14
|
if (@$err) { |
|
82
|
0
|
|
|
|
|
|
for my $diag (@$err) { |
|
83
|
0
|
|
|
|
|
|
my ($file, $message) = %$diag; |
|
84
|
0
|
0
|
|
|
|
|
if ($file eq '') { |
|
85
|
0
|
|
|
|
|
|
die "general error: $message\n"; |
|
86
|
|
|
|
|
|
|
} else { |
|
87
|
0
|
|
|
|
|
|
die "problem making path $file: $message\n"; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |