| 1 | package Hash::Lazy::Tie; | ||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | BEGIN { | ||||||||||
| 6 | 6 | ▶ | require Tie::Hash; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 6 | our @ISA = qw(Tie::ExtraHash); | |||||||||
| 8 | } | ||||||||||
| 9 | |||||||||||
| 10 | 6 | ▶ | use Carp qw(confess); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 6 | ▶ | use self; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 6 | ▶ | use constant USAGE => 'my %h; tie %h, "Hash::Lazy::Tie", $builder, \%h;'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 6 | ▶ | use constant STORAGE => 0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 6 | ▶ | use constant BUILDER => 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 6 | ▶ | use constant TIED => 2; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | 5 | ▶ | sub TIEHASH { | ||||||||
|
Subroutine
TIEHASH: called CC=2 SCAR=7.0
| |||||||||||
| 20 | 5 | my ($builder, $tied) = @args; | |||||||||
| 21 | |||||||||||
| 22 | 5 | ▶ | confess "The use of Hash::Lazy::Tie requires passing the hash variable that it's tying to. Usage: " . USAGE | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | unless defined($tied); | ||||||||||
| 24 | |||||||||||
| 25 | 5 | return bless [{}, $builder, $tied], $self; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 93 | ▶ | sub FETCH { | ||||||||
|
Subroutine
FETCH: called CC=3 SCAR=11.0
| |||||||||||
| 29 | 93 | my ($key) = @args; | |||||||||
| 30 | |||||||||||
| 31 | 93 | ▶ | return $self->[STORAGE]{$key} if exists $self->[STORAGE]{$key}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | |||||||||||
| 33 | 37 | my $ret = $self->[BUILDER]->($self->[TIED], $key); | |||||||||
| 34 | 37 | ▶ | $self->[STORAGE]{$key} = $ret unless exists $self->[STORAGE]{$key}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 37 | return $self->[STORAGE]{$key}; | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | 6 | 1; | |||||||||