| 1 | package Class::Property::RW::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 parent 'Class::Property::RW'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | sub TIESCALAR | ||||||||||
| 6 | 3 | ▶ | { | ||||||||
|
Subroutine
TIESCALAR: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | my( $class, $field, $init, $flag_ref ) = @_; | |||||||||
| 8 | 3 | return bless { | |||||||||
| 9 | 'field' => $field | ||||||||||
| 10 | , 'init' => $init | ||||||||||
| 11 | , 'flag_ref' => $flag_ref | ||||||||||
| 12 | }, $class; | ||||||||||
| 13 | } | ||||||||||
| 14 | |||||||||||
| 15 | sub STORE | ||||||||||
| 16 | 2 | ▶ | { | ||||||||
|
Subroutine
STORE: called CC=2 SCAR=7.0
| |||||||||||
| 17 | 2 | my( $self, $value ) = @_; | |||||||||
| 18 | 2 | $self->{'object'}->{$self->{'field'}} = $value; | |||||||||
| 19 | 2 | ▶ | if( not defined $self->{'flag_ref'}->{$self->{'object'}} ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | { | ||||||||||
| 21 | 2 | $self->{'flag_ref'}->{$self->{'object'}} = $self->{'object'}; | |||||||||
| 22 | 2 | Scalar::Util::weaken($self->{'flag_ref'}->{$self->{'object'}}); | |||||||||
| 23 | } | ||||||||||
| 24 | 2 | return; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | sub FETCH | ||||||||||
| 28 | 4 | ▶ | { | ||||||||
|
Subroutine
FETCH: called CC=4 SCAR=14.6
| |||||||||||
| 29 | 4 | my( $self ) = @_; | |||||||||
| 30 | |||||||||||
| 31 | 4 | eval{ | |||||||||
| 32 | 4 | ▶ | if( not defined $self->{'flag_ref'}->{$self->{'object'}} ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | { | ||||||||||
| 34 | 4 | $self->{'flag_ref'}->{$self->{'object'}} = $self->{'object'}; | |||||||||
| 35 | 4 | Scalar::Util::weaken($self->{'flag_ref'}->{$self->{'object'}}); | |||||||||
| 36 | 4 | $self->{'object'}->{$self->{'field'}} = $self->{'init'}->($self->{'object'}); | |||||||||
| 37 | } | ||||||||||
| 38 | }; | ||||||||||
| 39 | 4 | ▶ | if( $@ ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | { | ||||||||||
| 41 | 1 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 42 | 1 | ▶ | use Carp qw(confess); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 43 | 0 | print Dumper($self); | |||||||||
| 44 | 0 | ▶ | confess $@ if $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 4 | return $self->{'object'}->{$self->{'field'}}; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 1 | 1; | |||||||||