Moose/FallbackHash.pm

filter: Statementstmt 92.8% 39 / 42 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 89.8% 53 / 59 CC 6 SCAR 12.5
CC
6
Cov
88%
__ANON__
6.8
BEGIN
1.0
BEGIN
1.0
CRAP 3.5
« Moose/Forgiving.pm ↑ Summary Moose/ReadOnly.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::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
BranchTrueFalseTotal
if ($_ eq "FETCH") 0 2 2
34 2 ▶ if ($_ eq "STORE") { return $hash->{$key} = $value }
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "STORE") 1 1 2
35 0 ▶ if ($_ eq "EXISTS") { return exists $hash->{$key} }
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "EXISTS") 0 1 1
36 1 ▶ if ($_ eq "DELETE") { return delete $hash->{$key} }
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "DELETE") 1 0 1
37
38 0 confess "This should never happen!";
39 }
40 2 };
41  
42 2 1;
43  
44 __END__
« Moose/Forgiving.pm ↑ Summary Moose/ReadOnly.pm »