blib/lib/Class/constr.pm

filter: Statementstmt 94.0% 47 / 50 Branchbran 73.0% 19 / 26 Conditioncond 74.0% 20 / 27 MC/DCmcdc 30.7% 4 / 13 Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 78.6% 96 / 122 CC 26 SCAR 29.0
CC
26
Cov
83%
__ANON__
25.0
import
6.2
BEGIN
1.0
CRAP 18.3
« blib/lib/Class/groups.pm ↑ Summary blib/lib/Class/props.pm »
1 package Class::constr ;
2 10 $VERSION = 2.40 ;
3 10 ▶use 5.006_001 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶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 10 ▶; $Carp::Internal{+__PACKAGE__}++
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 ; sub import
14 17 ▶ { my ($pkg, @args) = @_
Subroutine import: called CC=6 SCAR=18.3
15 17 ; my $callpkg = caller
16 17 ▶ ; $args[0] ||= {}
Condition100%2/2
$args[0] ||= {}
l!l
89
MC/DC100%1/1
$args[0] ||= {}
$args[0]
Truth table100%2/2
A
A= $args[0]
Aresult
11
00
17 17 ; foreach my $constr ( @args )
18 19 ▶ { my $n = $$constr{name} || 'new'
Condition100%2/2
$constr->{'name'} || 'new'
l!l
514
MC/DC100%1/1
$constr->{'name'} || 'new'
$constr->{'name'}
Truth table100%2/2
A
A= $constr->{'name'}
Aresult
11
00
19 ; $$constr{init} &&= [ $$constr{init} ]
20 19 ▶ unless ref $$constr{init} eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $constr->{"init"} eq "ARRAY" 19 0 19
Condition100%2/2
$constr->{"init"} &&= [$constr->{"init"}]
!ll
163
MC/DC100%1/1
$constr->{"init"} &&= [$constr->{"init"}]
$constr->{"init"}
Truth table100%2/2
A
A= $constr->{"init"}
Aresult
00
11
21 10 ; no strict 'refs'
22 10 ▶ ; *{$callpkg.'::'.$n}
Subroutine BEGIN: called CC=1 SCAR=0.0
23 = sub
24 0 { &{$$constr{pre_process}} if defined $$constr{pre_process}
25 46 ▶ ; my $c = shift
Subroutine __ANON__: called CC=21 SCAR=32.2
Branch: 1 branch
BranchTrueFalseTotal
if defined $constr->{"pre_process"} 0 46 46
26 46 ▶ ; my %props = ref $_[0] eq 'HASH' ? %{$_[0]} : @_
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 46 46
27 46 ▶ ; my $class = ref($c) || $c
Condition66%2/3
ref $c || $c
l!l&&r!l&&!r
4420
MC/DC0%0/2
ref $c || $c
ref $c $c
Truth table66%2/3
A || B
A= ref $cB= $c
ABresult
1X1
011
000
28 46 ; my $s = bless {}, $class
29 46 ; my $default_props = {}
30 46 ▶ ; if (my $cdef = $$constr{default})
Branch: 1 branch
BranchTrueFalseTotal
if (my $cdef = $constr->{"default"}) 6 40 46
31 6 ▶ { $default_props = ref $cdef eq 'HASH' && $cdef
Condition66%10/15
ref $cdef eq 'HASH' && $cdef || ref $cdef eq 'CODE' && $s->$cdef(%props) || !ref($cdef) && $s->$cdef(%props)
l!l&&r!l&&!r
510
ref $cdef eq "HASH" and $cdef or ref $cdef eq "CODE" and $s->$cdef(%props)
l!l&&r!l&&!r
321
ref $cdef eq "HASH" and $cdef
!ll&&!rl&&r
303
ref $cdef eq "CODE" and $s->$cdef(%props)
!ll&&!rl&&r
102
not ref $cdef and $s->$cdef(%props)
!ll&&!rl&&r
001
MC/DC0%0/6
ref $cdef eq 'HASH' && $cdef || ref $cdef eq 'CODE' && $s->$cdef(%props) || !ref($cdef) && $s->$cdef(%props)
ref $cdef eq "HASH" $cdef ref $cdef eq "CODE" $s->$cdef(%props) not ref $cdef $s->$cdef(%props)
Truth table20%3/15
A and B or C and D || not(E) and F
A= ref $cdef eq "HASH"B= $cdefC= ref $cdef eq "CODE"D= $s->$cdef(%props)E= not ref $cdefF= $s->$cdef(%props)
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X111
0X10111
100X111
1010111
0X0X0X0
0X0X100
0X100X0
0X10100
100X0X0
100X100
10100X0
1010100
32 || ref $cdef eq 'CODE' && $s->$cdef(%props)
33 || not (ref $cdef) && $s->$cdef(%props)
34 6 ▶ ; ref $default_props eq 'HASH' or croak
Branch: 1 branch
BranchTrueFalseTotal
ref $default_props eq "HASH" or croak("Invalid default option for '${n}' ($default_props), died") 0 6 6
35 "Invalid default option for '$n' ($default_props), died"
36 }
37 # Values passed to the constructor (%props)
38 # will override copied values, (%$c)
39 # which will override default values (%$default_props)
40 ; %props = ( %$default_props
41 46 ▶ , $$constr{copy} && ref $c ? %$c : ()
Branch: 1 branch
BranchTrueFalseTotal
$constr->{'copy'} && ref $c ? : 3 43 46
Condition66%2/3
$constr->{"copy"} and ref $c
!ll&&!rl&&r
4303
MC/DC50%1/2
$constr->{"copy"} and ref $c
$constr->{"copy"} ref $c
Truth table66%2/3
A and B
A= $constr->{"copy"}B= ref $c
ABresult
0X0
100
111
42 , %props
43 )
44 # Set the initial values for the new object
45 46 ▶ ; while ( my ($p, $v) = each %props )
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %props) 41 34 75
46 41 ▶ { if (my $a = $s->can($p)) # if accessor available, use it
Branch: 1 branch
BranchTrueFalseTotal
if (my $a = $s->can($p)) { } 16 25 41
47 16 { $s->$a( $v )
48 }
49 else
50 { croak "No such property '$p', died"
51 unless $$constr{no_strict}
52 25 ▶ ; if ( $$constr{skip_autoload} )
Branch: 2 branches
BranchTrueFalseTotal
unless $constr->{"no_strict"} 12 13 25
if ($constr->{'skip_autoload'}) { } 0 13 13
53 0 { $$s{$p} = $v
54 }
55 else
56 13 { eval { $s->$p( $v ) } # try AUTOLOAD
57 13 ▶ ; $@ && do{ $$s{$p} = $v } # no strict so just set it
Branch: 1 branch
BranchTrueFalseTotal
$@ and do { $s->{$p} = $v } 13 0 13
58 }
59 }
60 }
61 # Execute any initializer methods
62 34 ▶ ; if ( $$constr{init} )
Branch: 1 branch
BranchTrueFalseTotal
if ($constr->{"init"}) 4 30 34
63 4 { foreach my $m ( @{$$constr{init}} )
64 # any initializer can cancel construction by undefining the
65 # object or returning a Class::Error object (false)
66 # If this happens, no need to continue
67 4 ▶ { last unless $s
Branch: 1 branch
BranchTrueFalseTotal
unless $s 0 4 4
68 4 ; $s->$m(%props)
69 }
70 }
71 34 ; $s
72 }#END sub
73 19 }#END for $constr
74 }#END import
75  
76  
77 10 ; 1
78  
79 __END__
« blib/lib/Class/groups.pm ↑ Summary blib/lib/Class/props.pm »