| Filename | /home/hejohns/perl5/lib/perl5/Data/Printer/Filter/CODE.pm |
| Statements | Executed 14 statements in 300µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 7µs | 8µs | Data::Printer::Filter::CODE::BEGIN@2 |
| 1 | 1 | 1 | 5µs | 5µs | Data::Printer::Filter::CODE::BEGIN@5 |
| 1 | 1 | 1 | 5µs | 133µs | Data::Printer::Filter::CODE::BEGIN@7 |
| 1 | 1 | 1 | 4µs | 14µs | Data::Printer::Filter::CODE::BEGIN@3 |
| 1 | 1 | 1 | 3µs | 12µs | Data::Printer::Filter::CODE::BEGIN@4 |
| 1 | 1 | 1 | 1µs | 1µs | Data::Printer::Filter::CODE::BEGIN@6 |
| 1 | 1 | 1 | 200ns | 200ns | Data::Printer::Filter::CODE::__ANON__ (xsub) |
| 0 | 0 | 0 | 0s | 0s | Data::Printer::Filter::CODE::_deparse |
| 0 | 0 | 0 | 0s | 0s | Data::Printer::Filter::CODE::_subref_is_reachable |
| 0 | 0 | 0 | 0s | 0s | Data::Printer::Filter::CODE::parse |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Data::Printer::Filter::CODE; | ||||
| 2 | 2 | 15µs | 2 | 10µs | # spent 8µs (7+1) within Data::Printer::Filter::CODE::BEGIN@2 which was called:
# once (7µs+1µs) by Data::Printer::Object::BEGIN@60 at line 2 # spent 8µs making 1 call to Data::Printer::Filter::CODE::BEGIN@2
# spent 1µs making 1 call to strict::import |
| 3 | 2 | 12µs | 2 | 25µs | # spent 14µs (4+11) within Data::Printer::Filter::CODE::BEGIN@3 which was called:
# once (4µs+11µs) by Data::Printer::Object::BEGIN@60 at line 3 # spent 14µs making 1 call to Data::Printer::Filter::CODE::BEGIN@3
# spent 11µs making 1 call to warnings::import |
| 4 | 2 | 14µs | 2 | 21µs | # spent 12µs (3+9) within Data::Printer::Filter::CODE::BEGIN@4 which was called:
# once (3µs+9µs) by Data::Printer::Object::BEGIN@60 at line 4 # spent 12µs making 1 call to Data::Printer::Filter::CODE::BEGIN@4
# spent 9µs making 1 call to Data::Printer::Filter::import |
| 5 | 2 | 14µs | 2 | 6µs | # spent 5µs (5+200ns) within Data::Printer::Filter::CODE::BEGIN@5 which was called:
# once (5µs+200ns) by Data::Printer::Object::BEGIN@60 at line 5 # spent 5µs making 1 call to Data::Printer::Filter::CODE::BEGIN@5
# spent 200ns making 1 call to Data::Printer::Filter::CODE::__ANON__ |
| 6 | 2 | 12µs | 1 | 1µs | # spent 1µs within Data::Printer::Filter::CODE::BEGIN@6 which was called:
# once (1µs+0s) by Data::Printer::Object::BEGIN@60 at line 6 # spent 1µs making 1 call to Data::Printer::Filter::CODE::BEGIN@6 |
| 7 | 2 | 230µs | 2 | 262µs | # spent 133µs (5+129) within Data::Printer::Filter::CODE::BEGIN@7 which was called:
# once (5µs+129µs) by Data::Printer::Object::BEGIN@60 at line 7 # spent 133µs making 1 call to Data::Printer::Filter::CODE::BEGIN@7
# spent 129µs making 1 call to Exporter::import |
| 8 | |||||
| 9 | 1 | 1µs | 1 | 14µs | filter 'CODE' => \&parse; # spent 14µs making 1 call to Data::Printer::Filter::__ANON__[Data/Printer/Filter.pm:23] |
| 10 | |||||
| 11 | |||||
| 12 | sub parse { | ||||
| 13 | my ($subref, $ddp) = @_; | ||||
| 14 | my $string; | ||||
| 15 | my $color = 'code'; | ||||
| 16 | if ($ddp->deparse) { | ||||
| 17 | $string = _deparse($subref, $ddp); | ||||
| 18 | if ($ddp->coderef_undefined && $string =~ /\A\s*sub\s*;\s*\z/) { | ||||
| 19 | $string = $ddp->coderef_undefined; | ||||
| 20 | $color = 'undef'; | ||||
| 21 | } | ||||
| 22 | } | ||||
| 23 | elsif ($ddp->coderef_undefined && !_subref_is_reachable($subref)) { | ||||
| 24 | $string = $ddp->coderef_undefined; | ||||
| 25 | $color = 'undef'; | ||||
| 26 | } | ||||
| 27 | else { | ||||
| 28 | $string = $ddp->coderef_stub; | ||||
| 29 | } | ||||
| 30 | return $ddp->maybe_colorize($string, $color); | ||||
| 31 | }; | ||||
| 32 | |||||
| 33 | ####################################### | ||||
| 34 | ### Private auxiliary helpers below ### | ||||
| 35 | ####################################### | ||||
| 36 | |||||
| 37 | sub _deparse { | ||||
| 38 | my ($subref, $ddp) = @_; | ||||
| 39 | require B::Deparse; | ||||
| 40 | |||||
| 41 | # FIXME: line below breaks encapsulation on Data::Printer::Object | ||||
| 42 | my $i = $ddp->{indent} + $ddp->{_array_padding}; | ||||
| 43 | |||||
| 44 | my $deparseopts = ["-sCi${i}v'Useless const omitted'"]; | ||||
| 45 | |||||
| 46 | my $sub = 'sub ' . B::Deparse->new($deparseopts)->coderef2text($subref); | ||||
| 47 | my $pad = $ddp->newline; | ||||
| 48 | $sub =~ s/\n/$pad/gse; | ||||
| 49 | return $sub; | ||||
| 50 | } | ||||
| 51 | |||||
| 52 | sub _subref_is_reachable { | ||||
| 53 | my ($subref) = @_; | ||||
| 54 | require B; | ||||
| 55 | my $cv = B::svref_2object($subref); | ||||
| 56 | return !(B::class($cv->ROOT) eq 'NULL' && !${ $cv->const_sv }); | ||||
| 57 | } | ||||
| 58 | |||||
| 59 | 1 | 2µs | 1; | ||
# spent 200ns within Data::Printer::Filter::CODE::__ANON__ which was called:
# once (200ns+0s) by Data::Printer::Filter::CODE::BEGIN@5 at line 5 |