File Coverage

lib/DataFlow/Proc/DPath.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package DataFlow::Proc::DPath;
2              
3 1     1   40506 use strict;
  1         3  
  1         35  
4 1     1   5 use warnings;
  1         1  
  1         42  
5              
6             # ABSTRACT: A processor that filters parts of data structures
7              
8             our $VERSION = '1.112100'; # VERSION
9              
10 1     1   561 use Moose;
  0            
  0            
11             extends 'DataFlow::Proc';
12              
13             use namespace::autoclean;
14              
15             use Data::DPath qw{dpath dpathr};
16              
17             has 'search_dpath' => (
18             'is' => 'ro',
19             'isa' => 'Str',
20             'required' => 1,
21             );
22              
23             has 'references' => (
24             'is' => 'ro',
25             'isa' => 'Bool',
26             'default' => 0,
27             );
28              
29             sub _policy { return 'ScalarOnly' }
30              
31             sub _make_dpath {
32             my $self = shift;
33             return $self->references
34             ? dpathr( $self->search_dpath )
35             : dpath( $self->search_dpath );
36             }
37              
38             sub _build_p {
39             my $self = shift;
40             return sub { return $self->_make_dpath->match($_) };
41             }
42              
43             __PACKAGE__->meta->make_immutable;
44              
45             1;
46              
47              
48              
49             =pod
50              
51             =encoding utf-8
52              
53             =head1 NAME
54              
55             DataFlow::Proc::DPath - A processor that filters parts of data structures
56              
57             =head1 VERSION
58              
59             version 1.112100
60              
61             =head1 SYNOPSIS
62              
63             use DataFlow::Proc::DPath;
64             my $proc =
65             DataFlow::Proc::DPath->new( search_dpath => '//*[key =~ /potatoes/]' );
66              
67             @result = $proc->process($data); # some complex data structure
68              
69             # Or, more commonly
70              
71             use DataFlow;
72              
73             my $flow = DataFlow->new([
74             # ...
75             [ DPath => search_dpath => '//*[key =~ /potatoes/]' ],
76             # ...
77             ]);
78              
79             @result = $flow->process($data);
80              
81             =head1 DESCRIPTION
82              
83             This processor provides a filter for Perl data structures using the
84             L<Data::DPath> module. Items will B<always> be treated as scalars (it is
85             likely they will be references to more complex structures, but
86             nonetheless, scalars) and the result will B<always> be an array, with zero
87             or more elements.
88              
89             Use the C<references> attribute if you want to receive references to the
90             filtered-down content (perhaps you would like to modify only a part of the
91             data structure).
92              
93             =head1 ATTRIBUTES
94              
95             =head2 search_dpath
96              
97             The path expression used by the L<Data::DPath> functions.
98              
99             =head2 references
100              
101             This attribute is a boolean, and it signals whether the result list should
102             have references into the data structure or simple copies. The default is 0
103             (false).
104              
105             =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders
106              
107             =head1 SUPPORT
108              
109             =head2 Perldoc
110              
111             You can find documentation for this module with the perldoc command.
112              
113             perldoc DataFlow::Proc::DPath
114              
115             =head2 Websites
116              
117             The following websites have more information about this module, and may be of help to you. As always,
118             in addition to those websites please use your favorite search engine to discover more resources.
119              
120             =over 4
121              
122             =item *
123              
124             Search CPAN
125              
126             The default CPAN search engine, useful to view POD in HTML format.
127              
128             L<http://search.cpan.org/dist/DataFlow-Proc-DPath>
129              
130             =item *
131              
132             AnnoCPAN
133              
134             The AnnoCPAN is a website that allows community annonations of Perl module documentation.
135              
136             L<http://annocpan.org/dist/DataFlow-Proc-DPath>
137              
138             =item *
139              
140             CPAN Ratings
141              
142             The CPAN Ratings is a website that allows community ratings and reviews of Perl modules.
143              
144             L<http://cpanratings.perl.org/d/DataFlow-Proc-DPath>
145              
146             =item *
147              
148             CPAN Forum
149              
150             The CPAN Forum is a web forum for discussing Perl modules.
151              
152             L<http://cpanforum.com/dist/DataFlow-Proc-DPath>
153              
154             =item *
155              
156             CPANTS
157              
158             The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
159              
160             L<http://cpants.perl.org/dist/overview/DataFlow-Proc-DPath>
161              
162             =item *
163              
164             CPAN Testers
165              
166             The CPAN Testers is a network of smokers who run automated tests on uploaded CPAN distributions.
167              
168             L<http://www.cpantesters.org/distro/D/DataFlow-Proc-DPath>
169              
170             =item *
171              
172             CPAN Testers Matrix
173              
174             The CPAN Testers Matrix is a website that provides a visual way to determine what Perls/platforms PASSed for a distribution.
175              
176             L<http://matrix.cpantesters.org/?dist=DataFlow-Proc-DPath>
177              
178             =back
179              
180             =head2 Email
181              
182             You can email the author of this module at C<RUSSOZ at cpan.org> asking for help with any problems you have.
183              
184             =head2 Internet Relay Chat
185              
186             You can get live help by using IRC ( Internet Relay Chat ). If you don't know what IRC is,
187             please read this excellent guide: L<http://en.wikipedia.org/wiki/Internet_Relay_Chat>. Please
188             be courteous and patient when talking to us, as we might be busy or sleeping! You can join
189             those networks/channels and get help:
190              
191             =over 4
192              
193             =item *
194              
195             irc.perl.org
196              
197             You can connect to the server at 'irc.perl.org' and join this channel: #sao-paulo.pm then talk to this person for help: russoz.
198              
199             =back
200              
201             =head2 Bugs / Feature Requests
202              
203             Please report any bugs or feature requests by email to C<bug-dataflow-proc-dpath at rt.cpan.org>, or through
204             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DataFlow-Proc-DPath>. You will be automatically notified of any
205             progress on the request by the system.
206              
207             =head2 Source Code
208              
209             The code is open to the world, and available for you to hack on. Please feel free to browse it and play
210             with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
211             from your repository :)
212              
213             L<https://github.com/russoz/DataFlow-Proc-DPath>
214              
215             git clone https://github.com/russoz/DataFlow-Proc-DPath
216              
217             =head1 AUTHOR
218              
219             Alexei Znamensky <russoz@cpan.org>
220              
221             =head1 COPYRIGHT AND LICENSE
222              
223             This software is copyright (c) 2011 by Alexei Znamensky.
224              
225             This is free software; you can redistribute it and/or modify it under
226             the same terms as the Perl 5 programming language system itself.
227              
228             =head1 BUGS AND LIMITATIONS
229              
230             No bugs have been reported.
231              
232             Please report any bugs or feature requests through the web interface at
233             L<http://rt.cpan.org>.
234              
235             =head1 DISCLAIMER OF WARRANTY
236              
237             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
238             FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT
239             WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER
240             PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND,
241             EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
242             IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
243             PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
244             SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME
245             THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
246              
247             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
248             WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
249             REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE
250             TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR
251             CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
252             SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
253             RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
254             FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
255             SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
256             DAMAGES.
257              
258             =cut
259              
260              
261             __END__
262