| 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
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||
| 52 | 4 | ▶ | my $ra = $access eq 'rw' || $access eq 'ro'; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$access eq 'rw' || $access eq 'ro'
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'
| |||||||||||||||||||||||||||||||||
| 53 | 4 | ▶ | my $wa = $access eq 'rw' || $access eq 'wo'; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$access eq 'rw' || $access eq 'wo'
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'
| |||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$accessor_name eq "DESTROY" or $mutator_name eq "DESTROY"
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"
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 64 | 0 | my $accessor; | |||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ($ra && $wa) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$ra and $wa
MC/DC0%0/2
$ra and $wa
$ra
$wa
Truth table0%0/3
A and B
A= $raB= $wa
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | subname($fullname, $accessor) if defined &subname; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 79 | 0 | $subnamed = 1; | |||||||||||||||||||||||||||||||
| 80 | 0 | *{$fullname} = $accessor; | |||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ($accessor_name eq $field) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined &Class::Accessor::Lazy::subname and not $subnamed
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
| |||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | *{$alias} = $accessor unless defined &{$alias}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$ra and not defined &{$fullaccname;}
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;}
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 95 | 4 | *{$fullaccname} = $accessor; | |||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||
| 97 | 4 | ▶ | if ($wa and not defined &{$fullmutname}) { # guess, we need warning here, that mutator exists | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$wa and not defined &{$fullmutname;}
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;}
| |||||||||||||||||||||||||||||||||
| 98 | 2 | my $mutator = $self->make_lazy_wo_accessor($field); | |||||||||||||||||||||||||||||||
| 99 | 2 | ▶ | subname($fullmutname, $mutator) if defined &subname; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 100 | 2 | *{$fullmutname} = $mutator; | |||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | 4 | ▶ | if( $lazy ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||||||
| 106 | 4 | my $init_method = "${class}::_lazy_init_$field"; | |||||||||||||||||||||||||||||||
| 107 | 4 | ▶ | unless (defined &{$init_method} ){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||