Usul/File.pm

filter: Statementstmt 81.1% 56 / 69 Branchbran 35.7% 5 / 14 Conditioncond 23.0% 6 / 26 MC/DCmcdc 5.8% 1 / 17 Subroutinesub 88.8% 16 / 18 Podpod 100% 7 / 7 totaltotal 60.2% 91 / 151 CC 17 SCAR 26.4
CC
17
Cov
61%
data_load
56.0
data_dump
12.0
tempname
4.2
CRAP 14.1
« Usul/Crypt/Util.pm ↑ Summary Usul/Getopt/Usage.pm »
1 package Class::Usul::File;
2  
3 20 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 20 ▶use Class::Usul::Constants qw( EXCEPTION_CLASS TRUE );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 20 ▶use Class::Usul::Functions qw( arg_list create_token is_arrayref io
Subroutine BEGIN: called CC=1 SCAR=0.0
7 20 merge_attributes throw );
8 20 ▶use Class::Usul::Types qw( ConfigProvider Locker Logger );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 20 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 20 ▶use File::DataClass::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 20 ▶use File::Spec::Functions qw( catfile );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 20 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 20 ▶use Unexpected::Functions qw( Unspecified );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 20 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # Public attributes
17 20 has 'config' => is => 'ro', isa => ConfigProvider, required => TRUE;
18  
19 20 has 'lock' => is => 'ro', isa => Locker, required => TRUE;
20  
21 20 has 'log' => is => 'ro', isa => Logger, required => TRUE;
22  
23 # Construction
24 5 ▶around 'BUILDARGS' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
25 5 my ($orig, $self, @args) = @_; my $attr = $orig->( $self, @args );
26  
27 5 ▶ my $builder = $attr->{builder} or return $attr;
Branch: 1 branch
BranchTrueFalseTotal
my $builder = $attr->{"builder"} or return $attr 5 0 5
28  
29 5 merge_attributes $attr, $builder, [ 'config', 'lock', 'log' ];
30  
31 5 return $attr;
32 20 };
33  
34 # Public methods
35 0 ▶sub data_dump {
Subroutine data_dump: not called CC=3 SCAR=24.8
Pod documented
36 0 my ($self, @args) = @_; my $args = arg_list @args; my $attr = {};
37  
38 exists $args->{storage_class} and defined $args->{storage_class}
39 0 ▶ and $attr->{storage_class} = delete $args->{storage_class};
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{"storage_class"} and defined $args->{"storage_class"} and $attr->{"storage_class"} = delete $args->{"storage_class"} 0 0 0
Condition0%0/3
exists $args->{"storage_class"} and defined $args->{"storage_class"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $args->{"storage_class"} and defined $args->{"storage_class"}
exists $args->{"storage_class"} defined $args->{"storage_class"}
Truth table0%0/3
A and B
A= exists $args->{"storage_class"}B= defined $args->{"storage_class"}
ABresult
0X0
100
111
40  
41 0 return $self->dataclass_schema( $attr )->dump( $args );
42 }
43  
44 0 ▶sub data_load {
Subroutine data_load: not called CC=7 SCAR=40.3
Pod documented
45 0 my ($self, @args) = @_; my $args = arg_list @args; my $attr = {};
46  
47 exists $args->{storage_class} and defined $args->{storage_class}
48 0 ▶ and $attr->{storage_class} = delete $args->{storage_class};
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{"storage_class"} and defined $args->{"storage_class"} and $attr->{"storage_class"} = delete $args->{"storage_class"} 0 0 0
Condition0%0/3
exists $args->{"storage_class"} and defined $args->{"storage_class"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $args->{"storage_class"} and defined $args->{"storage_class"}
exists $args->{"storage_class"} defined $args->{"storage_class"}
Truth table0%0/3
A and B
A= exists $args->{"storage_class"}B= defined $args->{"storage_class"}
ABresult
0X0
100
111
49  
50 exists $args->{arrays} and defined $args->{arrays}
51 0 ▶ and $attr->{storage_attributes}->{force_array} = $args->{arrays};
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{"arrays"} and defined $args->{"arrays"} and $attr->{"storage_attributes"}{"force_array"} = $args->{"arrays"} 0 0 0
Condition0%0/3
exists $args->{"arrays"} and defined $args->{"arrays"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $args->{"arrays"} and defined $args->{"arrays"}
exists $args->{"arrays"} defined $args->{"arrays"}
Truth table0%0/3
A and B
A= exists $args->{"arrays"}B= defined $args->{"arrays"}
ABresult
0X0
100
111
52  
53 0 ▶ (is_arrayref $args->{paths} and defined $args->{paths}->[ 0 ])
Branch: 1 branch
BranchTrueFalseTotal
&is_arrayref($args->{"paths"}) and defined $args->{"paths"}[0] or &throw(Unspecified(), ["paths"]) 0 0 0
Condition0%0/3
&is_arrayref($args->{"paths"}) and defined $args->{"paths"}[0]
!ll&&!rl&&r
000
MC/DC0%0/2
&is_arrayref($args->{"paths"}) and defined $args->{"paths"}[0]
&is_arrayref($args->{"paths"}) defined $args->{"paths"}[0]
Truth table0%0/3
A and B
A= &is_arrayref($args->{"paths"})B= defined $args->{"paths"}[0]
ABresult
0X0
100
111
54 or throw Unspecified, [ 'paths' ];
55  
56 0 return $self->dataclass_schema( $attr )->load( @{ $args->{paths} } );
57 }
58  
59 3 ▶sub dataclass_schema {
Subroutine dataclass_schema: called CC=3 SCAR=11.0
Pod documented
60 3 my ($self, @args) = @_; my $attr = arg_list @args;
61  
62 3 ▶ if (blessed $self) { $attr->{builder} = $self }
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($self)) { } 1 2 3
63 2 else { $attr->{cache_class} = 'none' }
64  
65 3 ▶ $attr->{storage_class} //= 'Any';
Condition50%1/2
$attr->{"storage_class"} //= "Any"
l!l
03
MC/DC0%0/1
$attr->{"storage_class"} //= "Any"
$attr->{"storage_class"}
Truth table50%1/2
A
A= $attr->{"storage_class"}
Aresult
11
00
66  
67 3 return File::DataClass::Schema->new( $attr );
68 }
69  
70 5 ▶sub delete_tmp_files {
Subroutine delete_tmp_files: called CC=2 SCAR=9.2
Pod documented
71 5 ▶ return io( $_[ 1 ] // $_[ 0 ]->tempdir )->delete_tmp_files;
Condition33%1/3
$_[1] // $_[0]->tempdir
l!l&&r!l&&!r
050
MC/DC0%0/2
$_[1] // $_[0]->tempdir
$_[1] $_[0]->tempdir
Truth table33%1/3
A // B
A= $_[1]B= $_[0]->tempdir
ABresult
1X1
011
000
72 }
73  
74 9 ▶sub tempdir {
Subroutine tempdir: called CC=1 SCAR=0.0
Pod documented
75 9 return $_[ 0 ]->config->tempdir;
76 }
77  
78 1 ▶sub tempfile {
Subroutine tempfile: called CC=2 SCAR=9.2
Pod documented
79 1 ▶ return io( $_[ 1 ] // $_[ 0 ]->tempdir )->tempfile;
Condition33%1/3
$_[1] // $_[0]->tempdir
l!l&&r!l&&!r
010
MC/DC0%0/2
$_[1] // $_[0]->tempdir
$_[1] $_[0]->tempdir
Truth table33%1/3
A // B
A= $_[1]B= $_[0]->tempdir
ABresult
1X1
011
000
80 }
81  
82 1 ▶sub tempname {
Subroutine tempname: called CC=4 SCAR=14.2
Pod documented
83 1 my ($self, $dir) = @_; my $path;
84  
85 1 ▶ while (not $path or -f $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $path or -f $path) 1 1 2
Condition66%2/3
not $path or -f $path
l!l&&r!l&&!r
101
MC/DC50%1/2
not $path or -f $path
not $path -f $path
Truth table66%2/3
not(A) or B
A= not $pathB= -f $path
ABresult
1X1
011
000
86 1 my $file = sprintf '%6.6d%s', $PID, (substr create_token, 0, 4);
87  
88 1 ▶ $path = catfile( $dir // $self->tempdir, $file );
Condition33%1/3
$dir // $self->tempdir
l!l&&r!l&&!r
010
MC/DC0%0/2
$dir // $self->tempdir
$dir $self->tempdir
Truth table33%1/3
A // B
A= $dirB= $self->tempdir
ABresult
1X1
011
000
89 }
90  
91 1 return $path;
92 }
93  
94 20 1;
95  
96 __END__
« Usul/Crypt/Util.pm ↑ Summary Usul/Getopt/Usage.pm »