| Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/YAML/PP/Exception.pm |
| Statements | Executed 8 statements in 446µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 35µs | 39µs | YAML::PP::Parser::BEGIN@1.286 |
| 1 | 1 | 1 | 9µs | 29µs | YAML::PP::Exception::BEGIN@7 |
| 1 | 1 | 1 | 9µs | 47µs | YAML::PP::Parser::BEGIN@2.287 |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Exception::new |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Exception::to_string |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | 2 | 35µs | 2 | 43µs | # spent 39µs (35+4) within YAML::PP::Parser::BEGIN@1.286 which was called:
# once (35µs+4µs) by YAML::PP::Parser::BEGIN@20 at line 1 # spent 39µs making 1 call to YAML::PP::Parser::BEGIN@1.286
# spent 4µs making 1 call to strict::import |
| 2 | 2 | 50µs | 2 | 85µs | # spent 47µs (9+38) within YAML::PP::Parser::BEGIN@2.287 which was called:
# once (9µs+38µs) by YAML::PP::Parser::BEGIN@20 at line 2 # spent 47µs making 1 call to YAML::PP::Parser::BEGIN@2.287
# spent 38µs making 1 call to warnings::import |
| 3 | package YAML::PP::Exception; | ||||
| 4 | |||||
| 5 | 1 | 0s | our $VERSION = '0.035'; # VERSION | ||
| 6 | |||||
| 7 | 2 | 357µs | 2 | 49µs | # spent 29µs (9+20) within YAML::PP::Exception::BEGIN@7 which was called:
# once (9µs+20µs) by YAML::PP::Parser::BEGIN@20 at line 7 # spent 29µs making 1 call to YAML::PP::Exception::BEGIN@7
# spent 20µs making 1 call to overload::import |
| 8 | |||||
| 9 | sub new { | ||||
| 10 | my ($class, %args) = @_; | ||||
| 11 | my $self = bless { | ||||
| 12 | line => $args{line}, | ||||
| 13 | msg => $args{msg}, | ||||
| 14 | next => $args{next}, | ||||
| 15 | where => $args{where}, | ||||
| 16 | yaml => $args{yaml}, | ||||
| 17 | got => $args{got}, | ||||
| 18 | expected => $args{expected}, | ||||
| 19 | column => $args{column}, | ||||
| 20 | }, $class; | ||||
| 21 | return $self; | ||||
| 22 | } | ||||
| 23 | |||||
| 24 | sub to_string { | ||||
| 25 | my ($self) = @_; | ||||
| 26 | my $next = $self->{next}; | ||||
| 27 | my $line = $self->{line}; | ||||
| 28 | my $column = $self->{column}; | ||||
| 29 | |||||
| 30 | my $yaml = ''; | ||||
| 31 | for my $token (@$next) { | ||||
| 32 | last if $token->{name} eq 'EOL'; | ||||
| 33 | $yaml .= $token->{value}; | ||||
| 34 | } | ||||
| 35 | $column = '???' unless defined $column; | ||||
| 36 | |||||
| 37 | my $remaining_yaml = $self->{yaml}; | ||||
| 38 | $remaining_yaml = '' unless defined $remaining_yaml; | ||||
| 39 | $yaml .= $remaining_yaml; | ||||
| 40 | { | ||||
| 41 | local $@; # avoid bug in old Data::Dumper | ||||
| 42 | require Data::Dumper; | ||||
| 43 | local $Data::Dumper::Useqq = 1; | ||||
| 44 | local $Data::Dumper::Terse = 1; | ||||
| 45 | $yaml = Data::Dumper->Dump([$yaml], ['yaml']); | ||||
| 46 | chomp $yaml; | ||||
| 47 | } | ||||
| 48 | |||||
| 49 | my $lines = 5; | ||||
| 50 | my @fields; | ||||
| 51 | |||||
| 52 | if ($self->{got} and $self->{expected}) { | ||||
| 53 | $lines = 6; | ||||
| 54 | $line = $self->{got}->{line}; | ||||
| 55 | $column = $self->{got}->{column} + 1; | ||||
| 56 | @fields = ( | ||||
| 57 | "Line" => $line, | ||||
| 58 | "Column" => $column, | ||||
| 59 | "Expected", join(" ", @{ $self->{expected} }), | ||||
| 60 | "Got", $self->{got}->{name}, | ||||
| 61 | "Where", $self->{where}, | ||||
| 62 | "YAML", $yaml, | ||||
| 63 | ); | ||||
| 64 | } | ||||
| 65 | else { | ||||
| 66 | @fields = ( | ||||
| 67 | "Line" => $line, | ||||
| 68 | "Column" => $column, | ||||
| 69 | "Message", $self->{msg}, | ||||
| 70 | "Where", $self->{where}, | ||||
| 71 | "YAML", $yaml, | ||||
| 72 | ); | ||||
| 73 | } | ||||
| 74 | my $fmt = join "\n", ("%-10s: %s") x $lines; | ||||
| 75 | my $string = sprintf $fmt, @fields; | ||||
| 76 | return $string; | ||||
| 77 | } | ||||
| 78 | |||||
| 79 | 1 | 4µs | 1; |