line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DataFlow::Item; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2247
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
46
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: A wrapper around the regular data processed by DataFlow |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.121830'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
656
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Moose::Autobox; |
12
|
|
|
|
|
|
|
use MooseX::Attribute::Chained; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use namespace::autoclean; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has 'metadata' => ( |
17
|
|
|
|
|
|
|
'is' => 'ro', |
18
|
|
|
|
|
|
|
'isa' => 'HashRef[Any]', |
19
|
|
|
|
|
|
|
'handles' => { metakeys => sub { shift->metadata->keys }, }, |
20
|
|
|
|
|
|
|
'lazy' => 1, |
21
|
|
|
|
|
|
|
'default' => sub { {} }, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has 'channels' => ( |
25
|
|
|
|
|
|
|
'is' => 'rw', |
26
|
|
|
|
|
|
|
'isa' => 'HashRef[Any]', |
27
|
|
|
|
|
|
|
'handles' => { channel_list => sub { shift->channels->keys }, }, |
28
|
|
|
|
|
|
|
'lazy' => 1, |
29
|
|
|
|
|
|
|
'default' => sub { {} }, |
30
|
|
|
|
|
|
|
'traits' => ['Chained'], |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub get_metadata { |
34
|
|
|
|
|
|
|
my ( $self, $key ) = @_; |
35
|
|
|
|
|
|
|
return $self->metadata->{$key}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub set_metadata { |
39
|
|
|
|
|
|
|
my ( $self, $key, $data ) = @_; |
40
|
|
|
|
|
|
|
$self->metadata->{$key} = $data; |
41
|
|
|
|
|
|
|
return $self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub get_data { |
45
|
|
|
|
|
|
|
my ( $self, $channel ) = @_; |
46
|
|
|
|
|
|
|
return $self->channels->{$channel}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub set_data { |
50
|
|
|
|
|
|
|
my ( $self, $channel, $data ) = @_; |
51
|
|
|
|
|
|
|
$self->channels->{$channel} = $data; |
52
|
|
|
|
|
|
|
return $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub itemize { ## no critic |
56
|
|
|
|
|
|
|
return __PACKAGE__->new()->set_data( $_[1], $_[2] ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub clone { |
60
|
|
|
|
|
|
|
my $self = shift; |
61
|
|
|
|
|
|
|
my @c = %{ $self->channels }; |
62
|
|
|
|
|
|
|
return __PACKAGE__->new( metadata => $self->metadata )->channels( {@c} ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub narrow { |
66
|
|
|
|
|
|
|
my ( $self, $channel ) = @_; |
67
|
|
|
|
|
|
|
return __PACKAGE__->new( metadata => $self->metadata, ) |
68
|
|
|
|
|
|
|
->set_data( $channel, $self->get_data($channel) ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=pod |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=encoding utf-8 |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 NAME |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
DataFlow::Item - A wrapper around the regular data processed by DataFlow |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 VERSION |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
version 1.121830 |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 SYNOPSIS |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
use DataFlow::Item; |
92
|
|
|
|
|
|
|
my $item = DataFlow::Item->itemize( 'channel_name', 42 ); |
93
|
|
|
|
|
|
|
say $item->get_data( 'channel_name' ); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$item->set_metadata( 'somekey', q{some meta value} ); |
96
|
|
|
|
|
|
|
say item->get_metadata( 'somekey' ); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 DESCRIPTION |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Wraps data and metadata for processing through DataFlow. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 metadata |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
A hash reference containing metada for the DataFlow. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 channels |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
A hash reference containing data for each 'channel'. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 METHODS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 metakeys |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
A convenience method that returns the list of the keys to the metadata hash |
117
|
|
|
|
|
|
|
reference. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 channel_list |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
A convenience method that returns the list of the keys to the channels hash |
122
|
|
|
|
|
|
|
reference. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 get_metadata |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Returns a metadata value, identified by its key. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 set_metadata |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Sets a metadata value, identified by its key. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 get_data |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Returns a channel value, identified by the channel name. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 set_data |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Sets a channel value, identified by the channel name. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 itemize |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This is a B<class> method that creates a new C<DataFlow::Item> with a certain |
143
|
|
|
|
|
|
|
data stored in a specific channel. As a class method, it must be called like |
144
|
|
|
|
|
|
|
this: |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
my $item = DataFlow::Item->itemize( 'channel1', { my => data } ); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 clone |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Makes a copy of the C<DataFlow::Item> object. Note that the whole metadata |
151
|
|
|
|
|
|
|
contents (hash reference, really) is passed by reference to the new instance, |
152
|
|
|
|
|
|
|
while the contents of the channels are copied one by one into the new object. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 narrow |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Makes a copy of the C<DataFlow::Item> object narrowed to one single channel. |
157
|
|
|
|
|
|
|
In other words, it is like clone, but the C<channels> will contain B<only> |
158
|
|
|
|
|
|
|
the channel specified as a parameter. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 SEE ALSO |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Please see those modules/websites for more information related to this module. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=over 4 |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item * |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
L<DataFlow|DataFlow> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=back |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 AUTHOR |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Alexei Znamensky <russoz@cpan.org> |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
This software is copyright (c) 2011 by Alexei Znamensky. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
181
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
You can make new bug reports, and view existing ones, through the |
186
|
|
|
|
|
|
|
web interface at L<http://rt.cpan.org>. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTY |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY |
191
|
|
|
|
|
|
|
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT |
192
|
|
|
|
|
|
|
WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER |
193
|
|
|
|
|
|
|
PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, |
194
|
|
|
|
|
|
|
EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE |
195
|
|
|
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
196
|
|
|
|
|
|
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE |
197
|
|
|
|
|
|
|
SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME |
198
|
|
|
|
|
|
|
THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
201
|
|
|
|
|
|
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR |
202
|
|
|
|
|
|
|
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE |
203
|
|
|
|
|
|
|
TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR |
204
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE |
205
|
|
|
|
|
|
|
SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
206
|
|
|
|
|
|
|
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
207
|
|
|
|
|
|
|
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
208
|
|
|
|
|
|
|
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
209
|
|
|
|
|
|
|
DAMAGES. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=cut |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
__END__ |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
|