| 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::FallbackSlot; | ||||||||||
| 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_slot => ( | |||||||||
| 19 | is => 'ro', | ||||||||||
| 20 | isa => Str, | ||||||||||
| 21 | required => 1, | ||||||||||
| 22 | init_arg => 'fallback', | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | override fallback => sub | ||||||||||
| 26 | 3 | ▶ | { | ||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=20.5
| |||||||||||
| 27 | 3 | my $self = shift; | |||||||||
| 28 | 3 | my ($operation, $key, $value) = @_; | |||||||||
| 29 | 3 | my $slot = $self->_fallback_slot; | |||||||||
| 30 | |||||||||||
| 31 | 3 | ▶ | $hashish->check($self->object->$slot) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | or croak "Value of tied object's '$slot' attribute is not hashref-like"; | ||||||||||
| 33 | |||||||||||
| 34 | 2 | for ($operation) | |||||||||
| 35 | { | ||||||||||
| 36 | 0 | ▶ | if ($_ eq "FETCH") { return $self->object->$slot->{$key} } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 2 | ▶ | if ($_ eq "STORE") { return $self->object->$slot->{$key} = $value } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | ▶ | if ($_ eq "EXISTS") { return exists $self->object->$slot->{$key} } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 1 | ▶ | if ($_ eq "DELETE") { return delete $self->object->$slot->{$key} } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | |||||||||||
| 41 | 0 | confess "This should never happen!"; | |||||||||
| 42 | } | ||||||||||
| 43 | 2 | }; | |||||||||
| 44 | |||||||||||
| 45 | 2 | 1; | |||||||||
| 46 | |||||||||||
| 47 | __END__ | ||||||||||