Repository/Role/File.pm

filter: Statementstmt 87.7% 50 / 57 Branchbran 56.2% 9 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.3% 14 / 15 Podpod 0.0% 0 / 8 totaltotal 76.0% 73 / 96 SCAR 23.7
CC
10
Cov
81%
mkdir
8.7
save
5.1
get_file_lines
2.0
CRAP 10.7
« Repository.pm ↑ Summary Repository/Mailrc.pm »
1 package CPAN::Repository::Role::File;
2 BEGIN {
3 2 ▶ $CPAN::Repository::Role::File::AUTHORITY = 'cpan:GETTY';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 }
5 {
6 2 $CPAN::Repository::Role::File::VERSION = '0.008';
7 }
8 # ABSTRACT: Role for file functions
9  
10 2 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use File::Path qw( make_path );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use File::Spec::Functions ':ALL';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use IO::Zlib;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 requires qw( file_parts generate_content );
18  
19 2 has repository_root => (
20 is => 'ro',
21 required => 1,
22 );
23  
24 2 has generate_uncompressed => (
25 is => 'ro',
26 lazy => 1,
27 builder => '_build_generate_uncompressed',
28 );
29  
30 4 ▶sub _build_generate_uncompressed { 1 }
Subroutine _build_generate_uncompressed: called CC=1 SCAR=0.0
31  
32 sub path_inside_root {
33 4 ▶ my ( $self ) = @_;
Subroutine path_inside_root: called CC=1 SCAR=0.0
Pod undocumented
34 4 return join("/",$self->file_parts);
35 }
36  
37 sub compressed_path_inside_root {
38 0 ▶ my ( $self ) = @_;
Subroutine compressed_path_inside_root: not called CC=1 SCAR=6.9
Pod undocumented
39 0 return join("/",$self->file_parts).".gz";
40 }
41  
42 sub full_filename {
43 32 ▶ my ( $self ) = @_;
Subroutine full_filename: called CC=1 SCAR=0.0
Pod undocumented
44 32 return catfile( splitdir($self->repository_root), $self->file_parts );
45 }
46  
47 24 ▶sub full_compressed_filename { shift->full_filename.".gz" }
Subroutine full_compressed_filename: called CC=1 SCAR=0.0
Pod undocumented
48  
49 sub exist {
50 11 ▶ my ( $self ) = @_;
Subroutine exist: called CC=2 SCAR=6.9
Pod undocumented
51 11 ▶ return 0 unless -f $self->full_compressed_filename;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $self->full_compressed_filename 5 6 11
52 6 return 1;
53 }
54  
55 sub save {
56 8 ▶ my ( $self ) = @_;
Subroutine save: called CC=5 SCAR=16.2
Pod undocumented
57 8 my @pps = $self->file_parts;
58 8 pop(@pps);
59 8 ▶ $self->mkdir( splitdir( $self->repository_root ), @pps ) unless -d catdir( $self->repository_root, @pps );
Branch: 1 branch
BranchTrueFalseTotal
unless -d catdir($self->repository_root, @pps) 2 6 8
60 8 my $content = $self->generate_content;
61 8 ▶ my $gz = IO::Zlib->new($self->full_compressed_filename, "w") or die "cant write to ".$self->full_compressed_filename;
Branch: 1 branch
BranchTrueFalseTotal
my $gz = "IO::Zlib"->new($self->full_compressed_filename, "w") or die 'cant write to ' . $self->full_compressed_filename 0 8 8
62 8 print $gz $content;
63 8 $gz->close;
64 8 ▶ if ($self->generate_uncompressed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->generate_uncompressed) 8 0 8
65 8 ▶ my $txt = IO::File->new($self->full_filename, "w") or die "cant write to ".$self->full_filename;
Branch: 1 branch
BranchTrueFalseTotal
my $txt = "IO::File"->new($self->full_filename, "w") or die 'cant write to ' . $self->full_filename 0 8 8
66 8 print $txt $content;
67 8 $txt->close;
68 }
69 8 return 1;
70 }
71  
72 sub get_file_lines {
73 5 ▶ my ( $self ) = @_;
Subroutine get_file_lines: called CC=2 SCAR=7.1
Pod undocumented
74 5 ▶ my $gz = IO::Zlib->new($self->full_compressed_filename, "r") or die "cant read ".$self->full_compressed_filename;
Branch: 1 branch
BranchTrueFalseTotal
my $gz = "IO::Zlib"->new($self->full_compressed_filename, "r") or die 'cant read ' . $self->full_compressed_filename 0 5 5
75 5 return <$gz>;
76 }
77  
78 sub mkdir {
79 2 ▶ my ( $self, @path ) = @_;
Subroutine mkdir: called CC=4 SCAR=21.7
Pod undocumented
80 2 make_path(catdir(@path),{ error => \my $err });
81 2 ▶ if (@$err) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$err) 0 2 2
82 0 for my $diag (@$err) {
83 0 my ($file, $message) = %$diag;
84 0 ▶ if ($file eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($file eq '') { } 0 0 0
85 0 die "general error: $message\n";
86 } else {
87 0 die "problem making path $file: $message\n";
88 }
89 }
90 }
91 }
92  
93 2 1;
94  
95  
96 __END__
97 =pod
98  
99 =head1 NAME
100  
101 CPAN::Repository::Role::File - Role for file functions
102  
103 =head1 VERSION
104  
105 version 0.008
106  
107 =encoding utf8
108  
109 =head1 SUPPORT
110  
111 IRC
112  
113 Join #duckduckgo on irc.freenode.net. Highlight Getty for fast reaction :).
114  
115 Repository
116  
117 http://github.com/Getty/p5-cpan-repository
118 Pull request and additional contributors are welcome
119  
120 Issue Tracker
121  
122 http://github.com/Getty/p5-cpan-repository/issues
123  
124 =head1 AUTHOR
125  
126 Torsten Raudssus <torsten@raudss.us> L<http://raudss.us/>
127  
128 =head1 COPYRIGHT AND LICENSE
129  
130 This software is copyright (c) 2012 by DuckDuckGo, Inc. L<http://duckduckgo.com/>.
131  
132 This is free software; you can redistribute it and/or modify it under
133 the same terms as the Perl 5 programming language system itself.
134  
135 =cut
136  
« Repository.pm ↑ Summary Repository/Mailrc.pm »