line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package List::Filter::Transform; |
2
|
2
|
|
|
2
|
|
43596
|
use base qw( List::Filter ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
642
|
|
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), |
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
|
|
|
2
|
|
31
|
use 5.8.0; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
79
|
|
97
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
52
|
|
98
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
59
|
|
99
|
|
|
|
|
|
|
my $DEBUG = 0; |
100
|
2
|
|
|
2
|
|
11
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
147
|
|
101
|
2
|
|
|
2
|
|
11
|
use Data::Dumper; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
95
|
|
102
|
2
|
|
|
2
|
|
11
|
use Hash::Util qw( unlock_keys lock_keys ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
18
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item new |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Instantiates a new List::Filter::Transform object. |
109
|
|
|
|
|
|
|
Inherits from L. |
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
|
|
|
|
|
|
|
sub init { |
121
|
6
|
|
|
6
|
1
|
8105
|
my $self = shift; |
122
|
6
|
|
|
|
|
14
|
my $args = shift; |
123
|
6
|
|
|
|
|
15
|
unlock_keys( %{ $self } ); |
|
6
|
|
|
|
|
50
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# make sure the dispatcher is generated for Transforms, not Filters. |
126
|
6
|
|
|
|
|
59
|
my $class = __PACKAGE__; |
127
|
6
|
|
33
|
|
|
66
|
$args->{ plugin_root } ||= $class . 's'; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# $self->$parent::init( $args ); |
130
|
6
|
|
|
|
|
50
|
$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
|
|
66
|
|
|
157
|
}; |
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# add attributes to object |
143
|
6
|
|
|
|
|
13
|
my @fields = (keys %{ $attributes }); |
|
6
|
|
|
|
|
27
|
|
144
|
6
|
|
|
|
|
13
|
@{ $self }{ @fields } = @{ $attributes }{ @fields }; # hash slice |
|
6
|
|
|
|
|
23
|
|
|
6
|
|
|
|
|
17
|
|
145
|
|
|
|
|
|
|
|
146
|
6
|
|
|
|
|
14
|
lock_keys( %{ $self } ); |
|
6
|
|
|
|
|
22
|
|
147
|
6
|
|
|
|
|
82
|
return $self; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=back |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 basic setters and getters |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Note: these accessors are all inherited from L |
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
|
|
|
|
|
|
|
1; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 SEE ALSO |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
L |
213
|
|
|
|
|
|
|
L |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 AUTHOR |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Joseph Brenner, Edoom@kzsu.stanford.eduE |
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 |