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