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