line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Pipeline::Action::StringReplace; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1618
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
with 'Data::Pipeline::Action'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has replace => ( |
7
|
|
|
|
|
|
|
isa => 'HashRef', |
8
|
|
|
|
|
|
|
is => 'rw', |
9
|
|
|
|
|
|
|
default => sub { +{ } }, |
10
|
|
|
|
|
|
|
lazy => 1, |
11
|
|
|
|
|
|
|
trigger => sub { |
12
|
|
|
|
|
|
|
my $self = shift; |
13
|
|
|
|
|
|
|
$self -> _tr( $self -> _build_tr ); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has _tr => ( isa => 'ArrayRef', is => 'rw' ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub BUILD { |
20
|
|
|
|
|
|
|
my $self = shift; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$self -> _tr( $self -> _build_tr ); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _build_tr { |
26
|
|
|
|
|
|
|
my($self) = @_; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my($left, $right); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my @keys = sort keys %{$self -> replace}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$left = join('', @keys); |
33
|
|
|
|
|
|
|
$right = join('', @{$self -> replace}{@keys}); |
34
|
|
|
|
|
|
|
return [ $left, $right ]; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub map_item { |
38
|
|
|
|
|
|
|
my($self, $i) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my($left, $right) = @{$self -> _tr}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
eval "\$i =~ tr/$left/$right/"; |
43
|
|
|
|
|
|
|
$i; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |