File Coverage

blib/lib/Locale/Maketext/Utils/Phrase/Norm/Ampersand.pm
Criterion Covered Total %
statement 24 24 100.0
branch 8 8 100.0
condition 2 3 66.6
subroutine 3 3 100.0
pod 0 1 0.0
total 37 39 94.8


line stmt bran cond sub pod time code
1             package Locale::Maketext::Utils::Phrase::Norm::Ampersand;
2              
3 4     4   1751 use strict;
  4         4  
  4         89  
4 4     4   22 use warnings;
  4         2  
  4         731  
5              
6             sub normalize_maketext_string {
7 74     74 0 69 my ($filter) = @_;
8              
9 74         122 my $string_sr = $filter->get_string_sr();
10              
11 74 100       63 if ( ${$string_sr} =~ s{\[output,chr,(?:\&|38)\]}{[output,amp]}g ) {
  74         188  
12 8         17 $filter->add_violation('Prefer [output,amp] over [output,chr,&] or [output,chr,38].');
13             }
14 74 100       56 if ( ${$string_sr} =~ s{chr\(&\)}{chr\(38\)}g ) {
  74         155  
15 8         14 $filter->add_violation('Prefer chr(38) over chr(&).');
16             }
17              
18 74 100       59 if ( ${$string_sr} =~ s{&}{[output,amp]}g ) {
  74         133  
19 8         16 $filter->add_violation('Ampersands need done via [output,amp].');
20             }
21              
22 74         47 my $aft = ${$string_sr} =~ s/\[output,amp\]([^ ])/[output,amp] $1/g;
  74         126  
23 74         54 my $bef = ${$string_sr} =~ s/([^ ])\[output,amp\]/$1 [output,amp]/g;
  74         131  
24 74 100 66     240 if ( $bef || $aft ) {
25 8         13 $filter->add_violation('Ampersand should have one space before and/or after unless it is embedded in an asis().');
26             }
27              
28 74         125 return $filter->return_value;
29             }
30              
31             1;
32              
33             __END__