Snippet/TabStop/WithTransformer.pm

filter: Statementstmt 94.2% 33 / 35 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 88.8% 48 / 54 CC 5 SCAR 6.8
CC
5
Cov
86%
parse
3.2
__ANON__
3.1
BEGIN
1.0
CRAP 2.0
« Snippet/TabStop/Parser.pm ↑ Summary Snippet/TabStop/Basic.pm »
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
BranchTrueFalseTotal
if ($src =~ m[^\$\{(\d+)/([^/]+?)/([^/]*)/(.*?)\}$]) 6 0 6
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
BranchTrueFalseTotal
if (length $flags) 0 6 6
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
BranchTrueFalseTotal
if ($out =~ /$search/) 5 0 5
32 5 eval "\$out =~ s{\$search}{$replace}g";
33 5 ▶ die $@ if($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 5 5
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__
« Snippet/TabStop/Parser.pm ↑ Summary Snippet/TabStop/Basic.pm »