| Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/YAML/PP.pm |
| Statements | Executed 74 statements in 6.49ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 2.74ms | 6.51ms | YAML::PP::BEGIN@8 |
| 1 | 1 | 1 | 2.23ms | 12.1ms | YAML::PP::BEGIN@11 |
| 1 | 1 | 1 | 1.63ms | 1.72ms | YAML::PP::Preserve::Array::BEGIN@300 |
| 1 | 1 | 1 | 1.44ms | 1.57ms | YAML::PP::Preserve::Hash::BEGIN@226 |
| 1 | 1 | 1 | 1.25ms | 1.55ms | YAML::PP::BEGIN@9 |
| 1 | 1 | 1 | 1.00ms | 29.0ms | YAML::PP::BEGIN@10 |
| 1 | 1 | 1 | 65µs | 2.67ms | YAML::PP::new |
| 1 | 1 | 1 | 63µs | 67µs | main::BEGIN@2.280 |
| 1 | 1 | 1 | 12µs | 43µs | YAML::PP::Preserve::Scalar::BEGIN@377 |
| 1 | 1 | 1 | 11µs | 400µs | YAML::PP::Preserve::Hash::BEGIN@227 |
| 1 | 1 | 1 | 11µs | 6.54s | YAML::PP::load_file |
| 1 | 1 | 1 | 10µs | 34µs | YAML::PP::BEGIN@12 |
| 1 | 1 | 1 | 9µs | 75µs | YAML::PP::BEGIN@15 |
| 1 | 1 | 1 | 9µs | 197µs | YAML::PP::Preserve::Array::BEGIN@301 |
| 1 | 1 | 1 | 8µs | 33µs | YAML::PP::BEGIN@13 |
| 1 | 1 | 1 | 8µs | 37µs | YAML::PP::Preserve::Hash::BEGIN@228 |
| 1 | 1 | 1 | 7µs | 46µs | main::BEGIN@3.281 |
| 1 | 1 | 1 | 6µs | 25µs | YAML::PP::Preserve::Array::BEGIN@302 |
| 1 | 1 | 1 | 5µs | 5µs | YAML::PP::_arg_yaml_version |
| 1 | 1 | 1 | 4µs | 4µs | YAML::PP::loader |
| 1 | 1 | 1 | 2µs | 2µs | YAML::PP::Preserve::Array::__ANON__ (xsub) |
| 1 | 1 | 1 | 2µs | 2µ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 | 44µs | 2 | 71µs | # spent 67µs (63+4) within main::BEGIN@2.280 which was called:
# once (63µs+4µs) by main::BEGIN@3 at line 2 # spent 67µs making 1 call to main::BEGIN@2.280
# spent 4µs making 1 call to strict::import |
| 3 | 2 | 49µs | 2 | 85µs | # spent 46µs (7+39) within main::BEGIN@3.281 which was called:
# once (7µs+39µs) by main::BEGIN@3 at line 3 # spent 46µs making 1 call to main::BEGIN@3.281
# spent 39µs making 1 call to warnings::import |
| 4 | package YAML::PP; | ||||
| 5 | |||||
| 6 | 1 | 0s | our $VERSION = '0.035'; # VERSION | ||
| 7 | |||||
| 8 | 2 | 541µs | 2 | 6.52ms | # spent 6.51ms (2.74+3.78) within YAML::PP::BEGIN@8 which was called:
# once (2.74ms+3.78ms) by main::BEGIN@3 at line 8 # spent 6.51ms making 1 call to YAML::PP::BEGIN@8
# spent 6µs making 1 call to YAML::PP::__ANON__ |
| 9 | 2 | 647µs | 2 | 1.56ms | # spent 1.55ms (1.25+306µs) within YAML::PP::BEGIN@9 which was called:
# once (1.25ms+306µs) by main::BEGIN@3 at line 9 # spent 1.55ms making 1 call to YAML::PP::BEGIN@9
# spent 12µs making 1 call to Exporter::import |
| 10 | 2 | 524µs | 2 | 29.0ms | # spent 29.0ms (1.00+28.0) within YAML::PP::BEGIN@10 which was called:
# once (1.00ms+28.0ms) by main::BEGIN@3 at line 10 # spent 29.0ms making 1 call to YAML::PP::BEGIN@10
# spent 1µs making 1 call to YAML::PP::__ANON__ |
| 11 | 2 | 438µs | 2 | 12.1ms | # spent 12.1ms (2.23+9.84) within YAML::PP::BEGIN@11 which was called:
# once (2.23ms+9.84ms) by main::BEGIN@3 at line 11 # spent 12.1ms making 1 call to YAML::PP::BEGIN@11
# spent 2µs making 1 call to YAML::PP::__ANON__ |
| 12 | 2 | 30µs | 2 | 58µs | # spent 34µs (10+24) within YAML::PP::BEGIN@12 which was called:
# once (10µs+24µs) by main::BEGIN@3 at line 12 # spent 34µs making 1 call to YAML::PP::BEGIN@12
# spent 24µs making 1 call to Exporter::import |
| 13 | 2 | 22µs | 2 | 58µs | # spent 33µs (8+25) within YAML::PP::BEGIN@13 which was called:
# once (8µs+25µs) by main::BEGIN@3 at line 13 # spent 33µs making 1 call to YAML::PP::BEGIN@13
# spent 25µs making 1 call to Exporter::import |
| 14 | |||||
| 15 | 2 | 985µs | 2 | 141µs | # spent 75µs (9+66) within YAML::PP::BEGIN@15 which was called:
# once (9µs+66µs) by main::BEGIN@3 at line 15 # spent 75µs making 1 call to YAML::PP::BEGIN@15
# spent 66µs making 1 call to base::import |
| 16 | 1 | 2µs | our @EXPORT_OK = qw/ Load LoadFile Dump DumpFile /; | ||
| 17 | |||||
| 18 | 1 | 1µs | my %YAML_VERSIONS = ('1.1' => 1, '1.2' => 1); | ||
| 19 | |||||
| 20 | |||||
| 21 | # spent 2.67ms (65µs+2.60) within YAML::PP::new which was called:
# once (65µs+2.60ms) by main::RUNTIME at line 6 of /Users/ether/git/fastly/Heavenly/profiling/jsm-0.552-om-0.031/../prof.pl | ||||
| 22 | 1 | 3µs | my ($class, %args) = @_; | ||
| 23 | |||||
| 24 | 1 | 1µ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 | 0s | my $writer = delete $args{writer}; | ||
| 31 | 1 | 0s | my $header = delete $args{header}; | ||
| 32 | 1 | 1µs | my $footer = delete $args{footer}; | ||
| 33 | 1 | 0s | my $duplicate_keys = delete $args{duplicate_keys}; | ||
| 34 | 1 | 2µs | 1 | 5µs | my $yaml_version = $class->_arg_yaml_version(delete $args{yaml_version}); # spent 5µs making 1 call to YAML::PP::_arg_yaml_version |
| 35 | 1 | 0s | my $default_yaml_version = $yaml_version->[0]; | ||
| 36 | 1 | 0s | 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 | 2µ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 | 1µs | for my $v (@$yaml_version) { | ||
| 50 | 1 | 0s | my $schema; | ||
| 51 | 1 | 6µs | 1 | 1µs | if (blessed($schemas) and $schemas->isa('YAML::PP::Schema')) { # spent 1µs making 1 call to Scalar::Util::blessed |
| 52 | $schema = $schemas; | ||||
| 53 | } | ||||
| 54 | else { | ||||
| 55 | 1 | 3µs | 1 | 24µs | $schema = YAML::PP::Schema->new( # spent 24µs making 1 call to YAML::PP::Schema::new |
| 56 | boolean => $bool, | ||||
| 57 | yaml_version => $v, | ||||
| 58 | ); | ||||
| 59 | 1 | 2µs | 1 | 2.34ms | $schema->load_subschemas(@$schemas); # spent 2.34ms making 1 call to YAML::PP::Schema::load_subschemas |
| 60 | } | ||||
| 61 | 1 | 2µs | $schemas{ $v } = $schema; | ||
| 62 | } | ||||
| 63 | 1 | 1µs | my $default_schema = $schemas{ $default_yaml_version }; | ||
| 64 | |||||
| 65 | 1 | 4µs | 1 | 144µs | my $loader = YAML::PP::Loader->new( # spent 144µ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 | 89µs | my $dumper = YAML::PP::Dumper->new( # spent 89µ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 5µs within YAML::PP::_arg_yaml_version which was called:
# once (5µs+0s) by YAML::PP::new at line 34 | ||||
| 101 | 1 | 1µs | my ($class, $version) = @_; | ||
| 102 | 1 | 1µs | my @versions = ('1.2'); | ||
| 103 | 1 | 1µ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 | 7µs | return \@versions; | ||
| 116 | } | ||||
| 117 | |||||
| 118 | |||||
| 119 | # spent 4µs within YAML::PP::loader which was called:
# once (4µs+0s) by YAML::PP::load_file at line 154 | ||||
| 120 | 1 | 1µs | if (@_ > 1) { | ||
| 121 | $_[0]->{loader} = $_[1] | ||||
| 122 | } | ||||
| 123 | 1 | 6µ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.54s (11µs+6.54) within YAML::PP::load_file which was called:
# once (11µs+6.54s) by main::RUNTIME at line 6 of /Users/ether/git/fastly/Heavenly/profiling/jsm-0.552-om-0.031/../prof.pl | ||||
| 153 | 1 | 0s | my ($self, $file) = @_; | ||
| 154 | 1 | 8µs | 2 | 6.54s | return $self->loader->load_file($file); # spent 6.54s making 1 call to YAML::PP::Loader::load_file
# spent 4µ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 | 863µs | 2 | 1.57ms | # spent 1.57ms (1.44+132µs) within YAML::PP::Preserve::Hash::BEGIN@226 which was called:
# once (1.44ms+132µs) by main::BEGIN@3 at line 226 # spent 1.57ms making 1 call to YAML::PP::Preserve::Hash::BEGIN@226
# spent 2µs making 1 call to YAML::PP::Preserve::Hash::__ANON__ |
| 227 | 2 | 37µs | 2 | 789µs | # spent 400µs (11+389) within YAML::PP::Preserve::Hash::BEGIN@227 which was called:
# once (11µs+389µs) by main::BEGIN@3 at line 227 # spent 400µs making 1 call to YAML::PP::Preserve::Hash::BEGIN@227
# spent 389µs making 1 call to base::import |
| 228 | 2 | 405µs | 2 | 66µs | # spent 37µs (8+29) within YAML::PP::Preserve::Hash::BEGIN@228 which was called:
# once (8µs+29µs) by main::BEGIN@3 at line 228 # spent 37µs making 1 call to YAML::PP::Preserve::Hash::BEGIN@228
# spent 29µ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 | 822µs | 2 | 1.72ms | # spent 1.72ms (1.63+97µs) within YAML::PP::Preserve::Array::BEGIN@300 which was called:
# once (1.63ms+97µs) by main::BEGIN@3 at line 300 # spent 1.72ms making 1 call to YAML::PP::Preserve::Array::BEGIN@300
# spent 2µs making 1 call to YAML::PP::Preserve::Array::__ANON__ |
| 301 | 2 | 35µs | 2 | 385µs | # spent 197µs (9+188) within YAML::PP::Preserve::Array::BEGIN@301 which was called:
# once (9µs+188µs) by main::BEGIN@3 at line 301 # spent 197µs making 1 call to YAML::PP::Preserve::Array::BEGIN@301
# spent 188µs making 1 call to base::import |
| 302 | 2 | 785µs | 2 | 44µs | # spent 25µs (6+19) within YAML::PP::Preserve::Array::BEGIN@302 which was called:
# once (6µs+19µs) by main::BEGIN@3 at line 302 # spent 25µs making 1 call to YAML::PP::Preserve::Array::BEGIN@302
# spent 19µ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 | 0s | # spent 43µs (12+31) within YAML::PP::Preserve::Scalar::BEGIN@377 which was called:
# once (12µs+31µs) by main::BEGIN@3 at line 381 | ||
| 378 | '+' => \&value, | ||||
| 379 | '""' => \&value, | ||||
| 380 | 'bool' => \&value, | ||||
| 381 | 1 | 182µs | 2 | 74µs | ; # spent 43µs making 1 call to YAML::PP::Preserve::Scalar::BEGIN@377
# spent 31µ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 | 6µs | 1; | ||
| 395 | |||||
| 396 | __END__ | ||||
# spent 2µs within YAML::PP::Preserve::Array::__ANON__ which was called:
# once (2µs+0s) by YAML::PP::Preserve::Array::BEGIN@300 at line 300 | |||||
# spent 2µs within YAML::PP::Preserve::Hash::__ANON__ which was called:
# once (2µs+0s) by YAML::PP::Preserve::Hash::BEGIN@226 at line 226 |