| 1 | 2 | ▶ | use 5.008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | package Tie::Moose::FallbackHash; | ||||||||||
| 6 | |||||||||||
| 7 | 2 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||
| 8 | 2 | our $VERSION = '0.003'; | |||||||||
| 9 | |||||||||||
| 10 | 2 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 2 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 2 | ▶ | use Types::Standard -types; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 2 | ▶ | use Types::TypeTiny qw(HashLike); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 2 | my $hashish = Ref['HASH'] | HashLike; | |||||||||
| 17 | |||||||||||
| 18 | 2 | has _fallback_hash => ( | |||||||||
| 19 | is => 'ro', | ||||||||||
| 20 | isa => $hashish, | ||||||||||
| 21 | required => 1, | ||||||||||
| 22 | init_arg => 'fallback', | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | override fallback => sub | ||||||||||
| 26 | 2 | ▶ | { | ||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=19.2
| |||||||||||
| 27 | 2 | my $self = shift; | |||||||||
| 28 | 2 | my ($operation, $key, $value) = @_; | |||||||||
| 29 | 2 | my $hash = $self->_fallback_hash; | |||||||||
| 30 | |||||||||||
| 31 | 2 | for ($operation) | |||||||||
| 32 | { | ||||||||||
| 33 | 0 | ▶ | if ($_ eq "FETCH") { return $hash->{$key} } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 2 | ▶ | if ($_ eq "STORE") { return $hash->{$key} = $value } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 0 | ▶ | if ($_ eq "EXISTS") { return exists $hash->{$key} } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 1 | ▶ | if ($_ eq "DELETE") { return delete $hash->{$key} } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | |||||||||||
| 38 | 0 | confess "This should never happen!"; | |||||||||
| 39 | } | ||||||||||
| 40 | 2 | }; | |||||||||
| 41 | |||||||||||
| 42 | 2 | 1; | |||||||||
| 43 | |||||||||||
| 44 | __END__ | ||||||||||