| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Data::Hash::DotNotation; |
|
2
|
2
|
|
|
2
|
|
1685
|
use strict; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
43
|
|
|
3
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
|
2
|
|
|
|
|
1
|
|
|
|
2
|
|
|
|
|
60
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.02'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
961
|
use Moose; |
|
|
2
|
|
|
|
|
588007
|
|
|
|
2
|
|
|
|
|
13
|
|
|
8
|
2
|
|
|
2
|
|
9301
|
use Carp; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
877
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Data::Hash::DotNotation - Convenient representation for nested Hash structures |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSYS |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Data::Hash::DotNotation; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $dn = Data::Hash::DotNotation->new({ |
|
19
|
|
|
|
|
|
|
name => 'Gurgeh', |
|
20
|
|
|
|
|
|
|
planet => 'earth', |
|
21
|
|
|
|
|
|
|
score => { |
|
22
|
|
|
|
|
|
|
contact => 10, |
|
23
|
|
|
|
|
|
|
scrabble => 20, |
|
24
|
|
|
|
|
|
|
}, |
|
25
|
|
|
|
|
|
|
}); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
print $dn->get('score.contact'); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 METHODS |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'data' => ( |
|
34
|
|
|
|
|
|
|
is => 'rw', |
|
35
|
|
|
|
|
|
|
default => sub { {}; }, |
|
36
|
|
|
|
|
|
|
); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 get |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get { |
|
43
|
4
|
|
|
4
|
1
|
24
|
my $self = shift; |
|
44
|
4
|
100
|
|
|
|
16
|
my $name = shift or croak "No name given"; |
|
45
|
3
|
|
|
|
|
4
|
return $self->_get($name); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 set |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub set { |
|
53
|
5
|
|
|
5
|
1
|
1894
|
my $self = shift; |
|
54
|
5
|
100
|
|
|
|
29
|
my $name = shift or croak 'No name given'; |
|
55
|
4
|
|
|
|
|
5
|
my $value = shift; |
|
56
|
|
|
|
|
|
|
|
|
57
|
4
|
|
|
|
|
10
|
$self->_set($name, $value); |
|
58
|
|
|
|
|
|
|
|
|
59
|
4
|
|
|
|
|
29
|
return $value; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 key_exists |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub key_exists { |
|
67
|
2
|
|
|
2
|
1
|
436
|
my $self = shift; |
|
68
|
2
|
|
|
|
|
4
|
my $name = shift; |
|
69
|
2
|
|
|
|
|
45
|
my $data = $self->data; |
|
70
|
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
7
|
my @parts = split(/\./, $name); |
|
72
|
2
|
|
|
|
|
5
|
my $node = pop @parts; |
|
73
|
|
|
|
|
|
|
|
|
74
|
2
|
|
33
|
|
|
11
|
while ($data and (my $section = shift @parts)) { |
|
75
|
0
|
0
|
|
|
|
0
|
if (ref $data->{$section} eq 'HASH') { |
|
76
|
0
|
|
|
|
|
0
|
$data = $data->{$section}; |
|
77
|
|
|
|
|
|
|
} else { |
|
78
|
0
|
|
|
|
|
0
|
return; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
2
|
|
|
|
|
7
|
return exists $data->{$node}; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _get { |
|
86
|
3
|
|
|
3
|
|
4
|
my $self = shift; |
|
87
|
3
|
|
|
|
|
4
|
my $name = shift; |
|
88
|
3
|
|
|
|
|
68
|
my $data = $self->data; |
|
89
|
|
|
|
|
|
|
|
|
90
|
3
|
|
|
|
|
8
|
my @parts = split(/\./, $name); |
|
91
|
3
|
|
|
|
|
5
|
my $node = pop @parts; |
|
92
|
|
|
|
|
|
|
|
|
93
|
3
|
|
66
|
|
|
15
|
while ($data and (my $section = shift @parts)) { |
|
94
|
2
|
50
|
|
|
|
7
|
if (ref $data->{$section} eq 'HASH') { |
|
95
|
2
|
|
|
|
|
7
|
$data = $data->{$section}; |
|
96
|
|
|
|
|
|
|
} else { |
|
97
|
0
|
|
|
|
|
0
|
return; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
3
|
100
|
33
|
|
|
10
|
if ($data and exists $data->{$node}) { |
|
102
|
2
|
|
|
|
|
9
|
return $data->{$node}; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
1
|
|
|
|
|
4
|
return; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub _set { |
|
109
|
4
|
|
|
4
|
|
3
|
my $self = shift; |
|
110
|
4
|
|
|
|
|
3
|
my $name = shift; |
|
111
|
4
|
|
|
|
|
5
|
my $value = shift; |
|
112
|
|
|
|
|
|
|
|
|
113
|
4
|
50
|
|
|
|
91
|
unless ($self->data) { |
|
114
|
0
|
|
|
|
|
0
|
$self->data({}); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
4
|
|
|
|
|
10
|
my @tarts = split(/\./, $name); |
|
118
|
4
|
|
|
|
|
5
|
my $node = pop @tarts; |
|
119
|
|
|
|
|
|
|
|
|
120
|
4
|
|
|
|
|
64
|
my $current_location = $self->data; |
|
121
|
4
|
|
|
|
|
7
|
foreach my $section (@tarts) { |
|
122
|
2
|
|
50
|
|
|
8
|
$current_location->{$section} //= {}; |
|
123
|
2
|
|
|
|
|
3
|
$current_location = $current_location->{$section}; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
4
|
100
|
|
|
|
7
|
if (defined($value)) { |
|
127
|
3
|
|
|
|
|
6
|
$current_location->{$node} = $value; |
|
128
|
|
|
|
|
|
|
} else { |
|
129
|
1
|
|
|
|
|
1
|
delete $current_location->{$node}; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
4
|
|
|
|
|
61
|
return $self->data; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
2
|
|
|
2
|
|
10
|
no Moose; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
10
|
|
|
136
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=over 4 |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item L<Moose> |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=back |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 SOURCE CODE |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
L<GitHub|https://github.com/binary-com/perl-Data-Hash-DotNotation> |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 AUTHOR |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
binary.com, C<< <perl at binary.com> >> |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 BUGS |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
157
|
|
|
|
|
|
|
C<bug-moosex-role-registry at rt.cpan.org>, or through the web |
|
158
|
|
|
|
|
|
|
interface at |
|
159
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-Hash-DotNotation>. |
|
160
|
|
|
|
|
|
|
We will be notified, and then you'll automatically be notified of progress on |
|
161
|
|
|
|
|
|
|
your bug as we make changes. |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 SUPPORT |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
perldoc Data::Hash::DotNotation |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
You can also look for information at: |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=over 4 |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-Hash-DotNotation> |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
L<http://annocpan.org/dist/Data-Hash-DotNotation> |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/Data-Hash-DotNotation> |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=item * Search CPAN |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/Data-Hash-DotNotation/> |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=back |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
1; |
|
194
|
|
|
|
|
|
|
|