File Coverage

inc/XML/SAX/Exception.pm
Criterion Covered Total %
statement 12 42 28.5
branch 0 10 0.0
condition n/a
subroutine 4 9 44.4
pod 0 5 0.0
total 16 66 24.2


line stmt bran cond sub pod time code
1             #line 1
2             package XML::SAX::Exception;
3 3     3   17  
  3         3  
  3         128  
4             use strict;
5 3         21  
6 3     3   3113 use overload '""' => "stringify",
  3         1987  
7             'fallback' => 1;
8 3     3   226  
  3         5  
  3         319  
9             use vars qw/$StackTrace $VERSION/;
10 3     3   147 $VERSION = '1.01';
  3         6  
  3         2142  
11             use Carp;
12              
13             $StackTrace = $ENV{XML_DEBUG} || 0;
14              
15             # Other exception classes:
16              
17             @XML::SAX::Exception::NotRecognized::ISA = ('XML::SAX::Exception');
18             @XML::SAX::Exception::NotSupported::ISA = ('XML::SAX::Exception');
19             @XML::SAX::Exception::Parse::ISA = ('XML::SAX::Exception');
20              
21              
22 0     0 0   sub throw {
23 0 0         my $class = shift;
24 0           if (ref($class)) {
25             die $class;
26 0           }
27             die $class->new(@_);
28             }
29              
30 0     0 0   sub new {
31 0           my $class = shift;
32 0 0         my %opts = @_;
33             confess "Invalid options: " . join(', ', keys %opts) unless exists $opts{Message};
34 0 0        
35             bless { ($StackTrace ? (StackTrace => stacktrace()) : ()), %opts },
36             $class;
37             }
38              
39 0     0 0   sub stringify {
40 0           my $self = shift;
41 0           local $^W;
42 0 0         my $error;
43 0           if (exists $self->{LineNumber}) {
44             $error = $self->{Message} . " [Ln: " . $self->{LineNumber} .
45             ", Col: " . $self->{ColumnNumber} . "]";
46             }
47 0           else {
48             $error = $self->{Message};
49 0 0         }
50 0           if ($StackTrace) {
51             $error .= stackstring($self->{StackTrace});
52 0           }
53 0           $error .= "\n";
54             return $error;
55             }
56              
57 0     0 0   sub stacktrace {
58 0           my $i = 2;
59 0           my @fulltrace;
60 0           while (my @trace = caller($i++)) {
61 0           my %hash;
62 0           @hash{qw(Package Filename Line)} = @trace[0..2];
63             push @fulltrace, \%hash;
64 0           }
65             return \@fulltrace;
66             }
67              
68 0     0 0   sub stackstring {
69 0           my $stacktrace = shift;
70 0           my $string = "\nFrom:\n";
71 0           foreach my $current (@$stacktrace) {
72             $string .= $current->{Filename} . " Line: " . $current->{Line} . "\n";
73 0           }
74             return $string;
75             }
76              
77             1;
78              
79             __END__