line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPAN::Repository::Role::File; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GETTY'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Role for file functions |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
36052
|
use Moo::Role; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
21
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.010'; |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
1064
|
use File::Path qw( make_path ); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
171
|
|
10
|
3
|
|
|
3
|
|
26
|
use File::Spec::Functions ':ALL'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
684
|
|
11
|
3
|
|
|
3
|
|
2677
|
use IO::Zlib; |
|
3
|
|
|
|
|
235128
|
|
|
3
|
|
|
|
|
33
|
|
12
|
3
|
|
|
3
|
|
146
|
use IO::File; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
2279
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
requires qw( file_parts generate_content ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has repository_root => ( |
17
|
|
|
|
|
|
|
is => 'ro', |
18
|
|
|
|
|
|
|
required => 1, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has generate_uncompressed => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
lazy => 1, |
24
|
|
|
|
|
|
|
builder => '_build_generate_uncompressed', |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
4
|
|
|
4
|
|
663
|
sub _build_generate_uncompressed { 1 } |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub path_inside_root { |
30
|
4
|
|
|
4
|
0
|
11
|
my ( $self ) = @_; |
31
|
4
|
|
|
|
|
17
|
return join("/",$self->file_parts); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub compressed_path_inside_root { |
35
|
0
|
|
|
0
|
0
|
0
|
my ( $self ) = @_; |
36
|
0
|
|
|
|
|
0
|
return join("/",$self->file_parts).".gz"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub full_filename { |
40
|
33
|
|
|
33
|
0
|
52
|
my ( $self ) = @_; |
41
|
33
|
|
|
|
|
179
|
return catfile( splitdir($self->repository_root), $self->file_parts ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
25
|
|
|
25
|
0
|
78
|
sub full_compressed_filename { shift->full_filename.".gz" } |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub exist { |
47
|
12
|
|
|
12
|
0
|
1325
|
my ( $self ) = @_; |
48
|
12
|
100
|
|
|
|
40
|
return 0 unless -f $self->full_compressed_filename; |
49
|
6
|
|
|
|
|
98
|
return 1; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub save { |
53
|
8
|
|
|
8
|
0
|
100922
|
my ( $self ) = @_; |
54
|
8
|
|
|
|
|
47
|
my @pps = $self->file_parts; |
55
|
8
|
|
|
|
|
19
|
pop(@pps); |
56
|
8
|
100
|
|
|
|
244
|
$self->mkdir( splitdir( $self->repository_root ), @pps ) unless -d catdir( $self->repository_root, @pps ); |
57
|
8
|
|
|
|
|
74
|
my $content = $self->generate_content; |
58
|
8
|
50
|
|
|
|
111
|
my $gz = IO::Zlib->new($self->full_compressed_filename, "w") or die "cant write to ".$self->full_compressed_filename; |
59
|
8
|
|
|
|
|
16024
|
print $gz $content; |
60
|
8
|
|
|
|
|
1338
|
$gz->close; |
61
|
8
|
50
|
|
|
|
2895
|
if ($self->generate_uncompressed) { |
62
|
8
|
50
|
|
|
|
213
|
my $txt = IO::File->new($self->full_filename, "w") or die "cant write to ".$self->full_filename; |
63
|
8
|
|
|
|
|
1247
|
print $txt $content; |
64
|
8
|
|
|
|
|
30
|
$txt->close; |
65
|
|
|
|
|
|
|
} |
66
|
8
|
|
|
|
|
430
|
return 1; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub get_file_lines { |
70
|
5
|
|
|
5
|
0
|
2368
|
my ( $self ) = @_; |
71
|
5
|
50
|
|
|
|
21
|
my $gz = IO::Zlib->new($self->full_compressed_filename, "r") or die "cant read ".$self->full_compressed_filename; |
72
|
5
|
|
|
|
|
9759
|
return <$gz>; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub mkdir { |
76
|
2
|
|
|
2
|
0
|
18
|
my ( $self, @path ) = @_; |
77
|
2
|
|
|
|
|
353
|
make_path(catdir(@path),{ error => \my $err }); |
78
|
2
|
50
|
|
|
|
12
|
if (@$err) { |
79
|
0
|
|
|
|
|
|
for my $diag (@$err) { |
80
|
0
|
|
|
|
|
|
my ($file, $message) = %$diag; |
81
|
0
|
0
|
|
|
|
|
if ($file eq '') { |
82
|
0
|
|
|
|
|
|
die "general error: $message\n"; |
83
|
|
|
|
|
|
|
} else { |
84
|
0
|
|
|
|
|
|
die "problem making path $file: $message\n"; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |