line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Grepl::Results; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
25416
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
156
|
|
4
|
6
|
|
|
6
|
|
28
|
use strict; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
164
|
|
5
|
6
|
|
|
6
|
|
520
|
use App::Grepl; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
148
|
|
6
|
6
|
|
|
6
|
|
2787
|
use App::Grepl::Results::Token; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
162
|
|
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
33
|
use base 'App::Grepl::Base'; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
398
|
|
9
|
6
|
|
|
6
|
|
31
|
use Scalar::Util 'reftype'; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
2442
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
App::Grepl::Results - PPI-powered grep results object |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 0.01 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
OO interface to grepl's results |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use App::Grepl::Results; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $found = App::Grepl::Results->new( { |
30
|
|
|
|
|
|
|
file => $file, |
31
|
|
|
|
|
|
|
} ); |
32
|
|
|
|
|
|
|
$found->add_results( $token => \@results ); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
print $found->file, "\n"; |
35
|
|
|
|
|
|
|
while ( my $result = $found->next ) { |
36
|
|
|
|
|
|
|
print $result->token, "matched:\n"; |
37
|
|
|
|
|
|
|
while ( my $item = $result->next ) { |
38
|
|
|
|
|
|
|
print "\t$item\n"; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 METHODS |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 Class Methods |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head3 C |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $grepl = App::Grepl::Results->new( { file => $file } ); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _initialize { |
53
|
8
|
|
|
8
|
|
18
|
my ( $self, $arg_for ) = @_; |
54
|
|
|
|
|
|
|
|
55
|
8
|
|
|
|
|
37
|
$self->file( delete $arg_for->{file} ); |
56
|
7
|
|
|
|
|
24
|
$self->{results} = []; |
57
|
7
|
|
|
|
|
27
|
return $self; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 Instance Methods |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head3 C |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $file = $result->file; |
65
|
|
|
|
|
|
|
$result->file($file); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Get or set the filename the results pertain to. Will C if the file |
68
|
|
|
|
|
|
|
does not exist. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub file { |
73
|
13
|
|
|
13
|
1
|
35
|
my $self = shift; |
74
|
13
|
100
|
|
|
|
100
|
return $self->{file} unless @_; |
75
|
8
|
|
|
|
|
16
|
my $file = shift; |
76
|
8
|
100
|
|
|
|
277
|
unless ( -e $file ) { |
77
|
1
|
|
|
|
|
6
|
$self->_croak("Cannot find file ($file)"); |
78
|
|
|
|
|
|
|
} |
79
|
7
|
|
|
|
|
45
|
$self->{file} = $file; |
80
|
7
|
|
|
|
|
16
|
return $self; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head3 C |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
if ( $found->have_results ) { ... } |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Boolean accessor indicating if we have results for the search. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
6
|
|
|
6
|
1
|
12
|
sub have_results { return scalar @{ shift->{results} } } |
|
6
|
|
|
|
|
30
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head3 C |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$found->add_results( 'heredoc' => \@array_ref_of_strings ); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Add results to the result object. Takes two arguments: |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=over 4 |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item * token |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This should be a string representing the result type (e.g., C, |
104
|
|
|
|
|
|
|
C, etc). |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Will C if C does not recognize the result type. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * results |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This should be an array reference of strings. These are the actual results. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Will C if something other than an array reference is passed. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=back |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub add_results { |
119
|
10
|
|
|
10
|
1
|
1277
|
my ( $self, $elem, $results ) = @_; |
120
|
10
|
|
|
|
|
16
|
push @{ $self->{results} } => App::Grepl::Results::Token->new( { |
|
10
|
|
|
|
|
108
|
|
121
|
|
|
|
|
|
|
token => $elem, |
122
|
|
|
|
|
|
|
results => $results, |
123
|
|
|
|
|
|
|
} ); |
124
|
8
|
|
|
|
|
37
|
return $self; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head3 C |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
if ( $result->filename_only ) { |
130
|
|
|
|
|
|
|
... |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
$result->filename_only(1); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
A boolean getter/setter for whether or not results are 'filename only'. These |
135
|
|
|
|
|
|
|
are returned to indicated that a file matched the criteria. The actual |
136
|
|
|
|
|
|
|
matches will not be returned. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub filename_only { |
141
|
13
|
|
|
13
|
1
|
28
|
my $self = shift; |
142
|
13
|
100
|
|
|
|
92
|
return $self->{filename_only} unless @_; |
143
|
5
|
|
|
|
|
12
|
my $filename_only = shift; |
144
|
5
|
|
|
|
|
12
|
$self->{filename_only} = $filename_only; |
145
|
5
|
|
|
|
|
13
|
return $self; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head3 C |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
while ( defined ( my $result = $found->next ) ) { |
151
|
|
|
|
|
|
|
... |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Returns the next result found. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Will C if results are requested from a 'filename_only' object. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Note that the iterator is destructive. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub next { |
163
|
8
|
|
|
8
|
1
|
18
|
my $self = shift; |
164
|
8
|
100
|
|
|
|
34
|
if ( $self->filename_only ) { |
165
|
1
|
|
|
|
|
12
|
$self->_croak("No results available for 'filename_only' results objects"); |
166
|
|
|
|
|
|
|
} |
167
|
7
|
|
|
|
|
12
|
my $next = shift @{ $self->{results} }; |
|
7
|
|
|
|
|
45
|
|
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 AUTHOR |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Curtis Poe, C<< >> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 BUGS |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
177
|
|
|
|
|
|
|
C, or through the web interface at |
178
|
|
|
|
|
|
|
L. |
179
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
180
|
|
|
|
|
|
|
your bug as I make changes. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 SUPPORT |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
perldoc App::Grepl::Results |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
You can also look for information at: |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=over 4 |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
L |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item * CPAN Ratings |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
L |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
L |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item * Search CPAN |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
L |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=back |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Copyright 2007 Curtis Poe, all rights reserved. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
217
|
|
|
|
|
|
|
under the same terms as Perl itself. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=cut |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
1; |