| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Class::Data::Annotated; |
|
2
|
1
|
|
|
1
|
|
1704
|
use Data::Annotated; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use Data::Path; |
|
4
|
|
|
|
|
|
|
use Carp; |
|
5
|
|
|
|
|
|
|
use strict; |
|
6
|
|
|
|
|
|
|
use warnings; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Class::Data::Annotated - Data::Annotated wrapped objects |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Class::Data::Annotated; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $$obj = Class::Data::Annotated->new(); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.2'; |
|
21
|
|
|
|
|
|
|
my $callbacks = { |
|
22
|
|
|
|
|
|
|
key_does_not_exist => sub {}, |
|
23
|
|
|
|
|
|
|
index_does_not_exist => sub {}, |
|
24
|
|
|
|
|
|
|
retrieve_index_from_non_array => sub {}, |
|
25
|
|
|
|
|
|
|
retrieve_key_from_non_hash => sub {}, |
|
26
|
|
|
|
|
|
|
}; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 METHODS |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 new() |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
instantiate an Annotated Data Structure |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub new { |
|
38
|
|
|
|
|
|
|
my ($class, $struct) = @_; |
|
39
|
|
|
|
|
|
|
croak('I just gotta have data') unless $struct; |
|
40
|
|
|
|
|
|
|
return bless {Annotations => Data::Annotated->new(), Data => Data::Path->new($struct, $callbacks)}, $class; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 annotate($path, \%annotation) |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
annotate a peice of the data. if that piece does not exist it will return undef. Otherwise it returns the data annotated. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub annotate { |
|
50
|
|
|
|
|
|
|
my ($self, $path, $annotation) = @_; |
|
51
|
|
|
|
|
|
|
$self->_validate_path($path); |
|
52
|
|
|
|
|
|
|
if ($self->data()->get($path)) { |
|
53
|
|
|
|
|
|
|
$self->{Annotations}->annotate($path, $annotation); |
|
54
|
|
|
|
|
|
|
return $self->data()->get($path); |
|
55
|
|
|
|
|
|
|
} else { return } |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 annotations |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Returns a L object holding the dictionary of annotations for this object |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub annotations { |
|
65
|
|
|
|
|
|
|
return shift->{Annotations}; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 get($path) |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
retrieves the data for this path in the object. returns undef if data location does not exist |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub get { |
|
75
|
|
|
|
|
|
|
my ($self, $path) = @_; |
|
76
|
|
|
|
|
|
|
$self->_validate_path($path); |
|
77
|
|
|
|
|
|
|
return $self->data()->get($path); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 get_annotation($path) |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
returns the annotations for the location in the data specified by the path. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub get_annotation { |
|
87
|
|
|
|
|
|
|
my ($self, $path) = @_; |
|
88
|
|
|
|
|
|
|
$self->_validate_path($path); |
|
89
|
|
|
|
|
|
|
return $self->annotations->{$path}; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 data |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Returns a L object holding the data in this object |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub data { |
|
99
|
|
|
|
|
|
|
return shift->{Data}; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 INTERNAL METHODS |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 _validate_path($path) |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
validates a L path. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub _validate_path { |
|
111
|
|
|
|
|
|
|
my ($self, $path) = @_; |
|
112
|
|
|
|
|
|
|
croak('Invalid Path: '.$path) unless $self->annotations()->_validate_path($path); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |