File Coverage

blib/lib/Pod/Abstract/Filter.pm
Criterion Covered Total %
statement 9 26 34.6
branch 0 2 0.0
condition n/a
subroutine 3 8 37.5
pod 5 5 100.0
total 17 41 41.4


line stmt bran cond sub pod time code
1             package Pod::Abstract::Filter;
2 1     1   4100 use strict;
  1         2  
  1         33  
3 1     1   4 use warnings;
  1         2  
  1         28  
4              
5 1     1   5 use Pod::Abstract;
  1         1  
  1         256  
6              
7             our $VERSION = '0.20';
8              
9             =head1 NAME
10              
11             Pod::Abstract::Filter - Generic Pod-in to Pod-out filter.
12              
13             =head1 DESCRIPTION
14              
15             This is a superclass for filter modules using
16             Pod::Abstract. Subclasses should override the C
17             sub. Pod::Abstract::Filter classes in the Pod::Abstract::Filter
18             namespace will be used by the C utility.
19              
20             To create a filter, you need to implement:
21              
22             =over
23              
24             =item filter
25              
26             Takes a Pod::Abstract::Node tree, and returns either another tree, or
27             a string. If a string is returned, it will be re-parsed to be input to
28             any following filter, or output directly if it is the last filter in
29             the list.
30              
31             It is recommended your filter method produce a Node tree if you are able
32             to, as this will improve interoperability with other C
33             based software.
34              
35             =item require_params
36              
37             If you want positional arguments following your filter in the style of:
38              
39             paf find [thing] Pod::Abstract
40              
41             then override require_params to list the named arguments that are to
42             be accepted after the filter name.
43              
44             =back
45              
46             =head1 METHODS
47              
48             =head2 new
49              
50             Create a new filter with the specified arguments.
51              
52             =cut
53              
54             sub new {
55 0     0 1   my $class = shift;
56 0           my %args = @_;
57            
58 0           return bless { %args }, $class;
59             }
60              
61             =head2 require_params
62              
63             Override to return a list of parameters that must be provided. This
64             will be accepted in order on the command line, unless they are first
65             set using the C<-flag=xxx> notation.
66              
67             =cut
68              
69             sub require_params {
70 0     0 1   return ( );
71             }
72              
73             =head2 param
74              
75             Get the named param. Read only.
76              
77             =cut
78              
79             sub param {
80 0     0 1   my $self = shift;
81 0           my $param_name = shift;
82 0           return $self->{$param_name};
83             }
84              
85             =head2 filter
86              
87             Stub method. Does nothing, just returns the original tree.
88              
89             =cut
90              
91             sub filter {
92 0     0 1   my $self = shift;
93 0           my $pa = shift;
94            
95 0           return $pa;
96             }
97              
98             =head2 run
99              
100             Run the filter. If $arg is a string, it will be parsed
101             first. Otherwise, the Abstract tree will be used. Returns either a
102             string or an abstract tree (which may be the original tree, modified).
103              
104             =cut
105              
106             sub run {
107 0     0 1   my $self = shift;
108 0           my $arg = shift;
109            
110 0 0         if( eval { $arg->isa( 'Pod::Abstract::Node' ) } ) {
  0            
111 0           return $self->filter($arg);
112             } else {
113 0           my $pa = Pod::Abstract->load_string($arg);
114 0           return $self->filter($pa);
115             }
116             }
117              
118             =head1 AUTHOR
119              
120             Ben Lilburne
121              
122             =head1 COPYRIGHT AND LICENSE
123              
124             Copyright (C) 2009 Ben Lilburne
125              
126             This program is free software; you can redistribute it and/or modify
127             it under the same terms as Perl itself.
128              
129             =cut
130              
131             1;