Moose/FallbackSlot.pm

filter: Statementstmt 93.0% 40 / 43 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 90.3% 56 / 62 CC 7 SCAR 14.2
CC
7
Cov
89%
__ANON__
7.8
BEGIN
1.0
BEGIN
1.0
CRAP 4.2
« Moose.pm ↑ Summary Moose/Forgiving.pm »
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
BranchTrueFalseTotal
$hashish->check($self->object->$slot) or croak("Value of tied object's '${slot}' attribute is not hashref-like") 2 1 3
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
BranchTrueFalseTotal
if ($_ eq "FETCH") 0 2 2
37 2 ▶ if ($_ eq "STORE") { return $self->object->$slot->{$key} = $value }
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "STORE") 1 1 2
38 0 ▶ if ($_ eq "EXISTS") { return exists $self->object->$slot->{$key} }
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "EXISTS") 0 1 1
39 1 ▶ if ($_ eq "DELETE") { return delete $self->object->$slot->{$key} }
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "DELETE") 1 0 1
40
41 0 confess "This should never happen!";
42 }
43 2 };
44  
45 2 1;
46  
47 __END__
« Moose.pm ↑ Summary Moose/Forgiving.pm »