| Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/YAML/PP.pm |
| Statements | Executed 74 statements in 6.59ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 3.31ms | 6.36ms | YAML::PP::BEGIN@8 |
| 1 | 1 | 1 | 2.37ms | 14.6ms | YAML::PP::BEGIN@11 |
| 1 | 1 | 1 | 1.85ms | 2.31ms | YAML::PP::BEGIN@9 |
| 1 | 1 | 1 | 1.65ms | 46.9ms | YAML::PP::BEGIN@10 |
| 1 | 1 | 1 | 1.65ms | 1.79ms | YAML::PP::Preserve::Array::BEGIN@300 |
| 1 | 1 | 1 | 1.41ms | 1.64ms | YAML::PP::Preserve::Hash::BEGIN@226 |
| 1 | 1 | 1 | 129µs | 3.62ms | YAML::PP::new |
| 1 | 1 | 1 | 38µs | 95µs | main::BEGIN@3.282 |
| 1 | 1 | 1 | 28µs | 31µs | main::BEGIN@2.281 |
| 1 | 1 | 1 | 26µs | 76µs | YAML::PP::Preserve::Array::BEGIN@302 |
| 1 | 1 | 1 | 22µs | 70µs | YAML::PP::Preserve::Scalar::BEGIN@377 |
| 1 | 1 | 1 | 19µs | 54µs | YAML::PP::Preserve::Hash::BEGIN@228 |
| 1 | 1 | 1 | 17µs | 17µs | YAML::PP::_arg_yaml_version |
| 1 | 1 | 1 | 17µs | 17µs | YAML::PP::loader |
| 1 | 1 | 1 | 12µs | 334µs | YAML::PP::Preserve::Array::BEGIN@301 |
| 1 | 1 | 1 | 12µs | 286µs | YAML::PP::Preserve::Hash::BEGIN@227 |
| 1 | 1 | 1 | 11µs | 50µs | YAML::PP::BEGIN@12 |
| 1 | 1 | 1 | 9µs | 6.98s | YAML::PP::load_file |
| 3 | 3 | 1 | 8µs | 8µs | YAML::PP::__ANON__ (xsub) |
| 1 | 1 | 1 | 7µs | 7µs | YAML::PP::Preserve::Array::__ANON__ (xsub) |
| 1 | 1 | 1 | 6µs | 19µs | YAML::PP::BEGIN@13 |
| 1 | 1 | 1 | 6µs | 60µs | YAML::PP::BEGIN@15 |
| 1 | 1 | 1 | 3µs | 3µs | YAML::PP::Preserve::Hash::__ANON__ (xsub) |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Dump |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::DumpFile |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Load |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::LoadFile |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Array::CLEAR |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Array::DELETE |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Array::EXISTS |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Array::EXTEND |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Array::FETCH |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Array::FETCHSIZE |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Array::PUSH |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Array::SHIFT |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Array::SPLICE |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Array::STORE |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Array::STORESIZE |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Array::TIEARRAY |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Array::UNSHIFT |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Array::_preserve |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Hash::CLEAR |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Hash::DELETE |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Hash::EXISTS |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Hash::FETCH |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Hash::FIRSTKEY |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Hash::NEXTKEY |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Hash::SCALAR |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Hash::STORE |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Hash::TIEHASH |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Scalar::alias |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Scalar::new |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Scalar::style |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Scalar::tag |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::Preserve::Scalar::value |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::clone |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::default_schema |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::dump |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::dump_file |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::dump_string |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::dumper |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::load_string |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::preserved_mapping |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::preserved_scalar |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::preserved_sequence |
| 0 | 0 | 0 | 0s | 0s | YAML::PP::schema |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | # ABSTRACT: YAML 1.2 Processor | ||||
| 2 | 2 | 58µs | 2 | 34µs | # spent 31µs (28+3) within main::BEGIN@2.281 which was called:
# once (28µs+3µs) by main::BEGIN@3 at line 2 # spent 31µs making 1 call to main::BEGIN@2.281
# spent 3µs making 1 call to strict::import |
| 3 | 2 | 34µs | 2 | 152µs | # spent 95µs (38+57) within main::BEGIN@3.282 which was called:
# once (38µs+57µs) by main::BEGIN@3 at line 3 # spent 95µs making 1 call to main::BEGIN@3.282
# spent 57µs making 1 call to warnings::import |
| 4 | package YAML::PP; | ||||
| 5 | |||||
| 6 | 1 | 1µs | our $VERSION = '0.035'; # VERSION | ||
| 7 | |||||
| 8 | 2 | 593µs | 2 | 6.36ms | # spent 6.36ms (3.31+3.05) within YAML::PP::BEGIN@8 which was called:
# once (3.31ms+3.05ms) by main::BEGIN@3 at line 8 # spent 6.36ms making 1 call to YAML::PP::BEGIN@8
# spent 2µs making 1 call to YAML::PP::__ANON__ |
| 9 | 2 | 670µs | 2 | 2.33ms | # spent 2.31ms (1.85+452µs) within YAML::PP::BEGIN@9 which was called:
# once (1.85ms+452µs) by main::BEGIN@3 at line 9 # spent 2.31ms making 1 call to YAML::PP::BEGIN@9
# spent 25µs making 1 call to Exporter::import |
| 10 | 2 | 637µs | 2 | 46.9ms | # spent 46.9ms (1.65+45.2) within YAML::PP::BEGIN@10 which was called:
# once (1.65ms+45.2ms) by main::BEGIN@3 at line 10 # spent 46.9ms making 1 call to YAML::PP::BEGIN@10
# spent 3µs making 1 call to YAML::PP::__ANON__ |
| 11 | 2 | 379µs | 2 | 14.6ms | # spent 14.6ms (2.37+12.3) within YAML::PP::BEGIN@11 which was called:
# once (2.37ms+12.3ms) by main::BEGIN@3 at line 11 # spent 14.6ms making 1 call to YAML::PP::BEGIN@11
# spent 3µs making 1 call to YAML::PP::__ANON__ |
| 12 | 2 | 22µs | 2 | 89µs | # spent 50µs (11+39) within YAML::PP::BEGIN@12 which was called:
# once (11µs+39µs) by main::BEGIN@3 at line 12 # spent 50µs making 1 call to YAML::PP::BEGIN@12
# spent 39µs making 1 call to Exporter::import |
| 13 | 2 | 16µs | 2 | 32µs | # spent 19µs (6+13) within YAML::PP::BEGIN@13 which was called:
# once (6µs+13µs) by main::BEGIN@3 at line 13 # spent 19µs making 1 call to YAML::PP::BEGIN@13
# spent 13µs making 1 call to Exporter::import |
| 14 | |||||
| 15 | 2 | 999µs | 2 | 114µs | # spent 60µs (6+54) within YAML::PP::BEGIN@15 which was called:
# once (6µs+54µs) by main::BEGIN@3 at line 15 # spent 60µs making 1 call to YAML::PP::BEGIN@15
# spent 54µs making 1 call to base::import |
| 16 | 1 | 2µs | our @EXPORT_OK = qw/ Load LoadFile Dump DumpFile /; | ||
| 17 | |||||
| 18 | 1 | 2µs | my %YAML_VERSIONS = ('1.1' => 1, '1.2' => 1); | ||
| 19 | |||||
| 20 | |||||
| 21 | # spent 3.62ms (129µs+3.49) within YAML::PP::new which was called:
# once (129µs+3.49ms) by main::RUNTIME at line 6 of /Users/ether/git/fastly/Heavenly/profiling/jsm-0.558-om-0.037/../prof.pl | ||||
| 22 | 1 | 5µs | my ($class, %args) = @_; | ||
| 23 | |||||
| 24 | 1 | 3µs | my $bool = delete $args{boolean}; | ||
| 25 | 1 | 1µs | $bool = 'perl' unless defined $bool; | ||
| 26 | 1 | 2µs | my $schemas = delete $args{schema} || ['+']; | ||
| 27 | 1 | 1µs | my $cyclic_refs = delete $args{cyclic_refs} || 'allow'; | ||
| 28 | 1 | 1µs | my $indent = delete $args{indent}; | ||
| 29 | 1 | 1µs | my $width = delete $args{width}; | ||
| 30 | 1 | 1µs | my $writer = delete $args{writer}; | ||
| 31 | 1 | 0s | my $header = delete $args{header}; | ||
| 32 | 1 | 0s | my $footer = delete $args{footer}; | ||
| 33 | 1 | 1µs | my $duplicate_keys = delete $args{duplicate_keys}; | ||
| 34 | 1 | 10µs | 1 | 17µs | my $yaml_version = $class->_arg_yaml_version(delete $args{yaml_version}); # spent 17µs making 1 call to YAML::PP::_arg_yaml_version |
| 35 | 1 | 1µs | my $default_yaml_version = $yaml_version->[0]; | ||
| 36 | 1 | 1µs | my $version_directive = delete $args{version_directive}; | ||
| 37 | 1 | 1µs | my $preserve = delete $args{preserve}; | ||
| 38 | 1 | 1µs | my $parser = delete $args{parser}; | ||
| 39 | my $emitter = delete $args{emitter} || { | ||||
| 40 | 1 | 5µs | indent => $indent, | ||
| 41 | width => $width, | ||||
| 42 | writer => $writer, | ||||
| 43 | }; | ||||
| 44 | 1 | 1µs | if (keys %args) { | ||
| 45 | die "Unexpected arguments: " . join ', ', sort keys %args; | ||||
| 46 | } | ||||
| 47 | |||||
| 48 | 1 | 0s | my %schemas; | ||
| 49 | 1 | 4µs | for my $v (@$yaml_version) { | ||
| 50 | 1 | 0s | my $schema; | ||
| 51 | 1 | 13µs | 1 | 4µs | if (blessed($schemas) and $schemas->isa('YAML::PP::Schema')) { # spent 4µs making 1 call to Scalar::Util::blessed |
| 52 | $schema = $schemas; | ||||
| 53 | } | ||||
| 54 | else { | ||||
| 55 | 1 | 6µs | 1 | 50µs | $schema = YAML::PP::Schema->new( # spent 50µs making 1 call to YAML::PP::Schema::new |
| 56 | boolean => $bool, | ||||
| 57 | yaml_version => $v, | ||||
| 58 | ); | ||||
| 59 | 1 | 3µs | 1 | 3.08ms | $schema->load_subschemas(@$schemas); # spent 3.08ms making 1 call to YAML::PP::Schema::load_subschemas |
| 60 | } | ||||
| 61 | 1 | 2µs | $schemas{ $v } = $schema; | ||
| 62 | } | ||||
| 63 | 1 | 0s | my $default_schema = $schemas{ $default_yaml_version }; | ||
| 64 | |||||
| 65 | 1 | 4µs | 1 | 216µs | my $loader = YAML::PP::Loader->new( # spent 216µs making 1 call to YAML::PP::Loader::new |
| 66 | schemas => \%schemas, | ||||
| 67 | cyclic_refs => $cyclic_refs, | ||||
| 68 | parser => $parser, | ||||
| 69 | default_yaml_version => $default_yaml_version, | ||||
| 70 | preserve => $preserve, | ||||
| 71 | duplicate_keys => $duplicate_keys, | ||||
| 72 | ); | ||||
| 73 | 1 | 4µs | 1 | 126µs | my $dumper = YAML::PP::Dumper->new( # spent 126µs making 1 call to YAML::PP::Dumper::new |
| 74 | schema => $default_schema, | ||||
| 75 | emitter => $emitter, | ||||
| 76 | header => $header, | ||||
| 77 | footer => $footer, | ||||
| 78 | version_directive => $version_directive, | ||||
| 79 | preserve => $preserve, | ||||
| 80 | ); | ||||
| 81 | |||||
| 82 | 1 | 2µs | my $self = bless { | ||
| 83 | schema => \%schemas, | ||||
| 84 | loader => $loader, | ||||
| 85 | dumper => $dumper, | ||||
| 86 | }, $class; | ||||
| 87 | 1 | 6µs | return $self; | ||
| 88 | } | ||||
| 89 | |||||
| 90 | sub clone { | ||||
| 91 | my ($self) = @_; | ||||
| 92 | my $clone = { | ||||
| 93 | schema => $self->schema, | ||||
| 94 | loader => $self->loader->clone, | ||||
| 95 | dumper => $self->dumper->clone, | ||||
| 96 | }; | ||||
| 97 | return bless $clone, ref $self; | ||||
| 98 | } | ||||
| 99 | |||||
| 100 | # spent 17µs within YAML::PP::_arg_yaml_version which was called:
# once (17µs+0s) by YAML::PP::new at line 34 | ||||
| 101 | 1 | 1µs | my ($class, $version) = @_; | ||
| 102 | 1 | 2µs | my @versions = ('1.2'); | ||
| 103 | 1 | 6µs | if (defined $version) { | ||
| 104 | @versions = (); | ||||
| 105 | if (not ref $version) { | ||||
| 106 | $version = [$version]; | ||||
| 107 | } | ||||
| 108 | for my $v (@$version) { | ||||
| 109 | unless ($YAML_VERSIONS{ $v }) { | ||||
| 110 | croak "YAML Version '$v' not supported"; | ||||
| 111 | } | ||||
| 112 | push @versions, $v; | ||||
| 113 | } | ||||
| 114 | } | ||||
| 115 | 1 | 24µs | return \@versions; | ||
| 116 | } | ||||
| 117 | |||||
| 118 | |||||
| 119 | # spent 17µs within YAML::PP::loader which was called:
# once (17µs+0s) by YAML::PP::load_file at line 154 | ||||
| 120 | 1 | 1µs | if (@_ > 1) { | ||
| 121 | $_[0]->{loader} = $_[1] | ||||
| 122 | } | ||||
| 123 | 1 | 5µs | return $_[0]->{loader}; | ||
| 124 | } | ||||
| 125 | |||||
| 126 | sub dumper { | ||||
| 127 | if (@_ > 1) { | ||||
| 128 | $_[0]->{dumper} = $_[1] | ||||
| 129 | } | ||||
| 130 | return $_[0]->{dumper}; | ||||
| 131 | } | ||||
| 132 | |||||
| 133 | sub schema { | ||||
| 134 | if (@_ > 1) { $_[0]->{schema}->{'1.2'} = $_[1] } | ||||
| 135 | return $_[0]->{schema}->{'1.2'}; | ||||
| 136 | } | ||||
| 137 | |||||
| 138 | sub default_schema { | ||||
| 139 | my ($self, %args) = @_; | ||||
| 140 | my $schema = YAML::PP::Schema->new( | ||||
| 141 | boolean => $args{boolean}, | ||||
| 142 | ); | ||||
| 143 | $schema->load_subschemas(qw/ Core /); | ||||
| 144 | return $schema; | ||||
| 145 | } | ||||
| 146 | |||||
| 147 | sub load_string { | ||||
| 148 | my ($self, $yaml) = @_; | ||||
| 149 | return $self->loader->load_string($yaml); | ||||
| 150 | } | ||||
| 151 | |||||
| 152 | # spent 6.98s (9µs+6.98) within YAML::PP::load_file which was called:
# once (9µs+6.98s) by main::RUNTIME at line 6 of /Users/ether/git/fastly/Heavenly/profiling/jsm-0.558-om-0.037/../prof.pl | ||||
| 153 | 1 | 0s | my ($self, $file) = @_; | ||
| 154 | 1 | 27µs | 2 | 6.98s | return $self->loader->load_file($file); # spent 6.98s making 1 call to YAML::PP::Loader::load_file
# spent 17µs making 1 call to YAML::PP::loader |
| 155 | } | ||||
| 156 | |||||
| 157 | sub dump { | ||||
| 158 | my ($self, @data) = @_; | ||||
| 159 | return $self->dumper->dump(@data); | ||||
| 160 | } | ||||
| 161 | |||||
| 162 | sub dump_string { | ||||
| 163 | my ($self, @data) = @_; | ||||
| 164 | return $self->dumper->dump_string(@data); | ||||
| 165 | } | ||||
| 166 | |||||
| 167 | sub dump_file { | ||||
| 168 | my ($self, $file, @data) = @_; | ||||
| 169 | return $self->dumper->dump_file($file, @data); | ||||
| 170 | } | ||||
| 171 | |||||
| 172 | # legagy interface | ||||
| 173 | sub Load { | ||||
| 174 | my ($yaml) = @_; | ||||
| 175 | YAML::PP->new->load_string($yaml); | ||||
| 176 | } | ||||
| 177 | |||||
| 178 | sub LoadFile { | ||||
| 179 | my ($file) = @_; | ||||
| 180 | YAML::PP->new->load_file($file); | ||||
| 181 | } | ||||
| 182 | |||||
| 183 | sub Dump { | ||||
| 184 | my (@data) = @_; | ||||
| 185 | YAML::PP->new->dump_string(@data); | ||||
| 186 | } | ||||
| 187 | |||||
| 188 | sub DumpFile { | ||||
| 189 | my ($file, @data) = @_; | ||||
| 190 | YAML::PP->new->dump_file($file, @data); | ||||
| 191 | } | ||||
| 192 | |||||
| 193 | sub preserved_scalar { | ||||
| 194 | my ($self, $value, %args) = @_; | ||||
| 195 | my $scalar = YAML::PP::Preserve::Scalar->new( | ||||
| 196 | value => $value, | ||||
| 197 | %args, | ||||
| 198 | ); | ||||
| 199 | return $scalar; | ||||
| 200 | } | ||||
| 201 | |||||
| 202 | sub preserved_mapping { | ||||
| 203 | my ($self, $hash, %args) = @_; | ||||
| 204 | my $data = {}; | ||||
| 205 | tie %$data, 'YAML::PP::Preserve::Hash'; | ||||
| 206 | %$data = %$hash; | ||||
| 207 | my $t = tied %$data; | ||||
| 208 | $t->{style} = $args{style}; | ||||
| 209 | $t->{alias} = $args{alias}; | ||||
| 210 | return $data; | ||||
| 211 | } | ||||
| 212 | |||||
| 213 | sub preserved_sequence { | ||||
| 214 | my ($self, $array, %args) = @_; | ||||
| 215 | my $data = []; | ||||
| 216 | tie @$data, 'YAML::PP::Preserve::Array'; | ||||
| 217 | push @$data, @$array; | ||||
| 218 | my $t = tied @$data; | ||||
| 219 | $t->{style} = $args{style}; | ||||
| 220 | $t->{alias} = $args{alias}; | ||||
| 221 | return $data; | ||||
| 222 | } | ||||
| 223 | |||||
| 224 | package YAML::PP::Preserve::Hash; | ||||
| 225 | # experimental | ||||
| 226 | 2 | 611µs | 2 | 1.64ms | # spent 1.64ms (1.41+228µs) within YAML::PP::Preserve::Hash::BEGIN@226 which was called:
# once (1.41ms+228µs) by main::BEGIN@3 at line 226 # spent 1.64ms making 1 call to YAML::PP::Preserve::Hash::BEGIN@226
# spent 3µs making 1 call to YAML::PP::Preserve::Hash::__ANON__ |
| 227 | 2 | 61µs | 2 | 560µs | # spent 286µs (12+274) within YAML::PP::Preserve::Hash::BEGIN@227 which was called:
# once (12µs+274µs) by main::BEGIN@3 at line 227 # spent 286µs making 1 call to YAML::PP::Preserve::Hash::BEGIN@227
# spent 274µs making 1 call to base::import |
| 228 | 2 | 496µs | 2 | 89µs | # spent 54µs (19+35) within YAML::PP::Preserve::Hash::BEGIN@228 which was called:
# once (19µs+35µs) by main::BEGIN@3 at line 228 # spent 54µs making 1 call to YAML::PP::Preserve::Hash::BEGIN@228
# spent 35µs making 1 call to Exporter::import |
| 229 | |||||
| 230 | sub TIEHASH { | ||||
| 231 | my ($class, %args) = @_; | ||||
| 232 | my $self = bless { | ||||
| 233 | keys => [keys %args], | ||||
| 234 | data => { %args }, | ||||
| 235 | }, $class; | ||||
| 236 | } | ||||
| 237 | |||||
| 238 | sub STORE { | ||||
| 239 | my ($self, $key, $val) = @_; | ||||
| 240 | my $keys = $self->{keys}; | ||||
| 241 | unless (exists $self->{data}->{ $key }) { | ||||
| 242 | push @$keys, $key; | ||||
| 243 | } | ||||
| 244 | if (ref $val and not blessed($val)) { | ||||
| 245 | if (reftype($val) eq 'HASH' and not tied %$val) { | ||||
| 246 | tie %$val, 'YAML::PP::Preserve::Hash', %$val; | ||||
| 247 | } | ||||
| 248 | elsif (reftype($val) eq 'ARRAY' and not tied @$val) { | ||||
| 249 | tie @$val, 'YAML::PP::Preserve::Array', @$val; | ||||
| 250 | } | ||||
| 251 | } | ||||
| 252 | $self->{data}->{ $key } = $val; | ||||
| 253 | } | ||||
| 254 | |||||
| 255 | sub FIRSTKEY { | ||||
| 256 | my ($self) = @_; | ||||
| 257 | return $self->{keys}->[0]; | ||||
| 258 | } | ||||
| 259 | |||||
| 260 | sub NEXTKEY { | ||||
| 261 | my ($self, $last) = @_; | ||||
| 262 | my $keys = $self->{keys}; | ||||
| 263 | for my $i (0 .. $#$keys) { | ||||
| 264 | if ("$keys->[ $i ]" eq "$last") { | ||||
| 265 | return $keys->[ $i + 1 ]; | ||||
| 266 | } | ||||
| 267 | } | ||||
| 268 | return; | ||||
| 269 | } | ||||
| 270 | |||||
| 271 | sub FETCH { | ||||
| 272 | my ($self, $key) = @_; | ||||
| 273 | my $val = $self->{data}->{ $key }; | ||||
| 274 | } | ||||
| 275 | |||||
| 276 | sub DELETE { | ||||
| 277 | my ($self, $key) = @_; | ||||
| 278 | @{ $self->{keys} } = grep { "$_" ne "$key" } @{ $self->{keys} }; | ||||
| 279 | delete $self->{data}->{ $key }; | ||||
| 280 | } | ||||
| 281 | |||||
| 282 | sub EXISTS { | ||||
| 283 | my ($self, $key) = @_; | ||||
| 284 | return exists $self->{data}->{ $key }; | ||||
| 285 | } | ||||
| 286 | |||||
| 287 | sub CLEAR { | ||||
| 288 | my ($self) = @_; | ||||
| 289 | $self->{keys} = []; | ||||
| 290 | $self->{data} = {}; | ||||
| 291 | } | ||||
| 292 | |||||
| 293 | sub SCALAR { | ||||
| 294 | my ($self) = @_; | ||||
| 295 | return scalar %{ $self->{data} }; | ||||
| 296 | } | ||||
| 297 | |||||
| 298 | package YAML::PP::Preserve::Array; | ||||
| 299 | # experimental | ||||
| 300 | 2 | 748µs | 2 | 1.80ms | # spent 1.79ms (1.65+147µs) within YAML::PP::Preserve::Array::BEGIN@300 which was called:
# once (1.65ms+147µs) by main::BEGIN@3 at line 300 # spent 1.79ms making 1 call to YAML::PP::Preserve::Array::BEGIN@300
# spent 7µs making 1 call to YAML::PP::Preserve::Array::__ANON__ |
| 301 | 2 | 53µs | 2 | 656µs | # spent 334µs (12+322) within YAML::PP::Preserve::Array::BEGIN@301 which was called:
# once (12µs+322µs) by main::BEGIN@3 at line 301 # spent 334µs making 1 call to YAML::PP::Preserve::Array::BEGIN@301
# spent 322µs making 1 call to base::import |
| 302 | 2 | 801µs | 2 | 126µs | # spent 76µs (26+50) within YAML::PP::Preserve::Array::BEGIN@302 which was called:
# once (26µs+50µs) by main::BEGIN@3 at line 302 # spent 76µs making 1 call to YAML::PP::Preserve::Array::BEGIN@302
# spent 50µs making 1 call to Exporter::import |
| 303 | |||||
| 304 | sub TIEARRAY { | ||||
| 305 | my ($class, @items) = @_; | ||||
| 306 | my $self = bless { | ||||
| 307 | data => [@items], | ||||
| 308 | }, $class; | ||||
| 309 | return $self; | ||||
| 310 | } | ||||
| 311 | |||||
| 312 | sub FETCH { | ||||
| 313 | my ($self, $i) = @_; | ||||
| 314 | return $self->{data}->[ $i ]; | ||||
| 315 | } | ||||
| 316 | sub FETCHSIZE { | ||||
| 317 | my ($self) = @_; | ||||
| 318 | return $#{ $self->{data} } + 1; | ||||
| 319 | } | ||||
| 320 | |||||
| 321 | sub _preserve { | ||||
| 322 | my ($val) = @_; | ||||
| 323 | if (ref $val and not blessed($val)) { | ||||
| 324 | if (reftype($val) eq 'HASH' and not tied %$val) { | ||||
| 325 | tie %$val, 'YAML::PP::Preserve::Hash', %$val; | ||||
| 326 | } | ||||
| 327 | elsif (reftype($val) eq 'ARRAY' and not tied @$val) { | ||||
| 328 | tie @$val, 'YAML::PP::Preserve::Array', @$val; | ||||
| 329 | } | ||||
| 330 | } | ||||
| 331 | return $val; | ||||
| 332 | } | ||||
| 333 | |||||
| 334 | sub STORE { | ||||
| 335 | my ($self, $i, $val) = @_; | ||||
| 336 | _preserve($val); | ||||
| 337 | $self->{data}->[ $i ] = $val; | ||||
| 338 | } | ||||
| 339 | sub PUSH { | ||||
| 340 | my ($self, @args) = @_; | ||||
| 341 | push @{ $self->{data} }, map { _preserve $_ } @args; | ||||
| 342 | } | ||||
| 343 | sub STORESIZE { | ||||
| 344 | my ($self, $i) = @_; | ||||
| 345 | $#{ $self->{data} } = $i - 1; | ||||
| 346 | } | ||||
| 347 | sub DELETE { | ||||
| 348 | my ($self, $i) = @_; | ||||
| 349 | delete $self->{data}->[ $i ]; | ||||
| 350 | } | ||||
| 351 | sub EXISTS { | ||||
| 352 | my ($self, $i) = @_; | ||||
| 353 | return exists $self->{data}->[ $i ]; | ||||
| 354 | } | ||||
| 355 | sub CLEAR { | ||||
| 356 | my ($self) = @_; | ||||
| 357 | $self->{data} = []; | ||||
| 358 | } | ||||
| 359 | sub SHIFT { | ||||
| 360 | my ($self) = @_; | ||||
| 361 | shift @{ $self->{data} }; | ||||
| 362 | } | ||||
| 363 | sub UNSHIFT { | ||||
| 364 | my ($self, @args) = @_; | ||||
| 365 | unshift @{ $self->{data} }, map { _preserve $_ } @args; | ||||
| 366 | } | ||||
| 367 | sub SPLICE { | ||||
| 368 | my ($self, $offset, $length, @args) = @_; | ||||
| 369 | splice @{ $self->{data} }, $offset, $length, map { _preserve $_ } @args; | ||||
| 370 | } | ||||
| 371 | sub EXTEND {} | ||||
| 372 | |||||
| 373 | |||||
| 374 | package YAML::PP::Preserve::Scalar; | ||||
| 375 | |||||
| 376 | use overload | ||||
| 377 | 1 | 1µs | # spent 70µs (22+48) within YAML::PP::Preserve::Scalar::BEGIN@377 which was called:
# once (22µs+48µs) by main::BEGIN@3 at line 381 | ||
| 378 | '+' => \&value, | ||||
| 379 | '""' => \&value, | ||||
| 380 | 'bool' => \&value, | ||||
| 381 | 1 | 253µs | 2 | 118µs | ; # spent 70µs making 1 call to YAML::PP::Preserve::Scalar::BEGIN@377
# spent 48µs making 1 call to overload::import |
| 382 | sub new { | ||||
| 383 | my ($class, %args) = @_; | ||||
| 384 | my $self = { | ||||
| 385 | %args, | ||||
| 386 | }; | ||||
| 387 | bless $self, $class; | ||||
| 388 | } | ||||
| 389 | sub value { $_[0]->{value} } | ||||
| 390 | sub tag { $_[0]->{tag} } | ||||
| 391 | sub style { $_[0]->{style} || 0 } | ||||
| 392 | sub alias { $_[0]->{alias} } | ||||
| 393 | |||||
| 394 | 1 | 7µs | 1; | ||
| 395 | |||||
| 396 | __END__ | ||||
# spent 7µs within YAML::PP::Preserve::Array::__ANON__ which was called:
# once (7µs+0s) by YAML::PP::Preserve::Array::BEGIN@300 at line 300 | |||||
# spent 3µs within YAML::PP::Preserve::Hash::__ANON__ which was called:
# once (3µs+0s) by YAML::PP::Preserve::Hash::BEGIN@226 at line 226 | |||||
sub YAML::PP::__ANON__; # xsub |