Skilletor/Source/Local.pm

filter: Statementstmt 96.6% 29 / 30 Branchbran 100% 10 / 10 Conditioncond 50.0% 3 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 90.0% 9 / 10 Podpod 100% 5 / 5 totaltotal 89.0% 57 / 64 CC 8 SCAR 9.8
CC
8
Cov
91%
expand_home
5.2
_build_dir
2.0
exists
2.0
CRAP 2.7
« Skilletor/Entry.pm ↑ Summary Skilletor/JSON/OrderedHash.pm »
1 package Skilletor::Source::Local;
2 # ABSTRACT: A source read straight from a local directory (author mode)
3  
4 34 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 34 ▶use Skilletor::Error::Source;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 34 ▶use Skilletor::FSUtil qw( path_join );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 34 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 34 with 'Skilletor::Role::Source';
10  
11 34 our $VERSION = '0.001';
12  
13 34 has local_path => (
14 is => 'ro',
15 required => 1,
16 );
17  
18 34 has home => (
19 is => 'ro',
20 );
21  
22 34 has dir => (
23 is => 'lazy',
24 init_arg => undef,
25 );
26  
27 201 ▶sub _build_dir {
Subroutine _build_dir: called CC=2 SCAR=6.9
28 201 my ( $self ) = @_;
29 201 ▶ return defined $self->home ? $self->expand_home( $self->local_path, $self->home ) : $self->local_path;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->home ? : 3 198 201
30 }
31  
32 # A leading ~ or ~/ against the home; other paths pass through.
33 241 ▶sub expand_home {
Subroutine expand_home: called CC=5 SCAR=16.6
Pod documented
34 241 my ( $self, $path, $home ) = @_;
35 241 ▶ return $home if $path eq '~';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "~" 1 240 241
36 240 ▶ return path_join( $home, substr( $path, 2 ) ) if $path =~ m{\A~/} || ( $^O eq 'MSWin32' && $path =~ m{\A~\\} );
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[\A~/] or $^O eq "MSWin32" and $path =~ /\A~\\/ 6 234 240
Condition50%3/6
$path =~ m[\A~/] or $^O eq "MSWin32" and $path =~ /\A~\\/
l!l&&r!l&&!r
60234
$^O eq "MSWin32" and $path =~ /\A~\\/
!ll&&!rl&&r
23400
MC/DC33%1/3
$path =~ m[\A~/] or $^O eq "MSWin32" and $path =~ /\A~\\/
$path =~ m[\A~/] $^O eq "MSWin32" $path =~ /\A~\\/
Truth table50%2/4
A or B and C
A= $path =~ m[\A~/]B= $^O eq "MSWin32"C= $path =~ /\A~\\/
ABCresult
1XX1
0111
00X0
0100
37 234 return $path;
38 }
39  
40 2 ▶sub exists { -d $_[0]->dir ? 1 : 0 }
Subroutine exists: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
-d $_[0]->dir ? : 1 1 2
41  
42 199 ▶sub resolve {
Subroutine resolve: called CC=2 SCAR=6.9
Pod documented
43 199 my ( $self ) = @_;
44 199 ▶ Skilletor::Error::Source->throw( 'local source directory does not exist: '.$self->dir ) unless -e $self->dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $self->dir 1 198 199
45 198 return { dir => $self->dir, version => 'local' };
46 }
47  
48 # No network to avoid: the directory itself.
49 0 ▶sub cached { $_[0]->resolve }
Subroutine cached: not called CC=1 SCAR=6.9
Pod documented
50  
51 # Local sources are always re-rendered.
52 14 ▶sub check { 1 }
Subroutine check: called CC=1 SCAR=0.0
Pod documented
53  
54 34 1;
55  
56 __END__
« Skilletor/Entry.pm ↑ Summary Skilletor/JSON/OrderedHash.pm »