Filter/Transform.pm

filter: Statementstmt 100% 39 / 39 Branchbran n/a Conditioncond 63.6% 14 / 22 MC/DCmcdc 38.4% 5 / 13 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 80.7% 67 / 83 CC 9 SCAR 17.8
CC
9
Cov
87%
init
9.8
BEGIN
1.0
BEGIN
1.0
CRAP 5.9
« Filter/Transform/Internal.pm ↑ Summary Filter/Storage/DBI.pm »
1 package List::Filter::Transform;
2 2 ▶use base qw( List::Filter );
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 =head1 NAME
5  
6 List::Filter::Transform - lists of find-and-replace operations
7  
8 =head1 SYNOPSIS
9  
10 use List::Filter::Transform;
11  
12 @terms = ( [ 'subroutine', 'gi', 'method' ],
13 { 'field', 'gi', 'attribute' ],
14 { 'functional', 'gi', 'not broken' ],
15 );
16  
17 my $filter = List::Filter::Transform->new(
18 { name => 'oop_up_docs',
19 terms => \@terms ,
20 description =>
21 "Hunt and destroy passe jargon in docs for spiffy OOP code.",
22 modifiers => "gi", # redundant with settings in @terms
23 } ); # Letting method default to 'sequential'
24  
25  
26  
27 # If non-standard behavior is desired in locating the methods via plugins
28 my $filter = List::Filter::Transform->new(
29 { name => 'oop_up_docs',
30 terms => \@terms ,
31 description =>
32 "Hunt and destroy passe jargon in docs for spiffy OOP code.",
33 modifiers => "g",
34 method => "reverse",
35 plugin_root => "List::Filter::Transform::Internal",
36 plugin_exceptions => ["List::Filter::Transforms::NotThisOne"],
37  
38 } );
39  
40 # alternately
41 my $filter = List::Filter::Transform->new(); # creates an empty filter
42  
43 my @terms = [ [ 'find_me', 'i', 'replace_with_this' ],
44 [ 'function', '', 'method' ],
45 [ 'variable', '', 'attribute' ],
46 [ 'Function', '', 'Method' ],
47 [ 'Variable', '', 'Attribute' ],
48 ];
49 $filter->set_name('oop_up_docs');
50 $filter->set_terms( \@terms );
51 $filter->set_method('sequential'); # typical
52 $filter->set_description(
53 "Hunt and destroy passe jargon in docs for spiffy OOP code.");
54 $filter->set_modifiers( "g" ); # 'g' applied, uh, 'globally'
55  
56  
57  
58 =head1 DESCRIPTION
59  
60 A "transform" is like a List::Filter "filter" (L<List::Filter>),
61 except that each pattern has an associated replacement expression.
62 A "transform" is essentially a list of perl substitutions ("s///").
63  
64 At the core of a transform object is the "terms" attribute, an
65 array of arrays of three values:
66  
67 (1) a perl regular expression,
68 (2) external match modifiers (e.g. 'g'),
69 (3) the replacement expression to substitute for a match
70  
71 Note: future versions of this code may have support for
72 (4) (optional) a hashref of miscellanious transform attributes.
73  
74 As with "filters", each transform has a "method" field which
75 specifies how the transform will be used by default. It is
76 expected that applying the substitutions in sequence will be
77 used so frequently, that the default method itself defaults
78 to "sequential".
79  
80 Valid methods are defined in the List::Filter::Transforms::*
81 modules, by default. And alternate location can be selected
82 with the "plugins_tree" argument, and plugin modules in the
83 tree can be selectively ignored if named in the "plugin_exceptions"
84 array.
85  
86 As of this writing, the only standard supported transform method
87 is "sequential".
88  
89  
90 =head2 METHODS
91  
92 =over
93  
94 =cut
95  
96 2 ▶use 5.8.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
97 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
98 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
99 2 my $DEBUG = 0;
100 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
101 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
102 2 ▶use Hash::Util qw( unlock_keys lock_keys );
Subroutine BEGIN: called CC=1 SCAR=0.0
103  
104 2 our $VERSION = '0.01';
105  
106 =item new
107  
108 Instantiates a new List::Filter::Transform object.
109 Inherits from L<List::Filter>.
110  
111 =cut
112  
113 =item init
114  
115 Initialize object attributes and then lock them down to prevent
116 accidental creation of new ones.
117  
118 =cut
119  
120 6 ▶sub init {
Subroutine init: called CC=9 SCAR=22.8
Pod documented
121 6 my $self = shift;
122 6 my $args = shift;
123 6 unlock_keys( %{ $self } );
124  
125 # make sure the dispatcher is generated for Transforms, not Filters.
126 6 my $class = __PACKAGE__;
127 6 ▶ $args->{ plugin_root } ||= $class . 's';
Condition50%1/2
$args->{"plugin_root"} ||= $class . 's'
l!l
06
MC/DC0%0/1
$args->{"plugin_root"} ||= $class . 's'
$args->{"plugin_root"}
Truth table50%1/2
A
A= $args->{"plugin_root"}
Aresult
11
00
128  
129 # $self->$parent::init( $args );
130 6 $self->SUPER::init( $args );
131  
132 my $attributes =
133 {
134 name => $args->{ name } || $self->{ name },
135 method => $args->{ method } || $self->{ method } || 'sequential',
136 description => $args->{ description } || $self->{ description },
137 terms => $args->{ terms } || $self->{ terms },
138 modifiers => $args->{ modifiers } || $self->{ modifiers },
139 dispatcher => $args->{ dispatcher } || $self->{ dispatcher },
140 6 ▶ };
Condition65%13/20
$args->{'name'} || $self->{'name'}
l!l&&r!l&&!r
501
$args->{'method'} || $self->{'method'} || 'sequential'
l!l
51
$args->{"method"} or $self->{"method"}
l!l&&r!l&&!r
501
$args->{'description'} || $self->{'description'}
l!l&&r!l&&!r
501
$args->{'terms'} || $self->{'terms'}
l!l&&r!l&&!r
501
$args->{'modifiers'} || $self->{'modifiers'}
l!l&&r!l&&!r
501
$args->{'dispatcher'} || $self->{'dispatcher'}
l!l&&r!l&&!r
060
MC/DC50%1/2
$args->{'name'} || $self->{'name'}
$args->{'name'} $self->{'name'}
MC/DC50%1/2
$args->{'method'} || $self->{'method'} || 'sequential'
$args->{"method"} $self->{"method"}
MC/DC50%1/2
$args->{'description'} || $self->{'description'}
$args->{'description'} $self->{'description'}
MC/DC50%1/2
$args->{'terms'} || $self->{'terms'}
$args->{'terms'} $self->{'terms'}
MC/DC50%1/2
$args->{'modifiers'} || $self->{'modifiers'}
$args->{'modifiers'} $self->{'modifiers'}
MC/DC0%0/2
$args->{'dispatcher'} || $self->{'dispatcher'}
$args->{'dispatcher'} $self->{'dispatcher'}
Truth table66%2/3
A || B
A= $args->{'name'}B= $self->{'name'}
ABresult
1X1
011
000
Truth table66%2/3
A or B
A= $args->{"method"}B= $self->{"method"}
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $args->{'description'}B= $self->{'description'}
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $args->{'terms'}B= $self->{'terms'}
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $args->{'modifiers'}B= $self->{'modifiers'}
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $args->{'dispatcher'}B= $self->{'dispatcher'}
ABresult
1X1
011
000
141  
142 # add attributes to object
143 6 my @fields = (keys %{ $attributes });
144 6 @{ $self }{ @fields } = @{ $attributes }{ @fields }; # hash slice
145  
146 6 lock_keys( %{ $self } );
147 6 return $self;
148 }
149  
150 =back
151  
152 =head2 basic setters and getters
153  
154 Note: these accessors are all inherited from L<List::Filter>
155  
156 =over
157  
158 =item name
159  
160 Getter for object attribute name
161  
162 =item set_name
163  
164 Setter for object attribute set_name
165  
166 =item method
167  
168 Getter for object attribute method
169  
170 =item set_method
171  
172 Setter for object attribute set_method
173  
174 =item description
175  
176 Getter for object attribute description
177  
178 =item set_description
179  
180 Setter for object attribute set_description
181  
182 =item terms
183  
184 Getter for object attribute terms
185  
186 =item set_terms
187  
188 Setter for object attribute set_terms
189  
190 =item modifiers
191  
192 Getter for object attribute modifiers
193  
194 =item set_modifiers
195  
196 Setter for object attribute set_modifiers
197  
198 =item dispatcher
199  
200 Getter for object attribute dispatcher
201  
202 =item set_dispatcher
203  
204 Setter for object attribute set_dispatcher
205  
206 =cut
207  
208 2 1;
209  
210 =head1 SEE ALSO
211  
212 L<List::Filter>
213 L<List::Filter::Project>
214  
215 =head1 AUTHOR
216  
217 Joseph Brenner, E<lt>doom@kzsu.stanford.eduE<gt>
218  
219 =head1 COPYRIGHT AND LICENSE
220  
221 Copyright (C) 2007 by Joseph Brenner
222  
223 This library is free software; you can redistribute it and/or modify
224 it under the same terms as Perl itself, either Perl version 5.8.2 or,
225 at your option, any later version of Perl 5 you may have available.
226  
227 =head1 BUGS
228  
229 None reported... yet.
230  
231 =cut
« Filter/Transform/Internal.pm ↑ Summary Filter/Storage/DBI.pm »