File Coverage

blib/lib/XML/Liberal/Remedy/LowAsciiChars.pm
Criterion Covered Total %
statement 7 9 77.7
branch 3 4 75.0
condition n/a
subroutine 2 2 100.0
pod 0 1 0.0
total 12 16 75.0


line stmt bran cond sub pod time code
1             package XML::Liberal::Remedy::LowAsciiChars;
2 5     5   2205 use strict;
  5         9  
  5         786  
3              
4             my @low_ascii = (0..8, 11..12, 14..31, 127);
5             my $dec_rx = do {
6             my $pat = join '|', @low_ascii;
7             qr/$pat/;
8             };
9             my $hex_rx = do {
10             my $pat = join '|', map { sprintf '%x', $_ } @low_ascii;
11             qr/$pat/i;
12             };
13              
14             # optimized to fix all errors in one apply() call
15             sub apply {
16 101     101 0 148 my $class = shift;
17 101         191 my($driver, $error, $xml_ref) = @_;
18              
19 101 100       187 return 0 if $error->message !~
20             /^parser error : xmlParseCharRef: invalid xmlChar value $dec_rx\b/;
21              
22 5 50       241 return 1 if $$xml_ref =~ s{&#(?:0*$dec_rx|[xX]0*$hex_rx);}{}g;
23              
24 0           Carp::carp("Can't find low ascii bytes, error was: ", $error->summary);
25 0           return 0;
26             }
27              
28             1;