lib/Module/Generic/TieHash.pm

filter: Statementstmt 65.5% 120 / 183 Branchbran 61.6% 37 / 60 Conditioncond 50.0% 26 / 52 MC/DCmcdc 30.3% 10 / 33 Subroutinesub 72.0% 18 / 25 Podpod 14.2% 1 / 7 totaltotal 58.8% 212 / 360 CC 53 SCAR 24.0
CC
53
Cov
62%
__message
56.0
SCALAR
12.0
THAW
12.0
CRAP 11.0
« lib/Module/Generic/Number.pm ↑ Summary lib/Module/Generic/Null.pm »
1 ##----------------------------------------------------------------------------
2 ## Module Generic - ~/lib/Module/Generic/TieHash.pm
3 ## Version v1.2.3
4 ## Copyright(c) 2023 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/03/20
7 ## Modified 2026/01/22
8 ## All rights reserved
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package Module::Generic::TieHash;
14 BEGIN
15 9 ▶{
Subroutine BEGIN: called CC=3 SCAR=12.7
16 9 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 9 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 9 warnings::register_categories( 'Module::Generic' );
19 9 ▶ use vars qw( $VERSION $PAUSED $MOD_PERL );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 9 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 # When true _exclude returns always false.
22 # This is used by Module::Generic::__message, because Module::Generic is always part of
23 # the exclusion list
24 9 our $PAUSED = 0;
25 9 our $VERSION = 'v1.2.3';
26 9 ▶ if( exists( $ENV{MOD_PERL} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"MOD_PERL"} and $Module::Generic::TieHash::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]) 0 9 9
Condition33%1/3
exists $ENV{"MOD_PERL"} and $Module::Generic::TieHash::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
!ll&&!rl&&r
900
MC/DC0%0/2
exists $ENV{"MOD_PERL"} and $Module::Generic::TieHash::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
exists $ENV{"MOD_PERL"} $Module::Generic::TieHash::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
Truth table33%1/3
A and B
A= exists $ENV{"MOD_PERL"}B= $Module::Generic::TieHash::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
ABresult
0X0
100
111
27 &&
28 ( $MOD_PERL = $ENV{MOD_PERL} =~ /^mod_perl\/(\d+\.[\d\.]+)/ ) )
29 {
30 0 select( ( select( STDOUT ), $| = 1 )[ 0 ] );
31 0 require Apache2::Log;
32 0 require Apache2::Module;
33 0 require Apache2::ServerUtil;
34 0 require Apache2::RequestUtil;
35 0 require Apache2::ServerRec;
36 0 require ModPerl::Util;
37 0 require Apache2::Const;
38 0 Apache2::Const->import( compile => qw( :log OK ) );
39 }
40 };
41  
42 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 9 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
44 9 my $mark = '__tiehash__';
45  
46 sub TIEHASH
47 42 ▶{
Subroutine TIEHASH: called CC=9 SCAR=24.8
48 42 my $this = shift( @_ );
49 42 my $opts = {};
50 42 ▶ $opts = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 39 3 42
51 42 ▶ if( ( Scalar::Util::reftype( $opts ) // '' ) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if ((builtin::reftype($opts) // "") ne "HASH") 0 42 42
Condition50%1/2
builtin::reftype($opts) // ""
l!l
420
MC/DC0%0/1
builtin::reftype($opts) // ""
builtin::reftype($opts)
Truth table50%1/2
A
A= builtin::reftype($opts)
Aresult
11
00
52 {
53 0 ▶ warn( "Parameters provided ($opts) is not an hash reference.\n" ) if( warnings::enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("Module::Generic") 0 0 0
54 0 return;
55 }
56 42 my $disable = [];
57 42 ▶ $disable = $opts->{disable} if( ( Scalar::Util::reftype( $opts->{disable} ) // '' ) eq 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($opts->{"disable"}) // "") eq "ARRAY" 0 42 42
Condition50%1/2
builtin::reftype($opts->{"disable"}) // ""
l!l
042
MC/DC0%0/1
builtin::reftype($opts->{"disable"}) // ""
builtin::reftype($opts->{"disable"})
Truth table50%1/2
A
A= builtin::reftype($opts->{"disable"})
Aresult
11
00
58 42 my $list = {};
59 42 @$list{ @$disable } = (1) x scalar( @$disable );
60 my $hash =
61 {
62 # The caller sets this to its class, so we can differentiate calls from inside and outside our caller's package
63 disable => $list,
64 debug => $opts->{debug},
65 # When disabled, the Tie::Hash system will return hash key values directly under $self instead of $self->{data}
66 # Disabled by default so the new() method can access its setup data directly under $self
67 # Then new() can call enable to active it
68 enable => 1,
69 # Do we enable the use of object as hash key?
70 42 ▶ key_object => $opts->{key_object} // 0,
Condition100%2/2
$opts->{"key_object"} // 0
l!l
393
MC/DC100%1/1
$opts->{"key_object"} // 0
$opts->{"key_object"}
Truth table100%2/2
A
A= $opts->{"key_object"}
Aresult
11
00
71 # Where to store the actual hash data
72 data => {},
73 # object reference address -> value
74 # This is used to store object as key
75 object_repo => {},
76 };
77 42 ▶ my $self = bless( $hash => ( ref( $this ) || $this ) );
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0420
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
78 # $self->__message( 1, "Debug value is '", ( $opts->{debug} // 0 ), "'" );
79 42 return( $self );
80 }
81  
82 sub CLEAR
83 0 ▶{
Subroutine CLEAR: not called CC=1 SCAR=6.9
84 0 my $self = shift( @_ );
85 0 my $data = $self->{data};
86 0 my $repo = $self->{object_repo};
87 0 %$repo = ();
88 0 %$data = ();
89 }
90  
91 sub DELETE
92 1 ▶{
Subroutine DELETE: called CC=5 SCAR=18.9
93 1 my $self = shift( @_ );
94 1 my $data = $self->{data};
95 1 my $repo = $self->{object_repo};
96 1 my $key = shift( @_ );
97 1 my $caller = caller;
98 1 ▶ if( $self->_exclude( $caller ) || !$self->{enable} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_exclude($caller) or not $self->{'enable'}) { } 0 1 1
Condition33%1/3
$self->_exclude($caller) or not $self->{"enable"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->_exclude($caller) or not $self->{"enable"}
$self->_exclude($caller) not $self->{"enable"}
Truth table33%1/3
A or not(B)
A= $self->_exclude($caller)B= not $self->{"enable"}
ABresult
1X1
011
000
99 {
100 0 CORE::delete( $self->{ $key } );
101 }
102 else
103 {
104 1 ▶ if( ref( $key ) && $self->{key_object} )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $key and $self->{'key_object'}) { } 0 1 1
Condition33%1/3
ref $key and $self->{"key_object"}
!ll&&!rl&&r
100
MC/DC0%0/2
ref $key and $self->{"key_object"}
ref $key $self->{"key_object"}
Truth table33%1/3
A and B
A= ref $keyB= $self->{"key_object"}
ABresult
0X0
100
111
105 {
106 0 CORE::delete( $repo->{ Scalar::Util::refaddr( $key ) } );
107 }
108 else
109 {
110 1 CORE::delete( $data->{ $key } );
111 }
112 }
113 }
114  
115 sub EXISTS
116 109 ▶{
Subroutine EXISTS: called CC=5 SCAR=16.1
117 109 my $self = shift( @_ );
118 109 my $data = $self->{data};
119 109 my $repo = $self->{object_repo};
120 109 my $key = shift( @_ );
121 109 my $caller = caller;
122 109 ▶ if( $self->_exclude( $caller ) || !$self->{enable} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_exclude($caller) or not $self->{'enable'}) { } 76 33 109
Condition66%2/3
$self->_exclude($caller) or not $self->{"enable"}
l!l&&r!l&&!r
07633
MC/DC50%1/2
$self->_exclude($caller) or not $self->{"enable"}
$self->_exclude($caller) not $self->{"enable"}
Truth table66%2/3
A or not(B)
A= $self->_exclude($caller)B= not $self->{"enable"}
ABresult
1X1
011
000
123 {
124 76 CORE::exists( $self->{ $key } );
125 }
126 else
127 {
128 33 ▶ if( ref( $key ) && $self->{key_object} )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $key and $self->{'key_object'}) { } 6 27 33
Condition100%3/3
ref $key and $self->{"key_object"}
!ll&&!rl&&r
2616
MC/DC100%2/2
ref $key and $self->{"key_object"}
ref $key $self->{"key_object"}
Truth table100%3/3
A and B
A= ref $keyB= $self->{"key_object"}
ABresult
0X0
100
111
129 {
130 6 CORE::exists( $repo->{ Scalar::Util::refaddr( $key ) } );
131 }
132 else
133 {
134 27 CORE::exists( $data->{ $key } );
135 }
136 }
137 }
138  
139 sub FETCH
140 548 ▶{
Subroutine FETCH: called CC=9 SCAR=22.2
141 548 my $self = shift( @_ );
142 548 my $data = $self->{data};
143 548 my $repo = $self->{object_repo};
144 548 my $key = shift( @_ );
145 548 my $caller = caller;
146 # $self->__message( 0, "FETCH($caller)[owner calling, enable=$self->{enable}] for key '${key}' is caller ${caller} excluded ? ", ( $self->_exclude( $caller ) ? 'yes' : 'no' ), " and is object enabled ? ", ( $self->{enable} ? 'yes' : 'no' ) );
147 # require Devel::StackTrace;
148 # my $trace = Devel::StackTrace->new;
149 # $self->__message( 4, "Is caller '$caller' excluded ? ", ( $self->_exclude( $caller ) ? 'yes' : 'no' ), ". Trace is: $trace" );
150 548 ▶ if( $self->_exclude( $caller ) || !$self->{enable} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_exclude($caller) or not $self->{'enable'}) { } 446 102 548
Condition66%2/3
$self->_exclude($caller) or not $self->{"enable"}
l!l&&r!l&&!r
0446102
MC/DC50%1/2
$self->_exclude($caller) or not $self->{"enable"}
$self->_exclude($caller) not $self->{"enable"}
Truth table66%2/3
A or not(B)
A= $self->_exclude($caller)B= not $self->{"enable"}
ABresult
1X1
011
000
151 {
152 # $self->__message( 4, "FETCH($caller)[owner calling, enable=$self->{enable}] <- '$key' <- '$self->{$key}'" );
153 446 ▶ return( wantarray ? () : undef ) if( !CORE::exists( $self->{ $key } ) );
Branch: 2 branches
BranchTrueFalseTotal
unless exists $self->{$key} 381 65 446
wantarray ? : 0 381 381
154 65 return( $self->{ $key } )
155 }
156 else
157 {
158 102 ▶ if( ref( $key ) && $self->{key_object} )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $key and $self->{'key_object'}) { } 6 96 102
Condition66%2/3
ref $key and $self->{"key_object"}
!ll&&!rl&&r
9606
MC/DC50%1/2
ref $key and $self->{"key_object"}
ref $key $self->{"key_object"}
Truth table66%2/3
A and B
A= ref $keyB= $self->{"key_object"}
ABresult
0X0
100
111
159 {
160 # $self->__message( 4, "fetching reference key '", overload::StrVal( $key ), "'" );
161 6 return( $repo->{ Scalar::Util::refaddr( $key ) }->[1] );
162 }
163 else
164 {
165 # $self->__message( 4, "fetching non-reference key '$key'" );
166 # $self->__message( 4, "Value '", ( $data->{ $key } // 'undef' ), "' looks like a number? ", ( Scalar::Util::looks_like_number( $data->{ $key } ) ? 'yes' : 'no' ) );
167 96 ▶ return( wantarray ? () : undef ) if( !CORE::exists( $data->{ $key } ) );
Branch: 2 branches
BranchTrueFalseTotal
unless exists $data->{$key} 2 94 96
wantarray ? : 0 2 2
168 94 return( $data->{ $key } );
169 }
170 }
171 }
172  
173 sub FIRSTKEY
174 44 ▶{
Subroutine FIRSTKEY: called CC=3 SCAR=11.7
175 44 my $self = shift( @_ );
176 44 my $data = $self->{data};
177 44 my @keys = ();
178 44 my $caller = caller;
179 44 ▶ if( $self->_exclude( $caller ) || !$self->{enable} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_exclude($caller) or not $self->{'enable'}) { } 0 44 44
Condition33%1/3
$self->_exclude($caller) or not $self->{"enable"}
l!l&&r!l&&!r
0044
MC/DC0%0/2
$self->_exclude($caller) or not $self->{"enable"}
$self->_exclude($caller) not $self->{"enable"}
Truth table33%1/3
A or not(B)
A= $self->_exclude($caller)B= not $self->{"enable"}
ABresult
1X1
011
000
180 {
181 0 @keys = keys( %$self );
182 }
183 else
184 {
185 44 @keys = keys( %$data );
186 }
187 44 $self->{ITERATOR} = \@keys;
188 44 return( $self->NEXTKEY );
189 }
190  
191 sub NEXTKEY
192 190 ▶{
Subroutine NEXTKEY: called CC=4 SCAR=13.9
193 190 my $self = shift( @_ );
194 190 my $data = $self->{data};
195 190 my $repo = $self->{object_repo};
196 190 ▶ my $keys = ref( $self->{ITERATOR} ) ? $self->{ITERATOR} : [];
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'ITERATOR'} ? : 190 0 190
197 190 my $key = shift( @$keys );
198 190 ▶ return if( !defined( $key ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 44 146 190
199 # $self->__message( 4, "Returning next key '$key'." );
200 146 ▶ if( index( $key, $mark ) == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($key, $mark) == 0) 6 140 146
201 {
202 6 return( $repo->{ substr( $key, length( $mark ), -2 ) }->[0] );
203 }
204 140 return( $key );
205 }
206  
207 sub SCALAR
208 0 ▶{
Subroutine SCALAR: not called CC=3 SCAR=24.8
209 0 my $self = shift( @_ );
210 0 my $data = $self->{data};
211 0 my $caller = caller;
212 0 ▶ if( $self->_exclude( $caller ) || !$self->{enable} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_exclude($caller) or not $self->{'enable'}) { } 0 0 0
Condition0%0/3
$self->_exclude($caller) or not $self->{"enable"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_exclude($caller) or not $self->{"enable"}
$self->_exclude($caller) not $self->{"enable"}
Truth table0%0/3
A or not(B)
A= $self->_exclude($caller)B= not $self->{"enable"}
ABresult
1X1
011
000
213 {
214 0 return( scalar( keys( %$self ) ) );
215 }
216 else
217 {
218 0 return( scalar( keys( %$data ) ) );
219 }
220 }
221  
222 sub STORE
223 599 ▶{
Subroutine STORE: called CC=8 SCAR=20.8
224 599 my $self = shift( @_ );
225 599 my $data = $self->{data};
226 599 my $repo = $self->{object_repo};
227 599 my( $key, $val ) = @_;
228 599 my $caller = caller;
229 599 ▶ if( $self->_exclude( $caller ) || !$self->{enable} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_exclude($caller) or not $self->{'enable'}) { } 457 142 599
Condition66%2/3
$self->_exclude($caller) or not $self->{"enable"}
l!l&&r!l&&!r
0457142
MC/DC50%1/2
$self->_exclude($caller) or not $self->{"enable"}
$self->_exclude($caller) not $self->{"enable"}
Truth table66%2/3
A or not(B)
A= $self->_exclude($caller)B= not $self->{"enable"}
ABresult
1X1
011
000
230 {
231 # print( STDERR "STORE($caller)[owner calling] <- '$key' -> '$val'\n" );
232 # $self->__message( 4, "STORE($caller)[owner calling] <- '$key' -> '", ( my $copy = $val ), "'" );
233 457 $self->{ $key } = $val;
234 }
235 else
236 {
237 # print( STDERR "STORE($caller)[non-owner calling] <- '$key' -> '$val' called from class ", [caller]->[0], " at line ", [caller]->[2], "\n" );
238 # Ensure recursive tied hash
239 142 ▶ if( ref( $val ) eq 'HASH' &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq "HASH" and not tied %$val) 3 139 142
Condition66%2/3
ref $val eq "HASH" and not tied %$val
!ll&&!rl&&r
13903
MC/DC50%1/2
ref $val eq "HASH" and not tied %$val
ref $val eq "HASH" not tied %$val
Truth table66%2/3
A and not(B)
A= ref $val eq "HASH"B= not tied %$val
ABresult
0X0
100
111
240 !tied( %$val ) )
241 {
242 # $self->__message( 4, "Value to store is an hash reference containing ", scalar( keys( %$val ) ), " item(s) and not tied yet. Tieing it now." );
243 3 my @items = %$val;
244 3 my $this = tie( %$val, ref( $self ) );
245 3 ▶ while( @items )
Branch: 1 branch
BranchTrueFalseTotal
if (@items) 11 3 14
246 {
247 11 $this->STORE( splice( @items, 0, 2 ) );
248 }
249 }
250  
251 #print( STDERR "STORE($caller)[enable=$self->{enable}] <- '$key' -> '$val'\n" );
252 142 ▶ if( ref( $key ) && $self->{key_object} )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $key and $self->{'key_object'}) { } 6 136 142
Condition100%3/3
ref $key and $self->{"key_object"}
!ll&&!rl&&r
13516
MC/DC100%2/2
ref $key and $self->{"key_object"}
ref $key $self->{"key_object"}
Truth table100%3/3
A and B
A= ref $keyB= $self->{"key_object"}
ABresult
0X0
100
111
253 {
254 6 my $addr = Scalar::Util::refaddr( $key );
255 # $self->__message( 4, "Storing a reference key (", overload::StrVal( $key ), ") with address $addr and value '$val'" );
256 6 $repo->{ $addr } = [$key, $val];
257 6 $data->{ "${mark}${addr}__" } = $val;
258 }
259 else
260 {
261 # $self->__message( 4, "Storing a non-reference key '$key' with value '", ( my $copy = $val ), "'" );
262 136 $data->{ $key } = $val;
263 }
264 }
265 }
266  
267 sub enable
268 198 ▶{
Subroutine enable: called CC=2 SCAR=6.9
Pod undocumented
269 198 my $self = shift( @_ );
270 198 ▶ $self->{enable} = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 164 34 198
271 198 return( $self->{enable} );
272 }
273  
274 sub key_object
275 0 ▶{
Subroutine key_object: not called CC=2 SCAR=17.9
Pod documented
276 0 my $self = shift( @_ );
277 0 ▶ $self->{key_object} = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
278 0 return( $self->{key_object} );
279 }
280  
281 sub _exclude
282 1301 ▶{
Subroutine _exclude: called CC=2 SCAR=7.6
283 1301 my $self = shift( @_ );
284 1301 my $caller = shift( @_ );
285 1301 ▶ return( !$PAUSED && CORE::exists( $self->{disable}->{ $caller } ) );
Condition33%1/3
!$Module::Generic::TieHash::PAUSED && exists $self->{'disable'}{$caller}
!ll&&!rl&&r
013010
MC/DC0%0/2
!$Module::Generic::TieHash::PAUSED && exists $self->{'disable'}{$caller}
!$Module::Generic::TieHash::PAUSED exists $self->{'disable'}{$caller}
Truth table33%1/3
not(A) && B
A= !$Module::Generic::TieHash::PAUSEDB= exists $self->{'disable'}{$caller}
ABresult
0X0
100
111
286 }
287  
288 sub __message
289 0 ▶{
Subroutine __message: not called CC=7 SCAR=40.3
290 0 my $this = shift( @_ );
291 0 ▶ my $self = ( ref( $this ) ? $this : {} );
Branch: 1 branch
BranchTrueFalseTotal
ref $this ? : 0 0 0
292 0 my $level = shift( @_ );
293 0 ▶ return(1) if( $self->{debug} < $level );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} < $level 0 0 0
294 0 my( $pkg, $file, $line, @otherInfo ) = caller();
295 0 ▶ my $sub = ( caller(1) )[3] // '';
Condition0%0/2
(caller 1)[3] // ""
l!l
00
MC/DC0%0/1
(caller 1)[3] // ""
(caller 1)[3]
Truth table0%0/2
A
A= (caller 1)[3]
Aresult
11
00
296 0 my $sub2 = substr( $sub, rindex( $sub, '::' ) + 2 );
297 0 ▶ my $txt = join( '', map( ( ref( $_ ) eq 'CODE' ) ? $_->() : ( $_ // '' ), @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 0 0
Condition0%0/2
$_ // ""
l!l
00
MC/DC0%0/1
$_ // ""
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
298 0 my $prefix = '#';
299 0 $txt =~ s/\n$//gs;
300 0 my $mesg = "${prefix} " . join( "\n${prefix} ", split( /\n/, $txt ) );
301 0 ▶ if( $MOD_PERL )
Branch: 1 branch
BranchTrueFalseTotal
if ($Module::Generic::TieHash::MOD_PERL) { } 0 0 0
302 {
303 0 require Apache2::ServerUtil;
304 0 my $s = Apache2::ServerUtil->server;
305 0 $s->log->debug( $mesg );
306 }
307 else
308 {
309 0 print( STDERR $mesg, "\n" );
310 }
311 }
312  
313 sub FREEZE
314 0 ▶{
Subroutine FREEZE: not called CC=1 SCAR=6.9
Pod undocumented
315 0 my( $self, $serialiser ) = @_;
316 # $serialiser is 'JSON' for example.
317 0 return( $self->TO_JSON );
318 }
319  
320 sub STORABLE_freeze
321 2 ▶{
Subroutine STORABLE_freeze: called CC=1 SCAR=0.0
Pod undocumented
322 2 my( $self, $is_cloning ) = @_;
323 2 my $data = $self->{data};
324 2 my $repo = $self->{object_repo};
325 # Array reference of array reference, each containing the original key-object -> the corresponding value
326 2 my $objects = [values( %$repo )];
327 2 my $options = {};
328 2 @$options{qw( disable debug enable )} = @$self{qw( disable debug enable )};
329 2 return( 'module_generic_tiehash', $options, $objects, $data );
330 }
331  
332 sub STORABLE_thaw
333 2 ▶{
Subroutine STORABLE_thaw: called CC=2 SCAR=7.0
Pod undocumented
334 2 my( $self, $is_cloning, $serialized, $options, $objects, $data ) = @_;
335 2 my @keys = keys( %$options );
336 2 @$self{ @keys } = @$options{ @keys };
337 2 $self->{data} = $data;
338 2 $self->{object_repo} = {};
339 2 my $repo = $self->{object_repo};
340 2 foreach my $ref ( @$objects )
341 {
342 0 $repo->{ Scalar::Util::refaddr( $ref->[0] ) } = $ref;
343 }
344 2 return( $self );
345 }
346  
347 # Hmm, not sure this is meaningful unless we can find the original tied hash from the object
348 sub THAW
349 0 ▶{
Subroutine THAW: not called CC=3 SCAR=24.8
Pod undocumented
350 0 my( $class, $serialiser, $ref ) = @_;
351 0 my( $options, $objects, $data ) = @$ref{qw( options objects data )};
352 0 my %hash;
353 0 my $self = tie( %hash, $class, $options );
354 0 foreach my $ref ( @$objects )
355 {
356 0 $hash{ $ref->[0] } = $ref->[1];
357 }
358 0 foreach my $k ( keys( %$ref ) )
359 {
360 0 $hash{ $k } = $ref->{ $k };
361 }
362 0 return( $self );
363 }
364  
365 sub TO_JSON
366 0 ▶{
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
367 0 my $self = shift( @_ );
368 0 my $data = $self->{data};
369 0 my $repo = $self->{object_repo};
370 # my( $pack, $file, $line ) = caller;
371 # $self->__message( 4, "Called from $pack at $line" );
372 # Array reference of array reference, each containing the original key-object -> the corresponding value
373 0 my $objects = [values( %$repo )];
374 0 my $options = {};
375 0 @$options{qw( disable debug enable )} = @$self{qw( disable debug enable )};
376 0 return({ options => $options, objects => $objects, data => $data });
377 }
378  
379 9 1;
380 # NOTE: POD
381 __END__
« lib/Module/Generic/Number.pm ↑ Summary lib/Module/Generic/Null.pm »