line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pod::Abstract::Filter::find; |
2
|
1
|
|
|
1
|
|
1087
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use base qw(Pod::Abstract::Filter); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
67
|
|
6
|
1
|
|
|
1
|
|
4
|
use Pod::Abstract::BuildNode qw(node); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
436
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.20'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Pod::Abstract::Filter::find - paf command to find specific nodes that |
13
|
|
|
|
|
|
|
contain a string. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
The intention of this filter is to allow a reduction of large Pod |
18
|
|
|
|
|
|
|
documents to find a specific function or method. You call C
|
19
|
|
|
|
|
|
|
-f=function YourModule>, and you get a small subset of nodes matching |
20
|
|
|
|
|
|
|
"function". |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
For this to work, there has to be some assumptions about Pod structure. I |
23
|
|
|
|
|
|
|
am presuming that find is not useful if it returns anything higher than a |
24
|
|
|
|
|
|
|
head2, so as long as your module wraps function doco in a head2, head3, |
25
|
|
|
|
|
|
|
head4 or list item, we're fine. If you use head1 then it won't be useful. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
In order to be useful as an end user tool, head1 nodes (...) are added |
28
|
|
|
|
|
|
|
between the found nodes. This stops perldoc from dying with no |
29
|
|
|
|
|
|
|
documentation. These can be easily stripped using: |
30
|
|
|
|
|
|
|
C<< $pa->select('/head1') >>, then hoist and detach, or reparent to other |
31
|
|
|
|
|
|
|
Node types. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
A good example of this working as intended is: |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
paf find select Pod::Abstract::Node |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub require_params { |
40
|
0
|
|
|
0
|
1
|
|
return ( 'f' ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub filter { |
44
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
45
|
0
|
|
|
|
|
|
my $pa = shift; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $find_string = $self->param('f'); |
48
|
0
|
0
|
0
|
|
|
|
unless($find_string && $find_string =~ m/^[a-zA-Z0-9_]+$/) { |
49
|
0
|
|
|
|
|
|
die "find: string must be specified with -f=str.\nMust be a simple string.\n"; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $out_doc = node->root; |
53
|
0
|
|
|
|
|
|
$out_doc->nest(node->pod); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Don't select parent nodes, leaf nodes only |
56
|
0
|
|
|
|
|
|
my @targets = $pa->select("//[. =~ {$find_string}][!/]"); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Don't accept anything less specific than a head2 |
59
|
0
|
|
|
|
|
|
my @dest_ok = qw(head2 head3 head4 item); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my %finals = ( ); |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
foreach my $t (@targets) { |
64
|
0
|
|
0
|
|
|
|
while($t->parent && !( grep { $t->type eq $_ } @dest_ok )) { |
|
0
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$t = $t->parent; |
66
|
|
|
|
|
|
|
} |
67
|
0
|
0
|
|
|
|
|
if(grep { $t->type eq $_ } @dest_ok) { |
|
0
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
unless($finals{$t->serial}) { |
69
|
0
|
|
|
|
|
|
my $head = node->head1('...'); |
70
|
0
|
0
|
|
|
|
|
if($t->type eq 'item') { |
71
|
0
|
|
|
|
|
|
my $over = node->over; |
72
|
0
|
|
|
|
|
|
$over->nest($t->duplicate); |
73
|
0
|
|
|
|
|
|
$head->nest($over); |
74
|
|
|
|
|
|
|
} else { |
75
|
0
|
|
|
|
|
|
$head->nest($t->duplicate); |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
|
$out_doc->push($head); |
78
|
0
|
|
|
|
|
|
$finals{$t->serial} = 1; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return $out_doc; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 AUTHOR |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Ben Lilburne |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Copyright (C) 2009 Ben Lilburne |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
95
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |