DWH_File/Tie/Hash.pm

filter: Statementstmt 89.9% 98 / 109 Branchbran 66.6% 24 / 36 Conditioncond 68.4% 13 / 19 MC/DCmcdc 33.3% 4 / 12 Subroutinesub 100% 20 / 20 Podpod 0.0% 0 / 9 totaltotal 77.5% 159 / 205 CC 26 SCAR 15.2
CC
26
Cov
82%
DELETE
9.4
tie_reference
8.2
wake_up_call
6.0
CRAP 4.6
« DWH_File/Tie/Array.pm ↑ Summary DWH_File/Kernel.pm »
1 package DWH_File::Tie::Hash;
2  
3 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use vars qw( @ISA $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use DWH_File::Subscript::Wired;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use DWH_File::Tie::Subscripted;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use DWH_File::Tie::Hash::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 9 @ISA = qw( DWH_File::Tie::Subscripted );
12 9 $VERSION = 0.01;
13  
14 30 ▶sub TIEHASH {
Subroutine TIEHASH: called CC=1 SCAR=0.0
15 30 my $this = shift;
16 30 my $self = $this->perform_tie( @_ );
17 #$self->{ cache } = DWH_File::Cache->new;
18 }
19  
20 2 ▶sub DELETE {
Subroutine DELETE: called CC=7 SCAR=22.4
21 2 my ( $self, $key ) = @_;
22 2 my $subscript = $self->get_subscript( $key );
23 2 ▶ my $node = $self->get_node( $subscript ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $node = $self->get_node($subscript) or return undef 2 0 2
24 2 my ( $p_node, $s_node, $p_sub, $s_sub );
25 2 ▶ if ( defined $node->{ pred } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node->{"pred"}) 2 0 2
26 2 $p_sub = $self->subscript_from_value_object( $node->{ pred } );
27 2 $p_node = $self->get_node( $p_sub );
28 }
29 2 ▶ if ( defined $node->{ succ } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node->{"succ"}) 2 0 2
30 2 $s_sub = $self->subscript_from_value_object( $node->{ succ } );
31 2 $s_node = $self->get_node( $s_sub );
32 }
33 2 my $value = $node->{ value };
34 2 $node->release;
35 2 $subscript->release;
36 2 $self->{ kernel }->delete( $subscript );
37 2 ▶ if ( not $p_node ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $p_node) { } 0 2 2
38 0 ▶ if ( not $s_node ) { $self->{ first } = undef } # first, last, only
Branch: 1 branch
BranchTrueFalseTotal
if (not $s_node) { } 0 0 0
39 else {
40 # first
41 0 $self->{ first } = $s_sub->{ value };
42 0 $s_node->{ pred } = undef;
43 0 $self->{ kernel }->store( $s_sub, $s_node );
44 }
45 # make lazy
46 0 $self->{ kernel }->save_custom_grounding( $self );
47 }
48 else {
49 2 ▶ if ( not $s_node ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $s_node) { } 0 2 2
50 # last
51 0 $p_node->{ succ } = undef;
52 0 $self->{ kernel }->store( $p_sub, $p_node );
53 }
54 else {
55 # general (mid)
56 2 $p_node->{ succ } = $s_sub->{ value };
57 2 $self->{ kernel }->store( $p_sub, $p_node );
58 2 $s_node->{ pred } = $p_sub->{ value };
59 2 $self->{ kernel }->store( $s_sub, $s_node );
60 }
61 }
62 2 return $value->actual_value;
63 }
64  
65 2 ▶sub CLEAR {
Subroutine CLEAR: called CC=3 SCAR=11.0
66 2 my ( $self ) = @_;
67 2 my $k = $self->{ first };
68 2 ▶ while ( defined $k and defined $k->actual_value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $k and defined $k->actual_value) 4 2 6
Condition66%2/3
defined $k and defined $k->actual_value
!ll&&!rl&&r
204
MC/DC50%1/2
defined $k and defined $k->actual_value
defined $k defined $k->actual_value
Truth table66%2/3
A and B
A= defined $kB= defined $k->actual_value
ABresult
0X0
100
111
69 4 my $sub = $self->subscript_from_value_object( $k );
70 4 my $node = $self->get_node( $sub );
71 4 $k = $node->{ succ };
72 4 $node->release;
73 4 $sub->release;
74 4 $self->{ kernel }->delete( $sub );
75 }
76 2 $self->{ first } = undef;
77 2 $self->{ kernel }->save_custom_grounding( $self );
78 }
79  
80 62 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: called CC=2 SCAR=6.9
81 62 ▶ defined $_[ 0 ]->{ first } ? $_[ 0 ]->{ first }->actual_value : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{'first'} ? : 49 13 62
82 }
83  
84 108 ▶sub NEXTKEY {
Subroutine NEXTKEY: called CC=3 SCAR=11.1
85 108 my $subscript = $_[ 0 ]->get_subscript( $_[ 1 ] );
86 108 ▶ my $node = $_[ 0 ]->get_node( $subscript ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $node = $_[0]->get_node($subscript) or return undef 108 0 108
87 108 ▶ return defined $node->{ succ } ? $node->{ succ }->actual_value : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $node->{'succ'} ? : 96 12 108
88 }
89  
90 30 ▶sub tie_reference {
Subroutine tie_reference: called CC=8 SCAR=21.1
Pod undocumented
91 30 ▶ $_[ 2 ] ||= {};
Condition100%2/2
$_[2] ||= {}
l!l
1317
MC/DC100%1/1
$_[2] ||= {}
$_[2]
Truth table100%2/2
A
A= $_[2]
Aresult
11
00
92 30 my ( $this, $kernel, $ref, $blessing, $id, $tail, $tie_class ) = @_;
93 30 ▶ my $class = ref $this || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0300
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
94 30 ▶ $tie_class ||= '';
Condition100%2/2
$tie_class ||= ""
l!l
1317
MC/DC100%1/1
$tie_class ||= ""
$tie_class
Truth table100%2/2
A
A= $tie_class
Aresult
11
00
95 30 ▶ $blessing ||= ref $ref;
Condition66%2/3
$blessing ||= ref $ref
l!l&&r!l&&!r
17130
MC/DC0%0/2
$blessing ||= ref $ref
$blessing ref $ref
Truth table66%2/3
A ||= B
A= $blessingB= ref $ref
ABresult
1X1
011
000
96 30 ▶ my $instance = tie %$ref, $tie_class || $class, $kernel, $ref, $id, $tail;
Condition66%2/3
$tie_class || $class
l!l&&r!l&&!r
13170
MC/DC0%0/2
$tie_class || $class
$tie_class $class
Truth table66%2/3
A || B
A= $tie_classB= $class
ABresult
1X1
011
000
97 30 ▶ if ( $blessing ne 'HASH' ) { bless $ref, $blessing }
Branch: 1 branch
BranchTrueFalseTotal
if ($blessing ne "HASH") 4 26 30
98 30 ▶ $tie_class and bless $instance, $class;
Branch: 1 branch
BranchTrueFalseTotal
$tie_class and bless $instance, $class 13 17 30
99 30 return $instance;
100 }
101  
102 17 ▶sub wake_up_call {
Subroutine wake_up_call: called CC=4 SCAR=17.9
Pod undocumented
103 17 my ( $self, $tail ) = @_;
104 0 ▶ unless ( defined $tail ) { die "Tail anomaly" }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tail) 0 17 17
105 17 my ( $signal, $first ) = unpack "a a*", $tail;
106 17 ▶ if ( $signal eq '>' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($signal eq '>') { } 17 0 17
elsif ($signal eq '<') { } 0 0 0
107 $self->{ first } = DWH_File::Value::Factory->
108 17 from_stored( $self->{ kernel }, $first );
109 }
110 0 elsif ( $signal eq '<' ) { $self->{ first } = undef }
111 0 else { die "Unknown signal byte: '$signal'" }
112 }
113  
114 13 ▶sub sign_in_first_time {
Subroutine sign_in_first_time: called CC=2 SCAR=6.9
Pod undocumented
115 13 my ( $self ) = @_;
116 13 ▶ while ( my ( $k, $v ) = each %{ $self->{ content } } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"content"};}) 33 13 46
117 33 $self->STORE( $k, $v );
118 }
119 }
120  
121 563 ▶sub node_class { 'DWH_File::Tie::Hash::Node' }
Subroutine node_class: called CC=1 SCAR=0.0
Pod undocumented
122  
123 50 ▶sub handle_new_node {
Subroutine handle_new_node: called CC=1 SCAR=0.0
Pod undocumented
124 50 my ( $self, $node, $subscript ) = @_;
125 50 $node->set_successor( $self->{ first } );
126 50 $self->set_first_key( $subscript->{ value } );
127 50 $subscript->retain;
128 }
129  
130 558 ▶sub get_subscript {
Subroutine get_subscript: called CC=1 SCAR=0.0
Pod undocumented
131 558 return DWH_File::Subscript::Wired->from_input( @_[ 0, 1 ] );
132 }
133  
134 8 ▶sub subscript_from_value_object {
Subroutine subscript_from_value_object: called CC=1 SCAR=0.0
Pod undocumented
135 8 return DWH_File::Subscript::Wired->new( @_[ 0, 1 ] );
136 }
137  
138 50 ▶sub set_first_key {
Subroutine set_first_key: called CC=2 SCAR=6.9
Pod undocumented
139 50 my ( $self, $new_first ) = @_;
140 50 my $first = $self->FIRSTKEY;
141 50 ▶ if ( defined $first ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $first) 37 13 50
142 37 my $subscript = $self->get_subscript( $first );
143 37 my $node = $self->get_node( $subscript );
144 37 $node->set_predecessor( $new_first );
145 # make lazy
146 37 $self->{ kernel }->store( $subscript, $node );
147 }
148 50 $self->{ first } = $new_first;
149 # make lazy
150 50 $self->{ kernel }->save_custom_grounding( $self );
151 }
152  
153 32 ▶sub custom_grounding {
Subroutine custom_grounding: called CC=3 SCAR=11.0
Pod undocumented
154 32 my $k = $_[ 0 ]->{ first };
155 32 ▶ if ( defined $k and defined $k->actual_value ) { return ">$k" }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $k and defined $k->actual_value) { } 25 7 32
Condition66%2/3
defined $k and defined $k->actual_value
!ll&&!rl&&r
7025
MC/DC50%1/2
defined $k and defined $k->actual_value
defined $k defined $k->actual_value
Truth table66%2/3
A and B
A= defined $kB= defined $k->actual_value
ABresult
0X0
100
111
156 7 else { return '<' }
157 }
158  
159 9 1;
160  
161 __END__
« DWH_File/Tie/Array.pm ↑ Summary DWH_File/Kernel.pm »