| 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
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 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
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 103 | 2 | return $self->{$field} = $_[0]; | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | 1 | }; | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 1 | 1; | |||||||||||||||||||