| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyrights 2010-2018 by [Mark Overmeer]. |
|
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
|
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
|
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.02. |
|
5
|
|
|
|
|
|
|
# This code is part of distribution Tie::Nested. Meta-POD processed with |
|
6
|
|
|
|
|
|
|
# OODoc into POD and HTML manual-pages. See README.md |
|
7
|
|
|
|
|
|
|
# Copyright Mark Overmeer. Licensed under the same terms as Perl itself. |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Tie::Nested; |
|
10
|
2
|
|
|
2
|
|
2536
|
use vars '$VERSION'; |
|
|
2
|
|
|
|
|
8
|
|
|
|
2
|
|
|
|
|
106
|
|
|
11
|
|
|
|
|
|
|
$VERSION = '0.11'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
53
|
|
|
15
|
2
|
|
|
2
|
|
9
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
37
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
2
|
|
|
2
|
|
758
|
use Log::Report 'tie-nested', syntax => 'SHORT'; |
|
|
2
|
|
|
|
|
182799
|
|
|
|
2
|
|
|
|
|
12
|
|
|
18
|
2
|
|
|
2
|
|
1325
|
use Data::Dumper; |
|
|
2
|
|
|
|
|
9629
|
|
|
|
2
|
|
|
|
|
1033
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub TIEHASH(@) |
|
22
|
11
|
|
|
11
|
|
901
|
{ my $class = shift; |
|
23
|
11
|
100
|
|
|
|
30
|
my $add = @_ % 2 ? shift : {}; |
|
24
|
11
|
|
|
|
|
47
|
my $self = (bless {}, $class)->init({@_} ); |
|
25
|
11
|
|
|
|
|
42
|
my @a = %$add; |
|
26
|
11
|
|
|
|
|
52
|
tie %$add, $self->{mine}; |
|
27
|
11
|
|
|
|
|
309
|
$self->{data} = $add; |
|
28
|
11
|
|
|
|
|
40
|
$self->STORE(shift @a, shift @a) while @a; |
|
29
|
11
|
|
|
|
|
67
|
$self; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub TIEARRAY(@) |
|
34
|
0
|
|
|
0
|
|
0
|
{ my $class = shift; |
|
35
|
0
|
0
|
|
|
|
0
|
my $add = @_ % 2 ? shift : []; |
|
36
|
0
|
0
|
|
|
|
0
|
$add = [$add] if ref $add ne 'ARRAY'; |
|
37
|
0
|
|
|
|
|
0
|
my $self = (bless {}, $class)->init( {@_} ); |
|
38
|
0
|
|
|
|
|
0
|
tie @$add, $self->{mine}; |
|
39
|
0
|
|
|
|
|
0
|
$self->{data} = $add; |
|
40
|
0
|
|
|
|
|
0
|
$self; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub init($) |
|
44
|
11
|
|
|
11
|
0
|
27
|
{ my ($self, $args) = @_; |
|
45
|
|
|
|
|
|
|
|
|
46
|
11
|
|
|
|
|
13
|
my ($mine, @nest_opts); |
|
47
|
11
|
100
|
|
|
|
32
|
if(my $r = $args->{recurse}) |
|
|
|
50
|
|
|
|
|
|
|
48
|
6
|
100
|
|
|
|
18
|
{ $r = [ $r ] if ref $r ne 'ARRAY'; |
|
49
|
6
|
|
|
|
|
14
|
$mine = $r->[0]; |
|
50
|
6
|
|
|
|
|
15
|
@nest_opts = (recurse => $r); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
elsif(my $n = $args->{nestings}) |
|
53
|
5
|
50
|
|
|
|
13
|
{ ($mine, my @nest) = ref $n eq 'ARRAY' ? @$n : $n; |
|
54
|
5
|
100
|
|
|
|
13
|
@nest_opts = (nestings => \@nest) if @nest; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
else |
|
57
|
0
|
|
|
|
|
0
|
{ error __x"tie needs either 'recurse' or 'nestings' parameter"; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
11
|
50
|
|
|
|
23
|
defined $mine |
|
61
|
|
|
|
|
|
|
or error __x"requires a package name for the tie on the data"; |
|
62
|
|
|
|
|
|
|
|
|
63
|
11
|
|
|
|
|
27
|
$self->{mine} = $mine; |
|
64
|
11
|
100
|
|
|
|
24
|
$self->{nest} = \@nest_opts if @nest_opts; |
|
65
|
11
|
|
|
|
|
26
|
$self; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub STORE($$$) |
|
69
|
25
|
|
|
25
|
|
3228
|
{ my ($self, $k, $v) = @_; |
|
70
|
25
|
|
|
|
|
46
|
my $t = $self->{mine}; |
|
71
|
25
|
|
33
|
|
|
71
|
my $d = $self->{data} ||= $t->($k, $v); |
|
72
|
|
|
|
|
|
|
|
|
73
|
25
|
100
|
|
|
|
49
|
if(my $nest = $self->{nest}) |
|
74
|
|
|
|
|
|
|
{ |
|
75
|
21
|
100
|
66
|
|
|
135
|
if(ref $v eq 'HASH' && $nest->[1][0]->can('TIEHASH')) |
|
|
|
50
|
33
|
|
|
|
|
|
76
|
7
|
|
|
|
|
45
|
{ tie %$v, ref $self, {%$v}, @$nest; |
|
77
|
7
|
|
|
|
|
32
|
return $d->{$k} = $v; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
elsif(ref $v eq 'ARRAY' && $nest->[1][0]->can('TIEARRAY')) |
|
80
|
0
|
|
|
|
|
0
|
{ tie @$v, ref $self, [@$v], @$nest; |
|
81
|
0
|
|
|
|
|
0
|
return $d->{$k} = $v; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
18
|
|
|
|
|
85
|
(tied %$d)->STORE($k, $v); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $end; |
|
89
|
2
|
|
|
2
|
|
818
|
END { $end++ } |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
our $AUTOLOAD; |
|
92
|
|
|
|
|
|
|
sub AUTOLOAD(@) |
|
93
|
191
|
50
|
|
191
|
|
18053
|
{ return if $end; |
|
94
|
191
|
|
|
|
|
732
|
$AUTOLOAD =~ s/.*\:\://; |
|
95
|
191
|
|
|
|
|
359
|
my $d = shift->{data}; |
|
96
|
191
|
|
|
|
|
294
|
my $obj = tied %$d; |
|
97
|
191
|
100
|
66
|
|
|
755
|
return if $AUTOLOAD eq 'DESTROY' && ! $obj->can('DESTROY'); |
|
98
|
180
|
|
|
|
|
501
|
$obj->$AUTOLOAD(@_); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |