Param/Base.pm

filter: Statementstmt 98.4% 64 / 65 Branchbran 94.7% 36 / 38 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 14 / 14 Podpod 100% 7 / 7 totaltotal 97.6% 126 / 129 CC 25 SCAR 18.1
CC
25
Cov
97%
param
13.0
add
5.0
has
3.0
CRAP 6.1
« Param/Compound.pm ↑ Summary Param/Encoding.pm »
1 package Class::Param::Base;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 ▶use Carp qw[];
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
9  
10 7 my @abstract = qw[ new get set names remove ];
11  
12 7 foreach my $abstract ( @abstract ) {
13  
14 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 5 ▶ *$abstract = sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
17 5 ▶ my $class = ref $_[0] ? ref shift : shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 5 5
18 5 Carp::croak qq/Abstract method '$abstract' must be implemented in '$class'./;
19 35 };
20 }
21 }
22  
23 16 ▶sub add {
Subroutine add: called CC=5 SCAR=16.1
Pod documented
24 16 my ( $self, $name, @add ) = @_;
25  
26 16 ▶ unless ( $self->has($name) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has($name)) 8 8 16
27  
28 8 my $value;
29  
30 8 ▶ if ( @add == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@add == 1) { } 5 3 8
31 5 ▶ $value = ref $add[0] eq 'ARRAY' ? [ $add[0] ] : $add[0];
Branch: 1 branch
BranchTrueFalseTotal
ref $add[0] eq 'ARRAY' ? : 4 1 5
32 }
33 else {
34 3 $value = \@add;
35 }
36  
37 8 return $self->set( $name => $value );
38 }
39  
40 8 my $value = $self->get($name);
41  
42 8 ▶ unless ( ref $value eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $value eq "ARRAY") 0 8 8
43 0 $value = [ $value ];
44 }
45  
46 8 push @{ $value }, @add;
47  
48 8 return $self->set( $name => $value );
49 }
50  
51 23 ▶sub has {
Subroutine has: called CC=3 SCAR=11.0
Pod documented
52 23 my ( $self, $name ) = @_;
53  
54 23 foreach ( $self->names ) {
55 49 ▶ return 1 if $_ eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $name 17 32 49
56 }
57  
58 6 return 0;
59 }
60  
61 1 ▶sub clear {
Subroutine clear: called CC=2 SCAR=6.9
Pod documented
62 1 my $self = shift;
63  
64 1 foreach ( $self->names ) {
65 2 $self->remove($_);
66 }
67  
68 1 return 1;
69 }
70  
71 2 ▶sub count {
Subroutine count: called CC=1 SCAR=0.0
Pod documented
72 2 return scalar shift->names;
73 }
74  
75 90 ▶sub param {
Subroutine param: called CC=13 SCAR=25.6
Pod documented
76 90 my ( $self, $name, @values ) = @_;
77  
78 90 ▶ if ( @_ == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 6 84 90
79 6 return $self->names;
80 }
81  
82 84 ▶ unless ( defined $name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 6 78 84
83 6 ▶ return wantarray ? () : undef;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 3 6
84 }
85  
86 78 ▶ if ( @_ == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) 62 16 78
87  
88 62 ▶ unless ( $self->has($name) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has($name)) 6 56 62
89 6 ▶ return wantarray ? () : undef;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 3 6
90 }
91  
92 56 my $value = $self->get($name);
93  
94 56 ▶ if ( ref $value eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 34 22 56
95 34 ▶ return wantarray ? @{ $value } : $value->[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 30 4 34
96 }
97 else {
98 22 ▶ return wantarray ? ( $value ) : $value;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 15 7 22
99 }
100 }
101  
102 16 ▶ if ( @values == 1 && ! defined $values[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@values == 1 and not defined $values[0]) 6 10 16
Condition100%3/3
@values == 1 and not defined $values[0]
!ll&&!rl&&r
376
MC/DC100%2/2
@values == 1 and not defined $values[0]
@values == 1 not defined $values[0]
Truth table100%3/3
A and not(B)
A= @values == 1B= not defined $values[0]
ABresult
0X0
100
111
103 6 return $self->remove($name);
104 }
105  
106 10 ▶ return $self->set( $name => @values > 1 ? \@values : $values[0] );
Branch: 1 branch
BranchTrueFalseTotal
@values > 1 ? : 3 7 10
107 }
108  
109 9 ▶sub scan {
Subroutine scan: called CC=2 SCAR=6.9
Pod documented
110 9 my ( $self, $callback ) = @_;
111  
112 9 foreach ( $self->names ) {
113 30 &$callback( $_, $self->param($_) );
114 }
115  
116 9 return 1;
117 }
118  
119 9 ▶sub as_hash {
Subroutine as_hash: called CC=2 SCAR=6.9
Pod documented
120 9 my $self = shift;
121 9 my %hash = ();
122  
123 30 ▶ $self->scan( sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
124 30 ▶ $hash{ shift() } = @_ > 2 ? \@_ : $_[1];
Branch: 1 branch
BranchTrueFalseTotal
@_ > 2 ? : 18 12 30
125 9 });
126  
127 9 ▶ return wantarray ? %hash : \%hash;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 6 9
128 }
129  
130 7 1;
131  
132 __END__
« Param/Compound.pm ↑ Summary Param/Encoding.pm »