Filter/Transforms/Standard.pm

filter: Statementstmt 65.0% 26 / 40 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 68.7% 33 / 48 CC 3 SCAR 12.1
CC
3
Cov
65%
sequential
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.3
« Filter/Storage/DBI.pm ↑ Summary Filter/Storage.pm »
1 package List::Filter::Transforms::Standard;
2  
3 =head1 NAME
4  
5 List::Filter::Transforms::Standard - standard List::Filter transform methods
6  
7 =head1 SYNOPSIS
8  
9 # This module is not intended to be used directly
10 # See: L<List::Filter::Dispatcher>
11  
12 =head1 DESCRIPTION
13  
14 This module defines the standard List::Filter transform methods,
15 such as "sequential", which simply performs in order each
16 find-and-replace specified inside the transform.
17  
18 This is the "transform" analog of L<List::Filter::Filters::Standard>.
19  
20 =head2 METHODS
21  
22 =over
23  
24 =cut
25  
26 2 ▶use 5.8.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 my $DEBUG = 0;
30 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 2 our $VERSION = '0.01';
34  
35 2 require Exporter;
36 2 our @ISA = qw(Exporter);
37 2 our %EXPORT_TAGS = ( 'all' => [ qw(
38 ) ] );
39 2 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
40 2 our @EXPORT = qw(
41 sequential
42 );
43  
44 =item new
45  
46 Instantiates a new List::Filter::Transform::Internal object.
47  
48 Takes an optional hashref as an argument, with named fields
49 identical to the names of the object attributes.
50  
51 With no arguments, the newly created transform will be empty.
52  
53 =cut
54  
55 # Note:
56 # This "new" is inherited from Class::Base
57 # It calls the "init" routine automatically.
58  
59 =item init
60  
61 Initialize object attributes and then lock them down to prevent
62 accidental creation of new ones.
63  
64 Note: there is no leading underscore on name "init", though it's
65 arguably an "internal" routine (i.e. not likely to be of use to
66 client code).
67  
68 =cut
69  
70 # init is inherited also, though oddly enough it comes
71 # from the Dispatcher -- because in the present plugin architecture,
72 # the following methods are exported to the Dispatcher object (via Exporter).
73  
74 =back
75  
76 =head2 List::Filter transform methods
77  
78 The methods that apply a list of transforms. Each List::Filter
79 transfrom specifies one of these methods to use by default.
80  
81 They all have identical interfaces: they take two input
82 arguments, a List::Filter transform and a reference to a list of
83 strings to be modified. These methods all return an array
84 reference of strings that have been modified by the transform method.
85  
86 =over
87  
88  
89 =item sequential
90  
91 Inputs:
92 (1) a List::Filter::Transform object
93 (which contains a list of substitutions to be performed)
94 (2) an arrayref of strings to be transformed
95 (3) an options hash reference:
96  
97 Supported option(s):
98 override_modifiers
99  
100 Return: an arrayref of the modified strings.
101  
102 Note: invalid regular expression modifiers are silently ignored.
103  
104 =cut
105  
106 0 ▶sub sequential {
Subroutine sequential: not called CC=3 SCAR=20.8
Pod documented
107 0 my $self = shift; # Note: this will be the *dispatcher* object
108 0 my $transform = shift;
109 0 my $items = shift;
110 0 my $opt = shift;
111  
112 # making a working copy of the items
113 0 my @work = @{ $items };
114  
115 2 ▶ use List::Filter::Transform::Internal;
Subroutine BEGIN: called CC=1 SCAR=0.0
116 my $lftu = List::Filter::Transform::Internal->new(
117 override_modifiers => $opt->{ override_modifiers },
118 0 );
119  
120 # accumulate changes in @work from each s/// of the transform, on
121 # each given item (through the magic of perl aliases)
122 0 foreach my $item (@work) {
123  
124 # Munge the pieces in the array of transform terms to build up a s///
125 0 my $global_mods = $opt->{ override_modifiers };
126 0 my $terms = $transform->terms;
127 0 foreach my $term (@{ $terms }) {
128  
129 0 $item = $lftu->substitute( $item, $term ); # method of a utility object, $lftu
130  
131 } # end foreach $term
132 } # end foreach $item
133  
134 # return array of transformed strings
135 0 return \@work;
136 } # end sub sequential
137  
138 2 1;
139  
140 =back
141  
142 =head1 MOTIVATION
143  
144 The motivation for this module's existence is simple parallelism: this
145 is the "transform" analog of L<List::Filter::Filters::Standard>. The
146 case is perhaps not as strong for the existance of this module, since
147 the "sequential" method is all that's really likely to be needed, but
148 one of the goals of this project is "pathological extensibility",
149 so I've tried to hold the door open to the possibility that there's
150 a reason for something besides "sequential" application of a transform.
151  
152 =head1 SEE ALSO
153  
154 L<List::Filter>
155  
156 =head1 TODO
157  
158 Write additional methods:
159  
160 =over
161  
162 =item reverse
163  
164 like sequential, but in reverse order
165  
166 =item shuffle
167  
168 apply in random order
169  
170 =item length_sorted
171  
172 apply regexps in order of length of the regexp
173 (doing it in order of length of matches would be better, but more
174 difficult).
175  
176 =item no_chained_changes
177  
178 like sequential, but verifies that later matches don't match
179 something in the replace field of an earlier substitution. That
180 often (though not always) indicates a bug
181  
182 =back
183  
184 =head1 AUTHOR
185  
186 Joseph Brenner, E<lt>doom@kzsu.stanford.eduE<gt>
187  
188 =head1 COPYRIGHT AND LICENSE
189  
190 Copyright (C) 2007 by Joseph Brenner
191  
192 This library is free software; you can redistribute it and/or modify
193 it under the same terms as Perl itself, either Perl version 5.8.2 or,
194 at your option, any later version of Perl 5 you may have available.
195  
196 =head1 BUGS
197  
198 None reported... yet.
199  
200 =cut
« Filter/Storage/DBI.pm ↑ Summary Filter/Storage.pm »