| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
exists $args->{"storage_class"} and defined $args->{"storage_class"}
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"}
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
exists $args->{"storage_class"} and defined $args->{"storage_class"}
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"}
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | exists $args->{arrays} and defined $args->{arrays} | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | and $attr->{storage_attributes}->{force_array} = $args->{arrays}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $args->{"arrays"} and defined $args->{"arrays"}
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"}
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | (is_arrayref $args->{paths} and defined $args->{paths}->[ 0 ]) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
&is_arrayref($args->{"paths"}) and defined $args->{"paths"}[0]
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]
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 63 | 2 | else { $attr->{cache_class} = 'none' } | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 3 | ▶ | $attr->{storage_class} //= 'Any'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$attr->{"storage_class"} //= "Any"
MC/DC0%0/1
$attr->{"storage_class"} //= "Any"
$attr->{"storage_class"}
Truth table50%1/2
A
A= $attr->{"storage_class"}
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
$_[1] // $_[0]->tempdir
$_[1]
$_[0]->tempdir
Truth table33%1/3
A // B
A= $_[1]B= $_[0]->tempdir
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
$_[1] // $_[0]->tempdir
$_[1]
$_[0]->tempdir
Truth table33%1/3
A // B
A= $_[1]B= $_[0]->tempdir
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
not $path or -f $path
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
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
$dir // $self->tempdir
$dir
$self->tempdir
Truth table33%1/3
A // B
A= $dirB= $self->tempdir
| |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 1 | return $path; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 20 | 1; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | __END__ | ||||||||||||||||||||||||||||