Filename | /usr/share/perl5/XML/SAX/Exception.pm |
Statements | Executed 18 statements in 897µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 33µs | 43µs | BEGIN@3 | XML::SAX::Exception::
1 | 1 | 1 | 29µs | 113µs | BEGIN@5 | XML::SAX::Exception::
1 | 1 | 1 | 17µs | 95µs | BEGIN@10 | XML::SAX::Exception::
1 | 1 | 1 | 17µs | 83µs | BEGIN@8 | XML::SAX::Exception::
0 | 0 | 0 | 0s | 0s | new | XML::SAX::Exception::
0 | 0 | 0 | 0s | 0s | stackstring | XML::SAX::Exception::
0 | 0 | 0 | 0s | 0s | stacktrace | XML::SAX::Exception::
0 | 0 | 0 | 0s | 0s | stringify | XML::SAX::Exception::
0 | 0 | 0 | 0s | 0s | throw | XML::SAX::Exception::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package XML::SAX::Exception; | ||||
2 | |||||
3 | 3 | 63µs | 2 | 52µs | # spent 43µs (33+10) within XML::SAX::Exception::BEGIN@3 which was called:
# once (33µs+10µs) by XML::LibXML::_SAXParser::BEGIN@1933 at line 3 # spent 43µs making 1 call to XML::SAX::Exception::BEGIN@3
# spent 10µs making 1 call to strict::import |
4 | |||||
5 | 1 | 19µs | 1 | 85µs | # spent 113µs (29+85) within XML::SAX::Exception::BEGIN@5 which was called:
# once (29µs+85µs) by XML::LibXML::_SAXParser::BEGIN@1933 at line 6 # spent 85µs making 1 call to overload::import |
6 | 2 | 48µs | 1 | 113µs | 'fallback' => 1; # spent 113µs making 1 call to XML::SAX::Exception::BEGIN@5 |
7 | |||||
8 | 3 | 59µs | 2 | 149µs | # spent 83µs (17+66) within XML::SAX::Exception::BEGIN@8 which was called:
# once (17µs+66µs) by XML::LibXML::_SAXParser::BEGIN@1933 at line 8 # spent 83µs making 1 call to XML::SAX::Exception::BEGIN@8
# spent 66µs making 1 call to vars::import |
9 | 1 | 1µs | $VERSION = '1.01'; | ||
10 | 3 | 614µs | 2 | 173µs | # spent 95µs (17+78) within XML::SAX::Exception::BEGIN@10 which was called:
# once (17µs+78µs) by XML::LibXML::_SAXParser::BEGIN@1933 at line 10 # spent 95µs making 1 call to XML::SAX::Exception::BEGIN@10
# spent 78µs making 1 call to Exporter::import |
11 | |||||
12 | 1 | 2µs | $StackTrace = $ENV{XML_DEBUG} || 0; | ||
13 | |||||
14 | # Other exception classes: | ||||
15 | |||||
16 | 1 | 24µs | @XML::SAX::Exception::NotRecognized::ISA = ('XML::SAX::Exception'); | ||
17 | 1 | 14µs | @XML::SAX::Exception::NotSupported::ISA = ('XML::SAX::Exception'); | ||
18 | 1 | 8µs | @XML::SAX::Exception::Parse::ISA = ('XML::SAX::Exception'); | ||
19 | |||||
20 | |||||
21 | sub throw { | ||||
22 | my $class = shift; | ||||
23 | if (ref($class)) { | ||||
24 | die $class; | ||||
25 | } | ||||
26 | die $class->new(@_); | ||||
27 | } | ||||
28 | |||||
29 | sub new { | ||||
30 | my $class = shift; | ||||
31 | my %opts = @_; | ||||
32 | confess "Invalid options: " . join(', ', keys %opts) unless exists $opts{Message}; | ||||
33 | |||||
34 | bless { ($StackTrace ? (StackTrace => stacktrace()) : ()), %opts }, | ||||
35 | $class; | ||||
36 | } | ||||
37 | |||||
38 | sub stringify { | ||||
39 | my $self = shift; | ||||
40 | local $^W; | ||||
41 | my $error; | ||||
42 | if (exists $self->{LineNumber}) { | ||||
43 | $error = $self->{Message} . " [Ln: " . $self->{LineNumber} . | ||||
44 | ", Col: " . $self->{ColumnNumber} . "]"; | ||||
45 | } | ||||
46 | else { | ||||
47 | $error = $self->{Message}; | ||||
48 | } | ||||
49 | if ($StackTrace) { | ||||
50 | $error .= stackstring($self->{StackTrace}); | ||||
51 | } | ||||
52 | $error .= "\n"; | ||||
53 | return $error; | ||||
54 | } | ||||
55 | |||||
56 | sub stacktrace { | ||||
57 | my $i = 2; | ||||
58 | my @fulltrace; | ||||
59 | while (my @trace = caller($i++)) { | ||||
60 | my %hash; | ||||
61 | @hash{qw(Package Filename Line)} = @trace[0..2]; | ||||
62 | push @fulltrace, \%hash; | ||||
63 | } | ||||
64 | return \@fulltrace; | ||||
65 | } | ||||
66 | |||||
67 | sub stackstring { | ||||
68 | my $stacktrace = shift; | ||||
69 | my $string = "\nFrom:\n"; | ||||
70 | foreach my $current (@$stacktrace) { | ||||
71 | $string .= $current->{Filename} . " Line: " . $current->{Line} . "\n"; | ||||
72 | } | ||||
73 | return $string; | ||||
74 | } | ||||
75 | |||||
76 | 1 | 46µs | 1; | ||
77 | |||||
78 | __END__ |