File Coverage

blib/lib/XML/Liberal/Remedy/LowAsciiChars.pm
Criterion Covered Total %
statement 3 9 33.3
branch 0 4 0.0
condition n/a
subroutine 1 2 50.0
pod 0 1 0.0
total 4 16 25.0


line stmt bran cond sub pod time code
1             package XML::Liberal::Remedy::LowAsciiChars;
2 2     2   1039 use strict;
  2         2  
  2         441  
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 0     0 0   my $class = shift;
17 0           my($driver, $error, $xml_ref) = @_;
18              
19 0 0         return 0 if $error->message !~
20             /^parser error : xmlParseCharRef: invalid xmlChar value $dec_rx\b/;
21              
22 0 0         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;