Lazy/Fast.pm

filter: Statementstmt 71.0% 49 / 69 Branchbran 41.6% 5 / 12 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 76.9% 10 / 13 Podpod 0.0% 0 / 5 totaltotal 59.6% 65 / 109 CC 9 SCAR 13.5
CC
9
Cov
63%
__ANON__
12.0
new
6.0
__ANON__
3.6
CRAP 3.9
« Lazy/Original.pm ↑ Summary
1 package Class::Accessor::Lazy::Fast;
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 Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Class::Accessor::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 1 our $VERSION = '1.000';
7
8 sub new
9 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
10 0 my( $proto, @args ) = @_;
11 0 ▶ $proto = ref $proto || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
12
13 0 my $self = $proto->SUPER::new(@args);
14 0 $self->{'__lazy_inits'} = {};
15
16 0 return $self;
17 }
18
19 1 our @EXPORT;
20
21 1 push @EXPORT, 'fast_accessors';
22 1 ▶sub fast_accessors{
Subroutine fast_accessors: called CC=2 SCAR=6.9
Pod undocumented
23 1 my $self = shift;
24 1 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
25
26 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
27
28 1 *{"${class}::make_accessor"} = \&Class::Accessor::Fast::make_accessor;
29 1 *{"${class}::make_ro_accessor"} = \&Class::Accessor::Fast::make_ro_accessor;
30 1 *{"${class}::make_wo_accessor"} = \&Class::Accessor::Fast::make_wo_accessor;
31 1 *{"${class}::make_lazy_accessor"} = \&Class::Accessor::Lazy::Fast::make_accessor;
32 1 *{"${class}::make_lazy_ro_accessor"} = \&Class::Accessor::Lazy::Fast::make_ro_accessor;
33 1 *{"${class}::make_lazy_wo_accessor"} = \&Class::Accessor::Lazy::Fast::make_wo_accessor;
34
35 1 return $self;
36 }
37
38
39 0 ▶sub make_accessor {
Subroutine make_accessor: not called CC=1 SCAR=6.9
Pod undocumented
40 0 my ($class, $field) = @_;
41
42 0 ▶ return sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
43 0 my $self = shift;
44
45 0 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
46 {
47 0 $self->{'__lazy_inits'}->{$field} = 1;
48 0 return $self->{$field} = $_[0];
49 }
50 else
51 {
52 0 ▶ if( not exists $self->{'__lazy_inits'}->{$field} )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"__lazy_inits"}{$field}) 0 0 0
53 {
54 0 my $init_method = "_lazy_init_$field";
55 0 $self->$init_method();
56 0 $self->{'__lazy_inits'}->{$field} = 1;
57 }
58
59 0 return $self->{$field};
60 }
61 0 };
62 }
63
64 2 ▶sub make_ro_accessor {
Subroutine make_ro_accessor: called CC=1 SCAR=0.1
Pod undocumented
65 2 my($class, $field) = @_;
66
67 8 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.3
68 8 my $self = shift;
69
70 8 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 8 8
71 {
72 0 my $caller = caller;
73 0 $self->_croak("'$caller' cannot alter the value of '$field' on objects of class '$class'");
74 }
75 else
76 {
77 8 ▶ if( not exists $self->{'__lazy_inits'}->{$field} )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"__lazy_inits"}{$field}) 4 4 8
78 {
79 4 my $init_method = "_lazy_init_$field";
80 4 $self->$init_method();
81 4 $self->{'__lazy_inits'}->{$field} = 1;
82 }
83 8 return $self->{$field};
84 }
85 2 };
86 }
87
88 # requires only for best_practice rw acessors
89 1 ▶sub make_wo_accessor {
Subroutine make_wo_accessor: called CC=1 SCAR=0.4
Pod undocumented
90 1 my($class, $field) = @_;
91
92 2 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=12.7
93 2 my $self = shift;
94
95 2 ▶ if( not scalar @_)
Branch: 1 branch
BranchTrueFalseTotal
if (not scalar @_) { } 0 2 2
96 {
97 0 my $caller = caller;
98 0 $self->_croak("'$caller' cannot access the value of '$field' on objects of class '$class'");
99 }
100 else
101 {
102 2 ▶ $self->{'__lazy_inits'}->{$field} = 1 unless exists $self->{'__lazy_inits'}->{$field};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"__lazy_inits"}{$field} 0 2 2
103 2 return $self->{$field} = $_[0];
104 }
105 1 };
106 }
107
108 1 1;
« Lazy/Original.pm ↑ Summary