File Coverage

blib/lib/XML/Handler/PrintEvents.pm
Criterion Covered Total %
statement 9 37 24.3
branch 0 4 0.0
condition n/a
subroutine 3 25 12.0
pod 0 22 0.0
total 12 88 13.6


line stmt bran cond sub pod time code
1             #
2             # This PerlSAX handler prints out all the PerlSAX events/callbacks
3             # it receives. Very useful when debugging.
4             #
5              
6             package XML::Handler::PrintEvents;
7 1     1   7662 use strict;
  1         4  
  1         42  
8 1     1   938 use XML::Filter::SAXT;
  1         1816  
  1         41  
9              
10 1     1   8 use vars qw($VERSION);
  1         9  
  1         296  
11             $VERSION = 0.01;
12              
13             my @EXTRA_HANDLERS = ( 'ignorable_whitespace' );
14              
15             sub new
16             {
17 0     0 0   my ($class, %options) = @_;
18 0           bless \%options, $class;
19             }
20              
21             sub print_event
22             {
23 0     0 0   my ($self, $event_name, $event) = @_;
24              
25 0           printf "%-22s ", $event_name;
26 0 0         if (defined $event)
27             {
28 0 0         print join (", ", map { "$_ => [" .
  0            
29             (defined $event->{$_} ? $event->{$_} : "(undef)")
30             . "]" } keys %$event);
31             }
32 0           print "\n";
33             }
34              
35             #
36             # This generates the PerlSAX handler methods for PrintEvents.
37             # They basically forward the event to print_event() while adding the callback
38             # (event) name.
39             #
40             for my $cb (@EXTRA_HANDLERS, map { @{$_} } values %XML::Filter::SAXT::SAX_HANDLERS)
41             {
42 0     0 0   eval "sub $cb { shift->print_event ('$cb', \@_) }";
  0     0 0    
  0     0 0    
  0     0 0    
  0     0 0    
  0     0 0    
  0     0 0    
  0     0 0    
  0     0 0    
  0     0 0    
  0     0 0    
  0     0 0    
  0     0 0    
  0     0 0    
  0     0 0    
  0     0 0    
  0     0 0    
  0     0 0    
  0     0 0    
  0     0 0    
43             }
44              
45             1; # package return code
46              
47             __END__