Lazy.pm

filter: Statementstmt 96.2% 76 / 79 Branchbran 82.1% 23 / 28 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 93.7% 15 / 16 Podpod 100% 5 / 5 totaltotal 92.0% 127 / 138 CC 19 SCAR 14.8
CC
19
Cov
92%
DOES
9.1
isa
6.0
VERSION
4.0
CRAP 4.4
↑ Summary Lazy/Ref.pm »
1 package Object::Lazy; ## no critic (TidyCode)
2
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 15 our $VERSION = '0.16';
7
8 15 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use Object::Lazy::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
11
12 18 ▶sub new { ## no critic (ArgUnpacking)
Subroutine new: called CC=2 SCAR=6.9
Pod documented
13 18 my ($class, $params) = Object::Lazy::Validate::validate_new(@_);
14
15 18 $params = Object::Lazy::Validate::init($params);
16 17 my $self = bless $params, $class;
17 17 ▶ if ( exists $params->{ref} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params->{"ref"}) 1 16 17
18 1 Object::Lazy::Ref::register($self);
19 }
20
21 17 return $self;
22 }
23
24 14 ▶my $build_object = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
25 14 my ($self, $self_ref) = @_;
26
27 14 local *__ANON__ = 'BUILD_OBJECT'; ## no critic (LocalVars)
28 14 my $built_object = $self->{build}->();
29 # don't build a second time
30 14 ▶ $self->{build} = sub { return $built_object };
Subroutine __ANON__: called CC=1 SCAR=0.0
31 14 ▶ if ( ! $self->{is_built} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"is_built"}) 9 5 14
32 9 $self->{is_built} = 1;
33 9 ▶ if ( exists $self->{logger} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"logger"}) 1 8 9
34 1 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
35 1 confess('object built');
36 }
37 1 ▶ catch {
Subroutine __ANON__: called CC=1 SCAR=0.0
38 1 $self->{logger}->($_);
39 1 };
40 }
41 }
42 14 ${$self_ref} = $built_object;
43
44 14 return $built_object;
45 15 };
46
47 0 ▶sub DESTROY {} # is not AUTOLOAD
Subroutine DESTROY: not called CC=1 SCAR=0.0
48
49 6 ▶sub AUTOLOAD { ## no critic (Autoloading ArgUnpacking)
Subroutine AUTOLOAD: called CC=1 SCAR=0.0
50 6 my $self = $_[0];
51
52 6 my $method = substr our $AUTOLOAD, 2 + length __PACKAGE__;
53 6 my $built_object = $build_object->($self, \$_[0]);
54
55 6 return $built_object->$method( @_[1 .. $#_] );
56 }
57
58 5 ▶sub isa { ## no critic (ArgUnpacking)
Subroutine isa: called CC=6 SCAR=17.9
Pod documented
59 5 my ($self, $class2check) = @_;
60
61 my @isa
62 = ref $self->{isa} eq 'ARRAY'
63 5 ? @{ $self->{isa} }
64 5 ▶ : ( $self->{isa} );
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'isa'} eq 'ARRAY' ? : 5 0 5
65 5 ▶ if ( $self->{is_built} || ! @isa ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"is_built"} or not @isa) 3 2 5
Condition100%3/3
$self->{"is_built"} or not @isa
l!l&&r!l&&!r
122
MC/DC100%2/2
$self->{"is_built"} or not @isa
$self->{"is_built"} not @isa
Truth table100%3/3
A or not(B)
A= $self->{"is_built"}B= not @isa
ABresult
1X1
011
000
66 3 my $built_object = $build_object->($self, \$_[0]);
67 3 return $built_object->isa($class2check);
68 }
69 2 CLASS: for my $class (@isa) {
70 4 ▶ $class->isa($class2check) and return 1;
Branch: 1 branch
BranchTrueFalseTotal
$class->isa($class2check) and return 1 1 3 4
71 }
72 1 my %isa = map { ($_ => undef) } @isa;
73
74 1 return exists $isa{$class2check};
75 }
76
77 3 ▶sub DOES { ## no critic (ArgUnpacking)
Subroutine DOES: called CC=8 SCAR=22.1
Pod documented
78 3 my ($self, $class2check) = @_;
79
80 3 ▶ UNIVERSAL->can('DOES')
Branch: 1 branch
BranchTrueFalseTotal
"UNIVERSAL"->can("DOES") or confess("UNIVERSAL 1.04 (Perl 5.10) required for method DOES") 3 0 3
81 or confess 'UNIVERSAL 1.04 (Perl 5.10) required for method DOES';
82
83 my @does
84 = ref $self->{DOES} eq 'ARRAY'
85 3 ? @{ $self->{DOES} }
86 3 ▶ : ( $self->{DOES} );
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'DOES'} eq 'ARRAY' ? : 3 0 3
87 my @isa_and_does = (
88 (
89 ref $self->{isa} eq 'ARRAY'
90 3 ? @{ $self->{isa} }
91 : ( $self->{isa} )
92 3 ▶ ),
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'isa'} eq 'ARRAY' ? : 3 0 3
93 @does,
94 );
95 3 ▶ if ( $self->{is_built} || ! @isa_and_does ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"is_built"} or not @isa_and_does) 1 2 3
Condition66%2/3
$self->{"is_built"} or not @isa_and_does
l!l&&r!l&&!r
102
MC/DC50%1/2
$self->{"is_built"} or not @isa_and_does
$self->{"is_built"} not @isa_and_does
Truth table66%2/3
A or not(B)
A= $self->{"is_built"}B= not @isa_and_does
ABresult
1X1
011
000
96 1 my $built_object = $build_object->($self, \$_[0]);
97 1 return $built_object->DOES($class2check);
98 }
99 2 CLASS: for my $class (@does) {
100 3 ▶ $class->DOES($class2check) and return 1;
Branch: 1 branch
BranchTrueFalseTotal
$class->DOES($class2check) and return 1 2 1 3
101 }
102 0 my %isa_and_does = map { ($_ => undef) } @isa_and_does;
103
104 0 return exists $isa_and_does{$class2check};
105 }
106
107 3 ▶sub can { ## no critic (ArgUnpacking)
Subroutine can: called CC=1 SCAR=0.0
Pod documented
108 3 my ($self, $method) = @_;
109
110 3 my $built_object = $build_object->($self, \$_[0]);
111
112 3 return $built_object->can($method);
113 }
114
115 3 ▶sub VERSION { ## no critic (ArgUnpacking)
Subroutine VERSION: called CC=4 SCAR=13.9
Pod documented
116 3 my ($self, @version) = @_;
117
118 3 ▶ if ( ! $self->{is_built} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"is_built"}) 3 0 3
119 3 ▶ if ( defined $self->{VERSION} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"VERSION"}) 1 2 3
120 1 $Object::Lazy::Version::VERSION = $self->{VERSION};
121 1 return +( bless {}, 'Object::Lazy::Version' )->VERSION(@version);
122 }
123 2 ▶ if ( $self->{version_from} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"version_from"}) 1 1 2
124 1 return +( bless {}, $self->{version_from} )->VERSION(@version);
125 }
126 }
127 1 my $built_object = $build_object->($self, \$_[0]);
128
129 1 return $built_object->VERSION(@version);
130 }
131
132 # $Id$
133
134 15 1;
135
136 __END__
↑ Summary Lazy/Ref.pm »