| Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/YAML/PP/Render.pm |
| Statements | Executed 29 statements in 608µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 30µs | 32µs | YAML::PP::Parser::BEGIN@2 |
| 1 | 1 | 1 | 16µs | 16µs | YAML::PP::Render::render_block_scalar |
| 1 | 1 | 1 | 6µs | 35µs | YAML::PP::Render::BEGIN@8 |
| 1 | 1 | 1 | 4µs | 28µs | YAML::PP::Parser::BEGIN@3 |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Render::render_multi_val |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Render::render_quoted |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | # ABSTRACT: YAML::PP Rendering functions | ||||
| 2 | 2 | 25µs | 2 | 34µs | # spent 32µs (30+2) within YAML::PP::Parser::BEGIN@2 which was called:
# once (30µs+2µs) by YAML::PP::Parser::BEGIN@17 at line 2 # spent 32µs making 1 call to YAML::PP::Parser::BEGIN@2
# spent 2µs making 1 call to strict::import |
| 3 | 2 | 41µs | 2 | 52µs | # spent 28µs (4+24) within YAML::PP::Parser::BEGIN@3 which was called:
# once (4µs+24µs) by YAML::PP::Parser::BEGIN@17 at line 3 # spent 28µs making 1 call to YAML::PP::Parser::BEGIN@3
# spent 24µs making 1 call to warnings::import |
| 4 | package YAML::PP::Render; | ||||
| 5 | |||||
| 6 | 1 | 1µs | our $VERSION = '0.035'; # VERSION | ||
| 7 | |||||
| 8 | 2 | 521µs | 2 | 64µs | # spent 35µs (6+29) within YAML::PP::Render::BEGIN@8 which was called:
# once (6µs+29µs) by YAML::PP::Parser::BEGIN@17 at line 8 # spent 35µs making 1 call to YAML::PP::Render::BEGIN@8
# spent 29µs making 1 call to constant::import |
| 9 | |||||
| 10 | sub render_quoted { | ||||
| 11 | my ($self, $style, $lines) = @_; | ||||
| 12 | |||||
| 13 | my $quoted = ''; | ||||
| 14 | my $addspace = 0; | ||||
| 15 | |||||
| 16 | for my $i (0 .. $#$lines) { | ||||
| 17 | my $line = $lines->[ $i ]; | ||||
| 18 | my $value = $line->{value}; | ||||
| 19 | my $last = $i == $#$lines; | ||||
| 20 | my $first = $i == 0; | ||||
| 21 | if ($value eq '') { | ||||
| 22 | if ($first) { | ||||
| 23 | $addspace = 1; | ||||
| 24 | } | ||||
| 25 | elsif ($last) { | ||||
| 26 | $quoted .= ' ' if $addspace; | ||||
| 27 | } | ||||
| 28 | else { | ||||
| 29 | $addspace = 0; | ||||
| 30 | $quoted .= "\n"; | ||||
| 31 | } | ||||
| 32 | next; | ||||
| 33 | } | ||||
| 34 | |||||
| 35 | $quoted .= ' ' if $addspace; | ||||
| 36 | $addspace = 1; | ||||
| 37 | if ($style eq '"') { | ||||
| 38 | if ($line->{orig} =~ m/\\$/) { | ||||
| 39 | $line->{value} =~ s/\\$//; | ||||
| 40 | $value =~ s/\\$//; | ||||
| 41 | $addspace = 0; | ||||
| 42 | } | ||||
| 43 | } | ||||
| 44 | $quoted .= $value; | ||||
| 45 | } | ||||
| 46 | return $quoted; | ||||
| 47 | } | ||||
| 48 | |||||
| 49 | # spent 16µs within YAML::PP::Render::render_block_scalar which was called:
# once (16µs+0s) by YAML::PP::Lexer::fetch_block at line 611 of YAML/PP/Lexer.pm | ||||
| 50 | 1 | 1µs | my ($self, $block_type, $chomp, $lines) = @_; | ||
| 51 | |||||
| 52 | 1 | 1µs | my ($folded, $keep, $trim); | ||
| 53 | 1 | 0s | if ($block_type eq '>') { | ||
| 54 | $folded = 1; | ||||
| 55 | } | ||||
| 56 | 1 | 2µs | if ($chomp eq '+') { | ||
| 57 | $keep = 1; | ||||
| 58 | } | ||||
| 59 | elsif ($chomp eq '-') { | ||||
| 60 | $trim = 1; | ||||
| 61 | } | ||||
| 62 | |||||
| 63 | 1 | 1µs | my $string = ''; | ||
| 64 | 1 | 1µs | if (not $keep) { | ||
| 65 | # remove trailing empty lines | ||||
| 66 | 1 | 1µs | while (@$lines) { | ||
| 67 | 1 | 0s | last if $lines->[-1] ne ''; | ||
| 68 | pop @$lines; | ||||
| 69 | } | ||||
| 70 | } | ||||
| 71 | 1 | 1µs | if ($folded) { | ||
| 72 | |||||
| 73 | my $prev = 'START'; | ||||
| 74 | my $trailing = ''; | ||||
| 75 | if ($keep) { | ||||
| 76 | while (@$lines and $lines->[-1] eq '') { | ||||
| 77 | pop @$lines; | ||||
| 78 | $trailing .= "\n"; | ||||
| 79 | } | ||||
| 80 | } | ||||
| 81 | for my $i (0 .. $#$lines) { | ||||
| 82 | my $line = $lines->[ $i ]; | ||||
| 83 | |||||
| 84 | my $type = $line eq '' | ||||
| 85 | ? 'EMPTY' | ||||
| 86 | : $line =~ m/\A[ \t]/ | ||||
| 87 | ? 'MORE' | ||||
| 88 | : 'CONTENT'; | ||||
| 89 | |||||
| 90 | if ($prev eq 'MORE' and $type eq 'EMPTY') { | ||||
| 91 | $type = 'MORE'; | ||||
| 92 | } | ||||
| 93 | elsif ($prev eq 'CONTENT') { | ||||
| 94 | if ($type ne 'CONTENT') { | ||||
| 95 | $string .= "\n"; | ||||
| 96 | } | ||||
| 97 | elsif ($type eq 'CONTENT') { | ||||
| 98 | $string .= ' '; | ||||
| 99 | } | ||||
| 100 | } | ||||
| 101 | elsif ($prev eq 'START' and $type eq 'EMPTY') { | ||||
| 102 | $string .= "\n"; | ||||
| 103 | $type = 'START'; | ||||
| 104 | } | ||||
| 105 | elsif ($prev eq 'EMPTY' and $type ne 'CONTENT') { | ||||
| 106 | $string .= "\n"; | ||||
| 107 | } | ||||
| 108 | |||||
| 109 | $string .= $line; | ||||
| 110 | |||||
| 111 | if ($type eq 'MORE' and $i < $#$lines) { | ||||
| 112 | $string .= "\n"; | ||||
| 113 | } | ||||
| 114 | |||||
| 115 | $prev = $type; | ||||
| 116 | } | ||||
| 117 | if ($keep) { | ||||
| 118 | $string .= $trailing; | ||||
| 119 | } | ||||
| 120 | $string .= "\n" if @$lines and not $trim; | ||||
| 121 | } | ||||
| 122 | else { | ||||
| 123 | 1 | 2µs | for my $i (0 .. $#$lines) { | ||
| 124 | 5 | 2µs | $string .= $lines->[ $i ]; | ||
| 125 | 5 | 2µs | $string .= "\n" if ($i != $#$lines or not $trim); | ||
| 126 | } | ||||
| 127 | } | ||||
| 128 | TRACE and warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$string], ['string']); | ||||
| 129 | 1 | 3µs | return $string; | ||
| 130 | } | ||||
| 131 | |||||
| 132 | sub render_multi_val { | ||||
| 133 | my ($self, $multi) = @_; | ||||
| 134 | my $string = ''; | ||||
| 135 | my $start = 1; | ||||
| 136 | for my $line (@$multi) { | ||||
| 137 | if (not $start) { | ||||
| 138 | if ($line eq '') { | ||||
| 139 | $string .= "\n"; | ||||
| 140 | $start = 1; | ||||
| 141 | } | ||||
| 142 | else { | ||||
| 143 | $string .= " $line"; | ||||
| 144 | } | ||||
| 145 | } | ||||
| 146 | else { | ||||
| 147 | $string .= $line; | ||||
| 148 | $start = 0; | ||||
| 149 | } | ||||
| 150 | } | ||||
| 151 | return $string; | ||||
| 152 | } | ||||
| 153 | |||||
| 154 | |||||
| 155 | 1 | 3µs | 1; |