File Coverage

blib/lib/XML/Filter/ExceptionLocator.pm
Criterion Covered Total %
statement 33 41 80.4
branch 4 10 40.0
condition 3 11 27.2
subroutine 8 8 100.0
pod 1 1 100.0
total 49 71 69.0


line stmt bran cond sub pod time code
1             package XML::Filter::ExceptionLocator;
2 2     2   44206 use 5.006;
  2         8  
  2         137  
3 2     2   11 use strict;
  2         3  
  2         69  
4 2     2   22 use warnings;
  2         8  
  2         91  
5             our $VERSION = '1.01';
6              
7 2     2   11 use base 'XML::SAX::Base';
  2         3  
  2         2972  
8              
9             # from XML::Filter::XInclude
10             sub set_document_locator {
11 1     1 1 87764 my ($self, $locator) = @_;
12 1   50     3 push @{$self->{locators} ||= []}, $locator;
  1         11  
13            
14 1         96 $self->SUPER::set_document_locator($locator);
15             }
16              
17             # install handler for all SAX methods
18             BEGIN {
19 2     2   6 for my $method (qw(start_document end_document start_element
20             end_element processing_instruction comment
21             skipped_entity ignorable_whitespace end_entity
22             start_entity entity_reference
23             s tart_cdata end_cdata)) {
24 2     2   58109 no strict 'refs';
  2         5  
  2         433  
25 28         50 my $super_meth = "SUPER::$method";
26 28         201 *{__PACKAGE__ . "::$method"} =
27             sub {
28 4     4   3479 my $self = shift;
29              
30             # call method in expected context
31 4         7 my $wantarray = wantarray;
32 4         7 my (@ret, $ret);
33 4 50       9 if ($wantarray) {
34 0         0 eval { @ret = $self->$super_meth(@_); };
  0         0  
35             } else {
36 4         7 eval { $ret = $self->$super_meth(@_); };
  4         61  
37             }
38              
39             # handle errors
40 4         106 my $err = $@;
41 4 50 33     22 if ($err and ref($err) and $err->isa('XML::SAX::Exception')) {
    50 33        
42             # it's showtime, add in Line/Col
43 0 0 0     0 if ($self->{locators} and @{$self->{locators}}) {
  0         0  
44 0         0 $err->{LineNumber} = $self->{locators}[-1]->{LineNumber};
45 0         0 $err->{ColumnNumber} = $self->{locators}[-1]->{ColumnNumber};
46             }
47 0         0 die $err;
48             } elsif ($err) {
49 0         0 die $err;
50             }
51              
52 4 50       12 return @ret if $wantarray;
53 4         19 return $ret;
54             }
55 28         122 }
56             }
57              
58             1;
59             __END__