blib/lib/Class/props.pm

filter: Statementstmt 89.1% 74 / 83 Branchbran 79.6% 43 / 54 Conditioncond 71.0% 27 / 38 MC/DCmcdc 40.0% 8 / 20 Subroutinesub 100% 14 / 14 Podpod 100% 1 / 1 totaltotal 79.5% 167 / 210 CC 43 SCAR 26.1
CC
43
Cov
82%
STORE
29.4
__ANON__
11.1
FETCH
6.2
CRAP 13.6
« blib/lib/Class/constr.pm ↑ Summary blib/lib/Class/Util.pm »
1 package Class::props ;
2 9 $VERSION = 2.40 ;
3 9 ▶use 5.006_001 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 # This file uses the "Perlish" coding style
7 # please read http://perl.4pro.net/perlish_coding_style.html
8  
9 ; use Carp
10 9 ▶; $Carp::Internal{+__PACKAGE__}++
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 ; sub import
13 15 ▶ { my $tool = shift
Subroutine import: called CC=1 SCAR=0.0
14 15 ; $tool->add_to(scalar caller, @_)
15 }
16  
17 ; sub add_to
18 15 ▶ { my ($tool, $pkg, @args) = @_
Subroutine add_to: called CC=2 SCAR=6.9
Pod documented
19 15 ; foreach my $prop ( @args )
20 43 { $prop = $tool->_init_prop_param( $prop )
21 43 ; $tool->_add_prop( $pkg, $prop )
22 }
23 }
24  
25 ; sub _init_prop_param
26 54 ▶ { my ( $tool, $prop ) = @_
Subroutine _init_prop_param: called CC=5 SCAR=16.3
27 54 ▶ ; $prop = { name => $prop }
Branch: 1 branch
BranchTrueFalseTotal
unless ref $prop eq "HASH" 12 42 54
28 unless ref $prop eq 'HASH'
29 ; $$prop{name} = [ $$prop{name} ]
30 54 ▶ unless ref $$prop{name} eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $prop->{"name"} eq "ARRAY" 44 10 54
31 ; $$prop{allowed} &&= [ $$prop{allowed} ]
32 54 ▶ unless ref $$prop{allowed} eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $prop->{"allowed"} eq "ARRAY" 54 0 54
Condition50%1/2
$prop->{"allowed"} &&= [$prop->{"allowed"}]
!ll
540
MC/DC0%0/1
$prop->{"allowed"} &&= [$prop->{"allowed"}]
$prop->{"allowed"}
Truth table50%1/2
A
A= $prop->{"allowed"}
Aresult
00
11
33 54 ; $prop
34 }
35
36 ; sub _add_prop
37 54 ▶ { my ( $tool, $pkg, $prop ) = @_
Subroutine _add_prop: called CC=6 SCAR=18.0
38 ; my $gr = delete $$prop{group}
39 54 ; my $to_tie = ( defined $$prop{default}
40 || defined $$prop{protected}
41 || defined $$prop{allowed}
42 || defined $$prop{validation}
43 || defined $$prop{post_process}
44 )
45 54 ▶ ; foreach my $n ( @{$$prop{name}} ) # foreach property
Condition83%10/12
defined $prop->{'default'} || defined $prop->{'protected'} || defined $prop->{'allowed'} || defined $prop->{'validation'} || defined $prop->{'post_process'}
l!l&&r!l&&!r
35019
defined $prop->{"default"} or defined $prop->{"protected"} or defined $prop->{"allowed"} or defined $prop->{"validation"}
l!l&&r!l&&!r
231219
defined $prop->{"default"} or defined $prop->{"protected"} or defined $prop->{"allowed"}
l!l&&r!l&&!r
23031
defined $prop->{"default"} or defined $prop->{"protected"}
l!l&&r!l&&!r
20331
MC/DC60%3/5
defined $prop->{'default'} || defined $prop->{'protected'} || defined $prop->{'allowed'} || defined $prop->{'validation'} || defined $prop->{'post_process'}
defined $prop->{"default"} defined $prop->{"protected"} defined $prop->{"allowed"} defined $prop->{"validation"} defined $prop->{'post_process'}
Truth table66%4/6
A or B or C or D || E
A= defined $prop->{"default"}B= defined $prop->{"protected"}C= defined $prop->{"allowed"}D= defined $prop->{"validation"}E= defined $prop->{'post_process'}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
46 9 { no strict 'refs'
47 9 ▶ ; *{$pkg.'::'.$n}
Subroutine BEGIN: called CC=1 SCAR=0.0
48 = sub : lvalue
49 235 ▶ { (@_ > 2) && croak qq(Too many arguments for "$n" property, died)
Subroutine __ANON__: called CC=11 SCAR=24.1
Branch: 1 branch
BranchTrueFalseTotal
@_ > 2 and croak(qq[Too many arguments for "$n" property, died]) 0 235 235
50 ; my $scalar
51 = $tool =~ /^Class/ ? $gr
52 22 ▶ ? \${(ref $_[0]||$_[0]).'::'.$gr}{$n}
Condition66%2/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
1660
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table66%2/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
53 52 ▶ : \${(ref $_[0]||$_[0]).'::'.$n}
Branch: 2 branches
BranchTrueFalseTotal
$tool =~ /^Package/ ? : 77 84 161
$gr ? : 15 62 77
Condition66%2/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
12400
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table66%2/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
54 : $tool =~ /^Package/ ? $gr
55 15 ? \${$pkg.'::'.$gr}{$n}
56 62 ▶ : \${$pkg.'::'.$n}
Branch: 1 branch
BranchTrueFalseTotal
$gr ? : 18 66 84
57 : $gr
58 ? \$_[0]{$gr}{$n}
59 235 ▶ : \$_[0]{$n}
Branch: 2 branches
BranchTrueFalseTotal
$tool =~ /^Class/ ? : 74 161 235
$gr ? : 22 52 74
60 235 ; my $Tscalar
61 235 ▶ ; if ( $to_tie )
Branch: 1 branch
BranchTrueFalseTotal
if ($to_tie) { } 168 67 235
62 168 { tie $$Tscalar
63 , 'Class::props::Tie'
64 , $_[0] # [0] object/class
65 , $n # [1] prop name
66 , $scalar # [2] lvalue ref
67 , $prop # [3] options ref
68 }
69 else
70 67 { $Tscalar = $scalar
71 }
72 235 ▶ ; @_ == 2
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 44 191 235
73 ? ( $$Tscalar = $_[1] )
74 : $$Tscalar
75 }
76 64 }
77 }
78  
79 ; package Class::props::Tie
80 ; use Carp
81 9 ▶; $Carp::Internal{+__PACKAGE__}++
Subroutine BEGIN: called CC=1 SCAR=0.0
82 ; use strict
83  
84 9 ▶; sub TIESCALAR
Subroutine BEGIN: called CC=1 SCAR=0.0
85 168 ▶ { bless \@_, shift
Subroutine TIESCALAR: called CC=1 SCAR=0.0
86 }
87
88 ; sub FETCH
89 { my $val = do
90 102 ▶ { if ( defined ${$_[0][2]} )
Subroutine FETCH: called CC=6 SCAR=18.3
Branch: 2 branches
BranchTrueFalseTotal
if (defined ${$_[0][2];}) { } 58 44 102
elsif (defined $_[0][3]{'default'}) { } 44 0 44
91 58 { ${$_[0][2]}
92 }
93 elsif ( defined $_[0][3]{default} )
94 { my $def = ref $_[0][3]{default} eq 'CODE'
95 ? $_[0][3]{default}( $_[0][0] )
96 : $_[0][3]{default}
97 44 ▶ ; $_[0][3]{no_strict}
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0][3]{'default'} eq 'CODE' ? : 10 34 44
98 44 ▶ ? ${$_[0][2]} = $def
Branch: 1 branch
BranchTrueFalseTotal
$_[0][3]{'no_strict'} ? : 0 44 44
99 : $_[0]->STORE( $def )
100 }
101 else
102 { undef
103 0 }
104 }
105 102 ; local $_ = $val
106 ; defined $_[0][3]{post_process}
107 102 ▶ ? $_[0][3]{post_process}( $_[0][0], $val )
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0][3]{'post_process'} ? : 2 100 102
108 : $val
109 }
110  
111 ; sub STORE
112 128 ▶ { my $from_FETCH = (caller(1))[3]
Subroutine STORE: called CC=18 SCAR=33.8
Condition100%3/3
(caller 1)[3] && (caller 1)[3] =~ /::FETCH$/
!ll&&!rl&&r
127244
MC/DC100%2/2
(caller 1)[3] && (caller 1)[3] =~ /::FETCH$/
(caller 1)[3] (caller 1)[3] =~ /::FETCH$/
Truth table100%3/3
A && B
A= (caller 1)[3]B= (caller 1)[3] =~ /::FETCH$/
ABresult
0X0
100
111
113 && (caller(1))[3] =~ /::FETCH$/
114 128 ▶ ; my $default = $from_FETCH
Branch: 1 branch
BranchTrueFalseTotal
$from_FETCH ? : 44 84 128
115 ? 'default '
116 : ''
117 128 ▶ ; if ( $_[0][3]{protected} # if protected
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0][3]{"protected"} and not $from_FETCH and not $Class::props::force) 18 110 128
Condition83%5/6
$_[0][3]{"protected"} and not $from_FETCH and not $Class::props::force
!ll&&!rl&&r
110018
$_[0][3]{"protected"} and not $from_FETCH
!ll&&!rl&&r
105518
MC/DC66%2/3
$_[0][3]{"protected"} and not $from_FETCH and not $Class::props::force
$_[0][3]{"protected"} not $from_FETCH not $Class::props::force
Truth table75%3/4
A and not(B) and not(C)
A= $_[0][3]{"protected"}B= not $from_FETCHC= not $Class::props::force
ABCresult
0XX0
10X0
1100
1111
118 &&! $from_FETCH # bypass for default
119 &&! $Class::props::force # bypass deliberately
120 )
121 18 { my ($OK, $f)
122 18 ▶ ; until ( $OK )
Branch: 1 branch
BranchTrueFalseTotal
unless ($OK) 36 12 48
123 36 ▶ { last unless my $caller = caller($f++)
Branch: 1 branch
BranchTrueFalseTotal
unless my $caller = caller $f++ 6 30 36
124 30 ; $OK = $caller->can($_[0][1])
125 }
126 18 ▶ ; $OK || croak qq("$_[0][1]" is a read-only property, died)
Branch: 1 branch
BranchTrueFalseTotal
$OK or croak(qq["$_[0][1]" is a read-only property, died]) 6 12 18
127 }
128 122 ▶ ; if ( $_[0][3]{allowed} # if restricted
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0][3]{"allowed"} and not $from_FETCH and not $Class::props::force) 0 122 122
Condition33%2/6
$_[0][3]{"allowed"} and not $from_FETCH and not $Class::props::force
!ll&&!rl&&r
12200
$_[0][3]{"allowed"} and not $from_FETCH
!ll&&!rl&&r
12200
MC/DC0%0/3
$_[0][3]{"allowed"} and not $from_FETCH and not $Class::props::force
$_[0][3]{"allowed"} not $from_FETCH not $Class::props::force
Truth table25%1/4
A and not(B) and not(C)
A= $_[0][3]{"allowed"}B= not $from_FETCHC= not $Class::props::force
ABCresult
0XX0
10X0
1100
1111
129 &&! $from_FETCH # bypass for default
130 &&! $Class::props::force # bypass deliberately
131 )
132 0 { my ($OK, $f)
133 0 ▶ ; until ( $OK )
Branch: 1 branch
BranchTrueFalseTotal
unless ($OK) 0 0 0
134 0 ▶ { last unless my $caller = (caller($f++))[3]
Branch: 1 branch
BranchTrueFalseTotal
unless my $caller = (caller $f++)[3] 0 0 0
135 0 ; $OK = grep { $caller =~ qr/$_/ } @{$_[0][3]{allowed}}
136 }
137 0 ▶ ; $OK || croak qq("$_[0][1]" is a read-only property, died)
Branch: 1 branch
BranchTrueFalseTotal
$OK or croak(qq["$_[0][1]" is a read-only property, died]) 0 0 0
138 }
139 122 ; local $_ = $_[1]
140 122 ▶ ; if ( defined $_[0][3]{validation} # validation subref
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0][3]{"validation"} and defined $_) 41 81 122
Condition66%2/3
defined $_[0][3]{"validation"} and defined $_
!ll&&!rl&&r
81041
MC/DC50%1/2
defined $_[0][3]{"validation"} and defined $_
defined $_[0][3]{"validation"} defined $_
Truth table66%2/3
A and B
A= defined $_[0][3]{"validation"}B= defined $_
ABresult
0X0
100
111
141 && defined $_ # bypass for undef (reset to default)
142 )
143 41 ▶ { $_[0][3]{validation}( $_[0][0], $_)
Branch: 1 branch
BranchTrueFalseTotal
$_[0][3]{"validation"}->($_[0][0], $_) or croak(qq[Invalid ${default}value for "$_[0][1]" property, died]) 6 35 41
144 || croak qq(Invalid ${default}value for "$_[0][1]" property, died)
145 }
146 116 ; ${$_[0][2]} = $_
147 }
148  
149 9 1 ;
150  
151 __END__
« blib/lib/Class/constr.pm ↑ Summary blib/lib/Class/Util.pm »