JESP/Patch.pm

filter: Statementstmt 86.8% 33 / 38 Branchbran 57.1% 8 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 76.1% 48 / 63 CC 9 SCAR 13.0
CC
9
Cov
76%
_build_file_data
5.3
_build_script_file
5.0
_abs_file_name
2.1
CRAP 3.7
« JESP.pm ↑ Summary JESP/Cmd/Command/about.pm »
1 package App::JESP::Patch;
2 8 $App::JESP::Patch::VERSION = '0.016';
3 8 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 8 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 App::JESP::Patch - A patch
10  
11 =cut
12  
13 8 has 'jesp' => ( is => 'ro', isa => 'App::JESP', required => 1, weak_ref => 1);
14  
15 8 has 'id' => ( is => 'ro', isa => 'Str', required => 1 );
16  
17 # config:
18 8 has 'file' => ( is => 'ro', isa => 'Str' );
19 8 has 'sql' => ( is => 'ro', isa => 'Maybe[Str]' , lazy_build => 1 );
20  
21 # Will be the absolute filename of the script
22 8 has 'script_file' => ( is => 'ro', isa => 'Maybe[Str]', lazy_build => 1);
23  
24 # Slurping stuff from files
25 8 has 'file_data' => ( is => 'ro' , lazy_build => 1 );
26  
27 #Transient properties:
28 8 has 'applied_datetime' => ( is => 'rw', isa => 'Str', required => 0 );
29  
30 4 ▶sub _build_file_data{
Subroutine _build_file_data: called CC=4 SCAR=16.6
31 4 my ($self) = @_;
32 0 ▶ unless( $self->file() ){ return };
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->file) 0 4 4
33  
34 4 my $file = $self->_abs_file_name( $self->file() );
35  
36 0 ▶ unless( ( -e $file ) && ( -r $file ) ){ die "Cannot read file '$file'\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file and -r $file) 0 4 4
Condition33%1/3
-e $file and -r $file
!ll&&!rl&&r
004
MC/DC0%0/2
-e $file and -r $file
-e $file -r $file
Truth table33%1/3
A and B
A= -e $fileB= -r $file
ABresult
0X0
100
111
37 4 return File::Slurp::read_file( $file );
38 }
39  
40 5 ▶sub _abs_file_name{
Subroutine _abs_file_name: called CC=2 SCAR=7.2
41 5 my ($self, $filename) = @_;
42 5 ▶ my $file =
Branch: 1 branch
BranchTrueFalseTotal
'File::Spec'->file_name_is_absolute($filename) ? : 0 5 5
43 File::Spec->file_name_is_absolute( $filename ) ?
44 $filename :
45 File::Spec->catfile( $self->jesp()->home() , $filename);
46 }
47  
48 1 ▶sub _build_script_file{
Subroutine _build_script_file: called CC=4 SCAR=16.1
49 1 my ($self) = @_;
50 0 ▶ unless( $self->file() ){ return; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->file) 0 1 1
51 1 my $file = $self->_abs_file_name( $self->file() );#
52 1 ▶ unless( -r $file ){
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $file) 0 1 1
53 0 confess("File '$file' is not readable (or there)");
54 }
55 # A script is executable
56 1 ▶ if( -x $file ){
Branch: 1 branch
BranchTrueFalseTotal
if (-x $file) 1 0 1
57 1 return $file;
58 }
59 0 return;
60 }
61  
62 5 ▶sub _build_sql{
Subroutine _build_sql: called CC=2 SCAR=6.9
63 5 my ($self) = @_;
64 5 ▶ unless ( $self->file() =~ /\.sql$/ ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->file =~ /\.sql$/) 1 4 5
65 1 return;
66 }
67 4 return $self->file_data();
68 }
69  
70 8 __PACKAGE__->meta()->make_immutable();
71 8 1;
« JESP.pm ↑ Summary JESP/Cmd/Command/about.pm »