| 1 | package Data::AsObject::Hash; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 7 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | $Data::AsObject::Hash::VERSION = '0.07'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Base class for Data::AsObject hashrefs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use Data::AsObject (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use namespace::clean -except => [qw/AUTOLOAD/]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 7 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | sub can { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | ▶ | if(@_ != 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | local $AUTOLOAD = ref($_[0]) .'::can'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | return $_[0]->AUTOLOAD(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 5 | my($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 5 | ▶ | return unless( exists $self->{$key} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | return sub { __get_data($self, $key) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 29 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=10 SCAR=33.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 29 | my $index = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 29 | my $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 29 | my $key = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 29 | $key =~ s/.*:://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 29 | undef $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 29 | ▶ | if ($key eq "can" && defined $index && $index != /\d+/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$key eq "can" and defined $index and $index != /\d+/
$key eq "can" and defined $index
MC/DC0%0/3
$key eq "can" and defined $index and $index != /\d+/
$key eq "can"
defined $index
$index != /\d+/
Truth table25%1/4
A and B and C
A= $key eq "can"B= defined $indexC= $index != /\d+/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 29 | ▶ | if ($key eq "isa" && defined $index && $index != /\d+/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$key eq "isa" and defined $index and $index != /\d+/
$key eq "isa" and defined $index
MC/DC0%0/3
$key eq "isa" and defined $index and $index != /\d+/
$key eq "isa"
defined $index
$index != /\d+/
Truth table25%1/4
A and B and C
A= $key eq "isa"B= defined $indexC= $index != /\d+/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | $index eq ref($self) or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$index eq ref $self or $index eq "Data::AsObject::Hash"
MC/DC0%0/2
$index eq ref $self or $index eq "Data::AsObject::Hash"
$index eq ref $self
$index eq "Data::AsObject::Hash"
Truth table0%0/3
A or B
A= $index eq ref $selfB= $index eq "Data::AsObject::Hash"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | $index eq "Data::AsObject::Hash" or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | $index eq "UNIVERSAL" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ? return 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | : return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 29 | return __get_data($self, $key, $index); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 31 | ▶ | sub __get_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__get_data: called CC=13 SCAR=25.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 31 | my ($self, $key, $index) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 31 | ▶ | my $data = exists $self->{$key} ? $self->{$key} : __guess_data($self, $key); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 31 | ▶ | my $mode = ref($self) =~ /^.*::(\w+)$/ ? $1 : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 31 | ▶ | if ( !$data ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 14 | ▶ | return if $key eq "DESTROY"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | my $msg = "Attempting to access non-existing hash key $key!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | ▶ | carp $msg if $mode eq 'Loose'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 4 | ▶ | croak $msg if $mode eq 'Strict'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 17 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
defined $index and $index =~ /\d+/ and &$Data::AsObject::__check_type($data) eq "ARRAY" and exists $data->[$index]
defined $index and $index =~ /\d+/ and &$Data::AsObject::__check_type($data) eq "ARRAY"
defined $index and $index =~ /\d+/
MC/DC25%1/4
defined $index and $index =~ /\d+/ and &$Data::AsObject::__check_type($data) eq "ARRAY" and exists $data->[$index]
defined $index
$index =~ /\d+/
&$Data::AsObject::__check_type($data) eq "ARRAY"
exists $data->[$index]
Truth table40%2/5
A and B and C and D
A= defined $indexB= $index =~ /\d+/C= &$Data::AsObject::__check_type($data) eq "ARRAY"D= exists $data->[$index]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | defined $index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | && $index =~ /\d+/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | && $Data::AsObject::__check_type->($data) eq "ARRAY" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | && exists $data->[$index] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 5 | $data = $data->[$index]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 17 | ▶ | if ( $Data::AsObject::__check_type->($data) eq "ARRAY" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 4 | bless $data, "Data::AsObject::Array::$mode"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } elsif ( $Data::AsObject::__check_type->($data) eq "HASH" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | bless $data, "Data::AsObject::Hash::$mode"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 17 | return $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 16 | ▶ | sub __guess_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__guess_data: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 16 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 16 | my $key_regex = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 16 | my $has_colon_or_dash = $key_regex =~ s/_/[-:]/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 16 | ▶ | my @matches = grep(/$key_regex/, keys %$self) if $has_colon_or_dash; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 16 | ▶ | if ( @matches == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | return $self->{$matches[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } elsif ( @matches > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | carp "Attempt to disambiguate hash key $key_regex returns multiple matches!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | return $self->{$matches[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 14 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | package Data::AsObject::Hash::Strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 7 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 7 | $Data::AsObject::Hash::Strict::VERSION = '0.07'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 7 | ▶ | use base 'Data::AsObject::Hash'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | package Data::AsObject::Hash::Loose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 7 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 7 | $Data::AsObject::Hash::Loose::VERSION = '0.07'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 7 | ▶ | use base 'Data::AsObject::Hash'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | package Data::AsObject::Hash::Silent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 7 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 7 | $Data::AsObject::Hash::Silent::VERSION = '0.07'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 7 | ▶ | use base 'Data::AsObject::Hash'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||