blib/lib/Tie/Hash/Check.pm

filter: Statementstmt 100% 64 / 64 Branchbran 100% 10 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod n/a totaltotal 100% 88 / 88 CC 7 SCAR 7.9
CC
7
Cov
100%
TIEHASH
5.0
FETCH
2.0
_add_hash_value
2.0
CRAP 2.2
↑ Summary
1 package Tie::Hash::Check;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Error::Pure::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 11 our $VERSION = 0.09;
10  
11 # Error level.
12 11 $Error::Pure::Utils::LEVEL = 5;
13  
14 # Hash create.
15 17 ▶sub TIEHASH {
Subroutine TIEHASH: called CC=5 SCAR=16.1
16 17 my ($class, $hash_hr, $stack_ar) = @_;
17 17 ▶ if (ref $hash_hr ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hash_hr ne "HASH") 1 16 17
18 1 err 'Parameter isn\'t hash.';
19 }
20 16 ▶ if (! $stack_ar) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stack_ar) 11 5 16
21 11 $stack_ar = [];
22 }
23 16 ▶ if (ref $stack_ar ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $stack_ar ne "ARRAY") 1 15 16
24 1 err 'Stack isn\'t array.';
25 }
26 15 my $self = bless {}, $class;
27 15 $self->{'data'} = {};
28 15 foreach my $key (keys %{$hash_hr}) {
29 21 _add_hash_value($self->{'data'}, $key, $hash_hr->{$key},
30 $stack_ar);
31 }
32 15 $self->{'stack'} = $stack_ar;
33 15 return $self;
34 }
35  
36 # Hash clear.
37 1 ▶sub CLEAR {
Subroutine CLEAR: called CC=1 SCAR=0.0
38 1 my $self = shift;
39 1 $self->{'data'} = {};
40 1 return;
41 }
42  
43 # Hash delete.
44 2 ▶sub DELETE {
Subroutine DELETE: called CC=1 SCAR=0.0
45 2 my ($self, $key) = @_;
46 2 delete $self->{'data'}->{$key};
47 2 return;
48 }
49  
50 # Hash exists.
51 17 ▶sub EXISTS {
Subroutine EXISTS: called CC=1 SCAR=0.0
52 17 my ($self, $key) = @_;
53 17 return exists $self->{'data'}->{$key};
54 }
55  
56 # Hash fetch.
57 30 ▶sub FETCH {
Subroutine FETCH: called CC=2 SCAR=6.9
58 30 my ($self, $key) = @_;
59 30 ▶ if (! exists $self->{'data'}->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"data"}{$key}) 5 25 30
60 5 my @stack = (@{$self->{'stack'}}, $key);
61 5 err 'Key \''.join('->', @stack).'\' doesn\'t exist.';
62 }
63 25 return $self->{'data'}->{$key};
64 }
65  
66 # Hash first key.
67 20 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: called CC=1 SCAR=0.0
68 20 my $self = shift;
69  
70 # Resets each.
71 20 my $a = scalar keys %{$self->{'data'}};
72  
73 20 return each %{$self->{'data'}};
74 }
75  
76 # Hash nextkey.
77 24 ▶sub NEXTKEY {
Subroutine NEXTKEY: called CC=1 SCAR=0.0
78 24 my $self= shift;
79 24 return each %{$self->{'data'}};
80 }
81  
82 # Hash scalar.
83 1 ▶sub SCALAR {
Subroutine SCALAR: called CC=1 SCAR=0.0
84 1 my $self = shift;
85 1 return scalar %{$self->{'data'}};
86 }
87  
88 # Hash store.
89 2 ▶sub STORE {
Subroutine STORE: called CC=1 SCAR=0.0
90 2 my ($self, $key, $value) = @_;
91 2 _add_hash_value($self->{'data'}, $key, $value, $self->{'stack'});
92 2 return;
93 }
94  
95 # Add hash value to storage.
96 23 ▶sub _add_hash_value {
Subroutine _add_hash_value: called CC=2 SCAR=6.9
97 23 my ($hash_hr, $key, $value, $stack_ar) = @_;
98 23 ▶ if (ref $value eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'HASH') { } 4 19 23
99 tie my %tmp, 'Tie::Hash::Check', $value,
100 4 [@{$stack_ar}, $key];
101 4 $hash_hr->{$key} = \%tmp;
102 } else {
103 19 $hash_hr->{$key} = $value;
104 }
105 23 return;
106 }
107  
108 11 1;
109  
110 __END__
↑ Summary