line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Snippet::TabStop::WithTransformer; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
8
|
|
|
8
|
|
195
|
$Text::Snippet::TabStop::WithTransformer::VERSION = '0.04'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Tab stop that modifies the replacement value supplied by the user |
7
|
|
|
|
|
|
|
|
8
|
8
|
|
|
8
|
|
46
|
use strict; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
247
|
|
9
|
8
|
|
|
8
|
|
42
|
use warnings; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
232
|
|
10
|
8
|
|
|
8
|
|
40
|
use base qw(Text::Snippet::TabStop); |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
661
|
|
11
|
8
|
|
|
8
|
|
47
|
use Carp qw(croak); |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
718
|
|
12
|
8
|
|
|
8
|
|
44
|
use Class::XSAccessor getters => { transformer => 'transformer' }; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
105
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub to_string { |
16
|
5
|
|
|
5
|
1
|
6
|
my $self = shift; |
17
|
5
|
|
|
|
|
19
|
my $output = $self->SUPER::to_string; |
18
|
5
|
|
|
|
|
15
|
return $self->transformer->($output); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
sub parse { |
21
|
6
|
|
|
6
|
1
|
8
|
my $class = shift; |
22
|
6
|
|
|
|
|
8
|
my $src = shift; |
23
|
6
|
50
|
|
|
|
33
|
if ( $src =~ m{^\$\{(\d+)/([^/]+?)/([^/]*)/(.*?)\}$} ) { |
24
|
6
|
|
|
|
|
28
|
my ( $tab_index, $search, $replace, $flags ) = ( $1, $2, $3, $4 ); |
25
|
6
|
|
|
|
|
11
|
$replace =~ s/\$0/\$&/g; |
26
|
6
|
50
|
|
|
|
17
|
if ( length($flags) ) { |
27
|
0
|
|
|
|
|
0
|
$search = "(?$flags$search)"; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
my $transformer = sub { |
30
|
5
|
|
|
5
|
|
6
|
my $out = shift; |
31
|
5
|
50
|
|
|
|
44
|
if ( $out =~ m/$search/ ) { |
32
|
5
|
|
|
|
|
334
|
eval "\$out =~ s{\$search}{$replace}g"; |
33
|
5
|
50
|
|
|
|
20
|
die $@ if($@); |
34
|
|
|
|
|
|
|
} |
35
|
5
|
|
|
|
|
22
|
return $out; |
36
|
6
|
|
|
|
|
25
|
}; |
37
|
6
|
|
|
|
|
30
|
return $class->_new( src => $src, index => $tab_index, transformer => $transformer ); |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
__END__ |