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   5763 use strict;
  4         12  
  4         138  
4 4     4   44 use warnings;
  4         7  
  4         1648  
5              
6             sub normalize_maketext_string {
7 74     74 0 140 my ($filter) = @_;
8              
9 74         222 my $string_sr = $filter->get_string_sr();
10              
11 74 100       106 if ( ${$string_sr} =~ s{\[output,chr,(?:\&|38)\]}{[output,amp]}g ) {
  74         349  
12 8         33 $filter->add_violation('Prefer [output,amp] over [output,chr,&] or [output,chr,38].');
13             }
14 74 100       127 if ( ${$string_sr} =~ s{chr\(&\)}{chr\(38\)}g ) {
  74         283  
15 8         27 $filter->add_violation('Prefer chr(38) over chr(&).');
16             }
17              
18 74 100       107 if ( ${$string_sr} =~ s{&}{[output,amp]}g ) {
  74         251  
19 8         26 $filter->add_violation('Ampersands need done via [output,amp].');
20             }
21              
22 74         94 my $aft = ${$string_sr} =~ s/\[output,amp\]([^ ])/[output,amp] $1/g;
  74         281  
23 74         126 my $bef = ${$string_sr} =~ s/([^ ])\[output,amp\]/$1 [output,amp]/g;
  74         226  
24 74 100 66     505 if ( $bef || $aft ) {
25 8         26 $filter->add_violation('Ampersand should have one space before and/or after unless it is embedded in an asis().');
26             }
27              
28 74         248 return $filter->return_value;
29             }
30              
31             1;
32              
33             __END__