Lazy.pm

filter: Statementstmt 75.7% 72 / 95 Branchbran 30.0% 9 / 30 Conditioncond 36.6% 11 / 30 MC/DCmcdc 10.0% 2 / 20 Subroutinesub 100% 13 / 13 Podpod 100% 3 / 3 totaltotal 57.5% 110 / 191 CC 27 SCAR 44.0
CC
27
Cov
59%
_mk_lazy_accessors
126.9
follow_best_practice
2.1
_mk_accessors
2.1
CRAP 81.8
↑ Summary Lazy/Original.pm »
1 package Class::Accessor::Lazy;
2 1 ▶use strict; use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use parent 'Class::Accessor';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Class::Accessor::Lazy::Original;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Class::Accessor::Lazy::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 1 our $VERSION = '1.003'; # change in pod
10
11 2 ▶sub mk_lazy_accessors {
Subroutine mk_lazy_accessors: called CC=1 SCAR=0.0
Pod documented
12 2 my($self, @fields) = @_;
13
14 2 return $self->_mk_lazy_accessors('rw', @fields);
15 }
16 2 ▶sub mk_lazy_ro_accessors {
Subroutine mk_lazy_ro_accessors: called CC=1 SCAR=0.0
Pod documented
17 2 my($self, @fields) = @_;
18
19 2 return $self->_mk_lazy_accessors('ro', @fields);
20 }
21
22
23 1 *make_lazy_accessor = \&Class::Accessor::Lazy::Original::make_accessor;
24 1 *make_lazy_ro_accessor = \&Class::Accessor::Lazy::Original::make_ro_accessor;
25 1 *make_lazy_wo_accessor = \&Class::Accessor::Lazy::Original::make_wo_accessor;
26
27 {
28 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
29
30 2 ▶ sub follow_best_practice {
Subroutine follow_best_practice: called CC=2 SCAR=7.4
Pod documented
31 2 my $self = shift;
32 2 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
33
34 2 $class->SUPER::follow_best_practice();
35
36 2 return $self;
37 }
38
39 6 ▶ sub _mk_accessors {
Subroutine _mk_accessors: called CC=2 SCAR=7.4
40 6 my $self = shift;
41 6 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
060
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
42
43 6 $class->SUPER::_mk_accessors(@_);
44
45 6 return $self;
46 }
47
48 4 ▶ sub _mk_lazy_accessors {
Subroutine _mk_lazy_accessors: called CC=25 SCAR=48.4
49 4 my $self = shift;
50 4 my($access, @fields) = @_;
51 4 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
52 4 ▶ my $ra = $access eq 'rw' || $access eq 'ro';
Condition66%2/3
$access eq 'rw' || $access eq 'ro'
l!l&&r!l&&!r
220
MC/DC0%0/2
$access eq 'rw' || $access eq 'ro'
$access eq 'rw' $access eq 'ro'
Truth table66%2/3
A || B
A= $access eq 'rw'B= $access eq 'ro'
ABresult
1X1
011
000
53 4 ▶ my $wa = $access eq 'rw' || $access eq 'wo';
Condition66%2/3
$access eq 'rw' || $access eq 'wo'
l!l&&r!l&&!r
202
MC/DC50%1/2
$access eq 'rw' || $access eq 'wo'
$access eq 'rw' $access eq 'wo'
Truth table66%2/3
A || B
A= $access eq 'rw'B= $access eq 'wo'
ABresult
1X1
011
000
54
55 4 foreach my $field (@fields) {
56 4 my $accessor_name = $self->accessor_name_for($field);
57 4 my $mutator_name = $self->mutator_name_for($field);
58 4 ▶ if( $accessor_name eq 'DESTROY' or $mutator_name eq 'DESTROY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($accessor_name eq "DESTROY" or $mutator_name eq "DESTROY") 0 4 4
Condition33%1/3
$accessor_name eq "DESTROY" or $mutator_name eq "DESTROY"
l!l&&r!l&&!r
004
MC/DC0%0/2
$accessor_name eq "DESTROY" or $mutator_name eq "DESTROY"
$accessor_name eq "DESTROY" $mutator_name eq "DESTROY"
Truth table33%1/3
A or B
A= $accessor_name eq "DESTROY"B= $mutator_name eq "DESTROY"
ABresult
1X1
011
000
59 0 $self->_carp("Having a data accessor named DESTROY in '$class' is unwise.");
60 }
61
62 4 my $lazy;
63 4 ▶ if ($accessor_name eq $mutator_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($accessor_name eq $mutator_name) { } 0 4 4
64 0 my $accessor;
65 0 ▶ if ($ra && $wa) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ra and $wa) { } 0 0 0
elsif ($ra) { } 0 0 0
Condition0%0/3
$ra and $wa
!ll&&!rl&&r
000
MC/DC0%0/2
$ra and $wa
$ra $wa
Truth table0%0/3
A and B
A= $raB= $wa
ABresult
0X0
100
111
66 0 $accessor = $self->make_lazy_accessor($field);
67 0 $lazy = 1;
68 } elsif ($ra) {
69 0 $accessor = $self->make_lazy_ro_accessor($field);
70 0 $lazy = 1;
71 } else {
72 0 $accessor = $self->make_lazy_wo_accessor($field);
73 }
74
75 0 my $fullname = "${class}::$accessor_name";
76 0 my $subnamed = 0;
77 0 ▶ unless (defined &{$fullname}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &{$fullname;}) 0 0 0
78 0 ▶ subname($fullname, $accessor) if defined &subname;
Branch: 1 branch
BranchTrueFalseTotal
if defined &Class::Accessor::Lazy::subname 0 0 0
79 0 $subnamed = 1;
80 0 *{$fullname} = $accessor;
81 }
82 0 ▶ if ($accessor_name eq $field) {
Branch: 1 branch
BranchTrueFalseTotal
if ($accessor_name eq $field) 0 0 0
83 # the old behaviour
84 0 my $alias = "${class}::_${field}_accessor";
85 0 ▶ subname($alias, $accessor) if defined &subname and not $subnamed;
Branch: 1 branch
BranchTrueFalseTotal
if defined &Class::Accessor::Lazy::subname and not $subnamed 0 0 0
Condition0%0/3
defined &Class::Accessor::Lazy::subname and not $subnamed
!ll&&!rl&&r
000
MC/DC0%0/2
defined &Class::Accessor::Lazy::subname and not $subnamed
defined &Class::Accessor::Lazy::subname not $subnamed
Truth table0%0/3
A and not(B)
A= defined &Class::Accessor::Lazy::subnameB= not $subnamed
ABresult
0X0
100
111
86 0 ▶ *{$alias} = $accessor unless defined &{$alias};
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{$alias;} 0 0 0
87 }
88 } else {
89 4 my $fullaccname = "${class}::$accessor_name";
90 4 my $fullmutname = "${class}::$mutator_name";
91 4 ▶ if ($ra and not defined &{$fullaccname}) { # guess, we need warning here, that accessor exists
Branch: 1 branch
BranchTrueFalseTotal
if ($ra and not defined &{$fullaccname;}) 4 0 4
Condition33%1/3
$ra and not defined &{$fullaccname;}
!ll&&!rl&&r
004
MC/DC0%0/2
$ra and not defined &{$fullaccname;}
$ra not defined &{$fullaccname;}
Truth table33%1/3
A and not(B)
A= $raB= not defined &{$fullaccname;}
ABresult
0X0
100
111
92 4 my $accessor = $self->make_lazy_ro_accessor($field);
93 4 $lazy = 1;
94 4 ▶ subname($fullaccname, $accessor) if defined &subname;
Branch: 1 branch
BranchTrueFalseTotal
if defined &Class::Accessor::Lazy::subname 0 4 4
95 4 *{$fullaccname} = $accessor;
96 }
97 4 ▶ if ($wa and not defined &{$fullmutname}) { # guess, we need warning here, that mutator exists
Branch: 1 branch
BranchTrueFalseTotal
if ($wa and not defined &{$fullmutname;}) 2 2 4
Condition66%2/3
$wa and not defined &{$fullmutname;}
!ll&&!rl&&r
202
MC/DC50%1/2
$wa and not defined &{$fullmutname;}
$wa not defined &{$fullmutname;}
Truth table66%2/3
A and not(B)
A= $waB= not defined &{$fullmutname;}
ABresult
0X0
100
111
98 2 my $mutator = $self->make_lazy_wo_accessor($field);
99 2 ▶ subname($fullmutname, $mutator) if defined &subname;
Branch: 1 branch
BranchTrueFalseTotal
if defined &Class::Accessor::Lazy::subname 0 2 2
100 2 *{$fullmutname} = $mutator;
101 }
102 }
103
104 4 ▶ if( $lazy )
Branch: 1 branch
BranchTrueFalseTotal
if ($lazy) 4 0 4
105 {
106 4 my $init_method = "${class}::_lazy_init_$field";
107 4 ▶ unless (defined &{$init_method} ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &{$init_method;}) 0 4 4
108 0 $self->_croak("Unable to create lazy accessor '$field' without defined init method $init_method");
109 }
110 }
111 }
112 4 return $self;
113 }
114 }
115
116 1 1;
117
118 __END__
↑ Summary Lazy/Original.pm »