| File | /usr/lib/perl5/YAML/Syck.pm | Statements Executed | 27 | Total Time | 0.001581 seconds |
| Calls | Inclusive Time | Subroutine | |
|---|---|---|---|
| 1 | 0.00014 | YAML::Syck:: | Dump |
| 0 | 0 | YAML::Syck:: | BEGIN |
| 0 | 0 | YAML::Syck:: | DumpFile |
| 0 | 0 | YAML::Syck:: | Load |
| 0 | 0 | YAML::Syck:: | LoadFile |
| 0 | 0 | YAML::Syck:: | __ANON__[:36] |
| 0 | 0 | YAML::Syck:: | __ANON__[:37] |
| 0 | 0 | YAML::Syck:: | __ANON__[:38] |
| 0 | 0 | YAML::Syck:: | __ANON__[:39] |
| 0 | 0 | YAML::Syck:: | __ANON__[:40] |
| 0 | 0 | YAML::Syck:: | __ANON__[:41] |
| 0 | 0 | YAML::Syck:: | __ANON__[:42] |
| 0 | 0 | YAML::Syck:: | __ANON__[:43] |
| 0 | 0 | YAML::Syck:: | __ANON__[:44] |
| 0 | 0 | YAML::Syck:: | __ANON__[:45] |
| 0 | 0 | YAML::Syck:: | __ANON__[:46] |
| 0 | 0 | YAML::Syck:: | __ANON__[:47] |
| 0 | 0 | YAML::Syck:: | __ANON__[:48] |
| 0 | 0 | YAML::Syck:: | __ANON__[:49] |
| 0 | 0 | YAML::Syck:: | __ANON__[:50] |
| 0 | 0 | YAML::Syck:: | __ANON__[:51] |
| 0 | 0 | YAML::Syck:: | __qr_helper |
| 0 | 0 | YAML::Syck:: | _is_openhandle |
| Line | Stmts. | Exclusive Time | Avg. | Code |
|---|---|---|---|---|
| 1 | package YAML::Syck; | |||
| 2 | # See documentation after the __END__ mark. | |||
| 3 | ||||
| 4 | 3 | 0.00004 | 0.00001 | use strict; # spent 9e-06s making 1 calls to strict::import |
| 5 | use vars qw( # spent 0.00016s making 1 calls to vars::import | |||
| 6 | @ISA @EXPORT $VERSION | |||
| 7 | $Headless $SortKeys $SingleQuote | |||
| 8 | $ImplicitTyping $ImplicitUnicode | |||
| 9 | $UseCode $LoadCode $DumpCode | |||
| 10 | $DeparseObject | |||
| 11 | 3 | 0.00003 | 0.00001 | ); |
| 12 | 3 | 0.00002 | 6e-06 | use 5.00307; |
| 13 | 3 | 0.00011 | 0.00004 | use Exporter; # spent 0.00004s making 1 calls to Exporter::import |
| 14 | ||||
| 15 | BEGIN { | |||
| 16 | 9 | 0.00025 | 0.00003 | $VERSION = '1.00'; |
| 17 | @EXPORT = qw( Dump Load DumpFile LoadFile ); | |||
| 18 | @ISA = qw( Exporter ); | |||
| 19 | ||||
| 20 | $SortKeys = 1; | |||
| 21 | ||||
| 22 | local $@; | |||
| 23 | eval { | |||
| 24 | require XSLoader; | |||
| 25 | XSLoader::load(__PACKAGE__, $VERSION); # spent 0.00024s making 1 calls to XSLoader::load | |||
| 26 | 1; | |||
| 27 | } or do { | |||
| 28 | require DynaLoader; | |||
| 29 | push @ISA, 'DynaLoader'; | |||
| 30 | __PACKAGE__->bootstrap($VERSION); | |||
| 31 | }; | |||
| 32 | ||||
| 33 | 1 | 0.00045 | 0.00045 | } |
| 34 | ||||
| 35 | use constant QR_MAP => { | |||
| 36 | '' => sub { qr{$_[0]} }, | |||
| 37 | x => sub { qr{$_[0]}x }, | |||
| 38 | i => sub { qr{$_[0]}i }, | |||
| 39 | s => sub { qr{$_[0]}s }, | |||
| 40 | m => sub { qr{$_[0]}m }, | |||
| 41 | ix => sub { qr{$_[0]}ix }, | |||
| 42 | sx => sub { qr{$_[0]}sx }, | |||
| 43 | mx => sub { qr{$_[0]}mx }, | |||
| 44 | si => sub { qr{$_[0]}si }, | |||
| 45 | mi => sub { qr{$_[0]}mi }, | |||
| 46 | ms => sub { qr{$_[0]}sm }, | |||
| 47 | six => sub { qr{$_[0]}six }, | |||
| 48 | mix => sub { qr{$_[0]}mix }, | |||
| 49 | msx => sub { qr{$_[0]}msx }, | |||
| 50 | msi => sub { qr{$_[0]}msi }, | |||
| 51 | msix => sub { qr{$_[0]}msix }, | |||
| 52 | 3 | 0.00055 | 0.00018 | }; # spent 0.00006s making 1 calls to constant::import |
| 53 | ||||
| 54 | sub __qr_helper { | |||
| 55 | if ($_[0] =~ /\A \(\? ([ixsm]*) (?:- (?:[ixsm]*))? : (.*) \) \z/x) { | |||
| 56 | my $sub = QR_MAP()->{$1} || QR_MAP()->{''}; | |||
| 57 | &$sub($2); | |||
| 58 | } | |||
| 59 | else { | |||
| 60 | qr/$_[0]/; | |||
| 61 | } | |||
| 62 | } | |||
| 63 | ||||
| 64 | # spent 0.00014s within YAML::Syck::Dump which was called:
# 1 times (0.00014s) by CGI::Session::Serialize::yaml::freeze at line 18 of /usr/share/perl5/CGI/Session/Serialize/yaml.pm sub Dump { | |||
| 65 | 1 | 0.00013 | 0.00013 | $#_ ? join('', map { YAML::Syck::DumpYAML($_) } @_) # spent 0.00013s making 1 calls to YAML::Syck::DumpYAML |
| 66 | : YAML::Syck::DumpYAML($_[0]); | |||
| 67 | } | |||
| 68 | ||||
| 69 | sub Load { | |||
| 70 | if (wantarray) { | |||
| 71 | my ($rv) = YAML::Syck::LoadYAML($_[0]); | |||
| 72 | @{$rv}; | |||
| 73 | } | |||
| 74 | else { | |||
| 75 | YAML::Syck::LoadYAML($_[0]); | |||
| 76 | } | |||
| 77 | } | |||
| 78 | ||||
| 79 | # NOTE. The code below (_is_openhandle) avoids to require/load | |||
| 80 | # Scalar::Util unless it is given a ref or glob | |||
| 81 | # as an argument. That is purposeful, so to avoid | |||
| 82 | # the need for this dependency unless strictly necessary. | |||
| 83 | # If that was not the case, Scalar::Util::openhandle could | |||
| 84 | # be used directly. | |||
| 85 | ||||
| 86 | sub _is_openhandle { | |||
| 87 | my $h = shift; | |||
| 88 | if ( ref($h) || ref(\$h) eq 'GLOB' ) { | |||
| 89 | require Scalar::Util; | |||
| 90 | return Scalar::Util::openhandle($h); | |||
| 91 | } else { | |||
| 92 | return undef; | |||
| 93 | } | |||
| 94 | } | |||
| 95 | ||||
| 96 | sub DumpFile { | |||
| 97 | my $file = shift; | |||
| 98 | if ( _is_openhandle($file) ) { | |||
| 99 | if ($#_) { | |||
| 100 | print {$file} YAML::Syck::DumpYAML($_) for @_; | |||
| 101 | } | |||
| 102 | else { | |||
| 103 | print {$file} YAML::Syck::DumpYAML($_[0]); | |||
| 104 | } | |||
| 105 | } | |||
| 106 | else { | |||
| 107 | local *FH; | |||
| 108 | open FH, "> $file" or die "Cannot write to $file: $!"; | |||
| 109 | if ($#_) { | |||
| 110 | print FH YAML::Syck::DumpYAML($_) for @_; | |||
| 111 | } | |||
| 112 | else { | |||
| 113 | print FH YAML::Syck::DumpYAML($_[0]); | |||
| 114 | } | |||
| 115 | close FH; | |||
| 116 | } | |||
| 117 | } | |||
| 118 | ||||
| 119 | sub LoadFile { | |||
| 120 | my $file = shift; | |||
| 121 | if ( _is_openhandle($file) ) { | |||
| 122 | Load(do { local $/; <$file> }); | |||
| 123 | } | |||
| 124 | else { | |||
| 125 | local *FH; | |||
| 126 | open FH, "< $file" or die "Cannot read from $file: $!"; | |||
| 127 | Load(do { local $/; <FH> }); | |||
| 128 | } | |||
| 129 | } | |||
| 130 | ||||
| 131 | 1 | 4e-06 | 4e-06 | 1; |
| 132 | ||||
| 133 | __END__ | |||
| 134 | =pod | |||
| 135 | ||||
| 136 | =head1 NAME | |||
| 137 | ||||
| 138 | YAML::Syck - Fast, lightweight YAML loader and dumper | |||
| 139 | ||||
| 140 | =head1 VERSION | |||
| 141 | ||||
| 142 | This document describes version 1.00 of YAML::Syck, released December 10, 2007. | |||
| 143 | ||||
| 144 | =head1 SYNOPSIS | |||
| 145 | ||||
| 146 | use YAML::Syck; | |||
| 147 | ||||
| 148 | # Set this for interoperability with other YAML/Syck bindings: | |||
| 149 | # e.g. Load('Yes') becomes 1 and Load('No') becomes ''. | |||
| 150 | $YAML::Syck::ImplicitTyping = 1; | |||
| 151 | ||||
| 152 | $data = Load($yaml); | |||
| 153 | $yaml = Dump($data); | |||
| 154 | ||||
| 155 | # $file can be an IO object, or a filename | |||
| 156 | $data = LoadFile($file); | |||
| 157 | DumpFile($file, $data); | |||
| 158 | ||||
| 159 | # A string with multiple YAML streams in it | |||
| 160 | $yaml = Dump(@data); | |||
| 161 | @data = Load($yaml); | |||
| 162 | ||||
| 163 | =head1 DESCRIPTION | |||
| 164 | ||||
| 165 | This module provides a Perl interface to the B<libsyck> data serialization | |||
| 166 | library. It exports the C<Dump> and C<Load> functions for converting | |||
| 167 | Perl data structures to YAML strings, and the other way around. | |||
| 168 | ||||
| 169 | B<NOTE>: If you are working with other language's YAML/Syck bindings | |||
| 170 | (such as Ruby), please set C<$YAML::Syck::ImplicitTyping> to C<1> before | |||
| 171 | calling the C<Load>/C<Dump> functions. The default setting is for | |||
| 172 | preserving backward-compatibility with C<YAML.pm>. | |||
| 173 | ||||
| 174 | =head1 FLAGS | |||
| 175 | ||||
| 176 | =head2 $YAML::Syck::Headless | |||
| 177 | ||||
| 178 | Defaults to false. Setting this to a true value will make C<Dump> omit the | |||
| 179 | leading C<---\n> marker. | |||
| 180 | ||||
| 181 | =head2 $YAML::Syck::SortKeys | |||
| 182 | ||||
| 183 | Defaults to false. Setting this to a true value will make C<Dump> sort | |||
| 184 | hash keys. | |||
| 185 | ||||
| 186 | =head2 $YAML::Syck::SingleQuote | |||
| 187 | ||||
| 188 | Defaults to false. Setting this to a true value will make C<Dump> always emit | |||
| 189 | single quotes instead of bare strings. | |||
| 190 | ||||
| 191 | =head2 $YAML::Syck::ImplicitTyping | |||
| 192 | ||||
| 193 | Defaults to false. Setting this to a true value will make C<Load> recognize | |||
| 194 | various implicit types in YAML, such as unquoted C<true>, C<false>, as well as | |||
| 195 | integers and floating-point numbers. Otherwise, only C<~> is recognized to | |||
| 196 | be C<undef>. | |||
| 197 | ||||
| 198 | =head2 $YAML::Syck::ImplicitUnicode | |||
| 199 | ||||
| 200 | Defaults to false. For Perl 5.8.0 or later, setting this to a true value will | |||
| 201 | make C<Load> set Unicode flag on for every string that contains valid UTF8 | |||
| 202 | sequences, and make C<Dump> return a unicode string. | |||
| 203 | ||||
| 204 | Regardless of this flag, Unicode strings are dumped verbatim without escaping; | |||
| 205 | byte strings with high-bit set will be dumped with backslash escaping. | |||
| 206 | ||||
| 207 | However, because YAML does not distinguish between these two kinds of strings, | |||
| 208 | so this flag will affect loading of both variants of strings. | |||
| 209 | ||||
| 210 | =head2 $YAML::Syck::ImplicitBinary | |||
| 211 | ||||
| 212 | Defaults to false. For Perl 5.8.0 or later, setting this to a true value will | |||
| 213 | make C<Dump> generate Base64-encoded C<!!binary> data for all non-Unicode | |||
| 214 | scalars containing high-bit bytes. | |||
| 215 | ||||
| 216 | =head2 $YAML::Syck::UseCode / $YAML::Syck::LoadCode / $YAML::Syck::DumpCode | |||
| 217 | ||||
| 218 | These flags control whether or not to try and eval/deparse perl source code; | |||
| 219 | each of them defaults to false. | |||
| 220 | ||||
| 221 | Setting C<$YAML::Syck::UseCode> to a true value is equivalent to setting | |||
| 222 | both C<$YAML::Syck::LoadCode> and C<$YAML::Syck::DumpCode> to true. | |||
| 223 | ||||
| 224 | =head1 BUGS | |||
| 225 | ||||
| 226 | Dumping Glob/IO values does not work yet. | |||
| 227 | ||||
| 228 | =head1 CAVEATS | |||
| 229 | ||||
| 230 | This module implements the YAML 1.0 spec. To deal with data in YAML 1.1, | |||
| 231 | please use the C<YAML::XS> module instead. | |||
| 232 | ||||
| 233 | The current implementation bundles libsyck source code; if your system has a | |||
| 234 | site-wide shared libsyck, it will I<not> be used. | |||
| 235 | ||||
| 236 | Tag names such as C<!!perl/hash:Foo> is blessed into the package C<Foo>, but | |||
| 237 | the C<!hs/foo> and C<!!hs/Foo> tags are blessed into C<hs::Foo>. Note that | |||
| 238 | this holds true even if the tag contains non-word characters; for example, | |||
| 239 | C<!haskell.org/Foo> is blessed into C<haskell.org::Foo>. Please use | |||
| 240 | L<Class::Rebless> to cast it into other user-defined packages. | |||
| 241 | ||||
| 242 | =head1 SEE ALSO | |||
| 243 | ||||
| 244 | L<YAML>, L<JSON::Syck> | |||
| 245 | ||||
| 246 | L<http://www.yaml.org/> | |||
| 247 | ||||
| 248 | =head1 AUTHORS | |||
| 249 | ||||
| 250 | Audrey Tang E<lt>cpan@audreyt.orgE<gt> | |||
| 251 | ||||
| 252 | =head1 COPYRIGHT | |||
| 253 | ||||
| 254 | Copyright 2005, 2006, 2007 by Audrey Tang E<lt>cpan@audreyt.orgE<gt>. | |||
| 255 | ||||
| 256 | This software is released under the MIT license cited below. | |||
| 257 | ||||
| 258 | The F<libsyck> code bundled with this library is released by | |||
| 259 | "why the lucky stiff", under a BSD-style license. See the F<COPYING> | |||
| 260 | file for details. | |||
| 261 | ||||
| 262 | =head2 The "MIT" License | |||
| 263 | ||||
| 264 | Permission is hereby granted, free of charge, to any person obtaining a copy | |||
| 265 | of this software and associated documentation files (the "Software"), to deal | |||
| 266 | in the Software without restriction, including without limitation the rights | |||
| 267 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
| 268 | copies of the Software, and to permit persons to whom the Software is | |||
| 269 | furnished to do so, subject to the following conditions: | |||
| 270 | ||||
| 271 | The above copyright notice and this permission notice shall be included in | |||
| 272 | all copies or substantial portions of the Software. | |||
| 273 | ||||
| 274 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |||
| 275 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| 276 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| 277 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| 278 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| 279 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| 280 | DEALINGS IN THE SOFTWARE. | |||
| 281 | ||||
| 282 | =cut |