Pad/Type/Path.pm

filter: Statementstmt 96.6% 58 / 60 Branchbran 100% 18 / 18 Conditioncond 86.6% 13 / 15 MC/DCmcdc 75.0% 6 / 8 Subroutinesub 90.9% 10 / 11 Podpod 100% 7 / 7 totaltotal 94.1% 112 / 119 CC 15 SCAR 13.8
CC
15
Cov
96%
verify
7.0
prepare
5.0
checkSpecKeys
3.0
CRAP 4.0
« Pad/Config.pm ↑ Summary Pad/Type/Number.pm »
1 23 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 23 ▶use Object::Pad;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 23 ▶use Getopt::Pad::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 class Getopt::Pad::Type::Path :isa(Getopt::Pad::Type) :abstract {
7 23 ▶ use constant SPEC_KEYS => ['mustExist', 'createPathIfMissing'];
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 23 our $VERSION = '0.06';
10  
11 2 field $mustExist :param :reader = 0;
12 0 ▶ field $createPathIfMissing :param :reader = 0;
Subroutine mustExist: called CC=1 SCAR=0.4
Pod documented
13  
14 0 ▶ method checkSpecKeys :common (%args) {
Subroutine checkSpecKeys: called CC=3 SCAR=11.0
Subroutine createPathIfMissing: not called CC=1 SCAR=0.0
Pod documented
Pod documented
15 73 ▶ return 'mustExist and createPathIfMissing are mutually exclusive' if $args{mustExist} && $args{createPathIfMissing};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"mustExist"} and $args{"createPathIfMissing"} 2 71 73
Condition100%3/3
$args{"mustExist"} and $args{"createPathIfMissing"}
!ll&&!rl&&r
40312
MC/DC100%2/2
$args{"mustExist"} and $args{"createPathIfMissing"}
$args{"mustExist"} $args{"createPathIfMissing"}
Truth table100%3/3
A and B
A= $args{"mustExist"}B= $args{"createPathIfMissing"}
ABresult
0X0
100
111
16 71 return undef;
17 23 }
18  
19 63 ▶ method glSuffix() { return '=s' }
Subroutine glSuffix: called CC=1 SCAR=0.0
Pod documented
20  
21 23 method kind;
22 23 method pathExists($value);
23  
24 # Create the path; return undef, or the reason it could not be created.
25 23 method createPath($value);
26  
27 # Whether a path exists depends on the machine, so it is asked of the
28 # value a parse settles on, never of a default when the spec is built.
29 # A path of the wrong kind can neither be used nor created.
30 18 ▶ method verify($value) {
Subroutine verify: called CC=7 SCAR=19.5
Pod documented
31 18 ▶ return undef if !defined $value || (!$mustExist && !$createPathIfMissing);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and $mustExist || $createPathIfMissing 2 16 18
Condition83%5/6
defined $value and $mustExist || $createPathIfMissing
!ll&&!rl&&r
0216
$mustExist or $createPathIfMissing
l!l&&r!l&&!r
1062
MC/DC66%2/3
defined $value and $mustExist || $createPathIfMissing
defined $value $mustExist $createPathIfMissing
Truth table75%3/4
A and B or C
A= defined $valueB= $mustExistC= $createPathIfMissing
ABCresult
0XX0
1000
11X1
1011
32 16 ▶ return undef if $self->pathExists($value);
Branch: 1 branch
BranchTrueFalseTotal
if $self->pathExists($value) 3 13 16
33 13 ▶ return sprintf("'%s' is not a %s", $value, $self->kind) if -e $value;
Branch: 1 branch
BranchTrueFalseTotal
if -e $value 4 9 13
34 9 ▶ return sprintf("%s '%s' does not exist", $self->kind, $value) if $mustExist;
Branch: 1 branch
BranchTrueFalseTotal
if $mustExist 4 5 9
35 5 return undef;
36 23 }
37  
38 11 ▶ method prepare($value) {
Subroutine prepare: called CC=5 SCAR=16.1
Pod documented
39 11 ▶ return undef if !defined $value || !$createPathIfMissing || $self->pathExists($value);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value && $createPathIfMissing or $self->pathExists($value) 4 7 11
Condition83%5/6
not defined $value && $createPathIfMissing or $self->pathExists($value)
l!l&&r!l&&!r
317
defined $value && $createPathIfMissing
!ll&&!rl&&r
038
MC/DC66%2/3
not defined $value && $createPathIfMissing or $self->pathExists($value)
defined $value $createPathIfMissing $self->pathExists($value)
Truth table75%3/4
not(A && B) or C
A= defined $valueB= $createPathIfMissingC= $self->pathExists($value)
ABCresult
0XX1
10X1
1111
1100
40  
41 7 my $reason = $self->createPath($value);
42 7 ▶ return defined $reason ? sprintf("cannot create %s '%s': %s", $self->kind, $value, $reason) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $reason ? : 2 5 7
43 23 }
44  
45 12 ▶ method constraintNotes() {
Subroutine constraintNotes: called CC=3 SCAR=11.0
Pod documented
46 12 ▶ return ('has to exist') if $mustExist;
Branch: 1 branch
BranchTrueFalseTotal
if $mustExist 10 2 12
47 2 ▶ return ('created if missing') if $createPathIfMissing;
Branch: 1 branch
BranchTrueFalseTotal
if $createPathIfMissing 1 1 2
48 1 return ();
49 23 }
50 }
51  
52 23 1;
53  
54 __END__
« Pad/Config.pm ↑ Summary Pad/Type/Number.pm »