blib/lib/File/Find/Rule/PPI.pm

filter: Statementstmt 83.7% 31 / 37 Branchbran 41.6% 5 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 1 totaltotal 75.0% 45 / 60 SCAR 20.7
CC
7
Cov
73%
__ANON__
12.0
ppi_find_any
4.0
__ANON__
3.0
CRAP 7.9
↑ Summary
1 package File::Find::Rule::PPI;
2  
3 =pod
4  
5 =head1 NAME
6  
7 File::Find::Rule::PPI - Add support for PPI queries to File::Find::Rule
8  
9 =head1 SYNOPSIS
10  
11 use File::Find::Rule ();
12 use File::Find::Rule::PPI ();
13  
14 # Find all perl modules that use here-docs
15 my $Find = File::Find::Rule->file
16 ->name('*.pm')
17 ->ppi_find_any('Token::HereDoc');
18 my @heredoc = $Find->in( $dir );
19  
20 =head1 DESCRIPTION
21  
22 File::Find::Rule::PPI allows you to integrate PPI content queries
23 into your L<File::Find::Rule> searches.
24  
25 Initially, it provides the one additional method C<ppi_find_any>,
26 which takes an argument identical to the L<PPI::Node> method C<find_any>
27 and checks each file as a perl document to see if matches the query.
28  
29 =head1 METHODS
30  
31 =cut
32  
33 2 ▶use 5.005;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 2 ▶use Params::Util 0.10 '_INSTANCE';
Subroutine BEGIN: called CC=1 SCAR=0.0
36 2 ▶use File::Find::Rule 0.20 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
37 2 ▶use PPI 1.000 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 2 ▶use vars qw{$VERSION @ISA @EXPORT};
Subroutine BEGIN: called CC=1 SCAR=0.0
40 BEGIN {
41 2 ▶ $VERSION = '1.06';
Subroutine BEGIN: called CC=1 SCAR=0.0
42 2 @ISA = 'File::Find::Rule';
43 2 @EXPORT = @File::Find::Rule::EXPORT;
44  
45 # Preload PPI::Find module if needed and possible
46 2 eval "use prefork => 'PPI::Find';";
47 }
48  
49  
50  
51  
52  
53 #####################################################################
54 # Add the methods to File::Find::Rule
55  
56 =pod
57  
58 =head2 ppi_find_any $condition | $PPI::Find
59  
60 The C<ppi_find_any> method causes a query identical to (and implemented
61 using) L<PPI::Node>'s C<find_any> method.
62  
63 It takes as argument any condition that would also be valid for the above
64 method.
65  
66 In addition, it can also take as argument an instantiated L<PPI::Find>
67 object, and will use that object's C<any_matches> method to achieve the
68 same effect.
69  
70 If you provide no or an illegal condition to ppi_find_any, the check will
71 always fail, and B<no> files will be returned when you execute the search.
72  
73 =cut
74  
75 sub File::Find::Rule::ppi_find_any {
76 2 ▶ require PPI;
Subroutine ppi_find_any: called CC=3 SCAR=13.9
Pod undocumented
77 2 my $self = shift()->_force_object;
78  
79 # Is this a PPI::Find object
80 2 ▶ if ( _INSTANCE($_[0], 'PPI::Find') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_INSTANCE($_[0], "PPI::Find")) 0 2 2
81 0 require PPI::Find;
82 0 my $Find = shift;
83 return $self->exec( sub {
84 0 ▶ my $Document = PPI::Document->new($_) or return;
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
my $Document = "PPI::Document"->new($_) or return 0 0 0
85 0 ▶ $Find->any_matches or return;
Branch: 1 branch
BranchTrueFalseTotal
$Find->any_matches or return 0 0 0
86 0 1;
87 0 } );
88 }
89  
90 # Normal Document->find_any test
91 2 my $condition = PPI::Node->_wanted(shift);
92  
93 # If you want to find crap, you never will
94 2 ▶ return $self->discard unless $condition;
Branch: 1 branch
BranchTrueFalseTotal
unless $condition 0 2 2
95  
96 # Add the query for a valid condition
97 $self->exec( sub {
98 6 ▶ my $Document = PPI::Document->new($_) or return;
Subroutine __ANON__: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
my $Document = "PPI::Document"->new($_) or return 0 6 6
99 6 ▶ $Document->find_any( $condition ) or return;
Branch: 1 branch
BranchTrueFalseTotal
$Document->find_any($condition) or return 1 5 6
100 5 1;
101 2 } );
102 }
103  
104 2 1;
105  
106 =pod
107  
108 =head1 SUPPORT
109  
110 Bugs should always be submitted via the CPAN bug tracker
111  
112 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Find-Rule-PPI>
113  
114 For other issues, contact the maintainer
115  
116 =head1 AUTHOR
117  
118 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
119  
120 =head1 ACKNOWLEDGMENTS
121  
122 Funding provided by The Perl Foundation
123  
124 =head1 SEE ALSO
125  
126 L<http://ali.as/>, L<File::Find::Rule>, L<PPI>
127  
128 =head1 COPYRIGHT
129  
130 Copyright 2005 - 2010 Adam Kennedy.
131  
132 This program is free software; you can redistribute
133 it and/or modify it under the same terms as Perl itself.
134  
135 The full text of the license can be found in the
136 LICENSE file included with this module.
137  
138 =cut
↑ Summary