File Coverage

blib/lib/YAML.pm
Criterion Covered Total %
statement 58 61 95.0
branch 14 20 70.0
condition 1 3 33.3
subroutine 14 14 100.0
pod 6 8 75.0
total 93 106 87.7


line stmt bran cond sub pod time code
1             package YAML;
2             our $VERSION = '1.30';
3              
4 48     48   1660116 use YAML::Mo;
  48         111  
  48         217  
5              
6 48     48   272 use Exporter;
  48         78  
  48         8720  
7             push @YAML::ISA, 'Exporter';
8             our @EXPORT = qw{ Dump Load };
9             our @EXPORT_OK = qw{ freeze thaw DumpFile LoadFile Bless Blessed };
10             our (
11             $UseCode, $DumpCode, $LoadCode,
12             $SpecVersion,
13             $UseHeader, $UseVersion, $UseBlock, $UseFold, $UseAliases,
14             $Indent, $SortKeys, $Preserve,
15             $AnchorPrefix, $CompressSeries, $InlineSeries, $Purity,
16             $Stringify, $Numify, $LoadBlessed, $QuoteNumericStrings,
17             $DumperClass, $LoaderClass
18             );
19              
20 48     48   16223 use YAML::Node; # XXX This is a temp fix for Module::Build
  48         106  
  48         2374  
21 48     48   277 use Scalar::Util qw/ openhandle /;
  48         77  
  48         2464  
22              
23             # XXX This VALUE nonsense needs to go.
24 48     48   259 use constant VALUE => "\x07YAML\x07VALUE\x07";
  48         75  
  48         12365  
25              
26             # YAML Object Properties
27             has dumper_class => default => sub {'YAML::Dumper'};
28             has loader_class => default => sub {'YAML::Loader'};
29             has dumper_object => default => sub {$_[0]->init_action_object("dumper")};
30             has loader_object => default => sub {$_[0]->init_action_object("loader")};
31              
32             sub Dump {
33 158     158 1 192676 my $yaml = YAML->new;
34 158 50       434 $yaml->dumper_class($YAML::DumperClass)
35             if $YAML::DumperClass;
36 158         389 return $yaml->dumper_object->dump(@_);
37             }
38              
39             sub Load {
40 321     321 1 403430 my $yaml = YAML->new;
41 321 50       847 $yaml->loader_class($YAML::LoaderClass)
42             if $YAML::LoaderClass;
43 321         701 return $yaml->loader_object->load(@_);
44             }
45              
46             {
47 48     48   315 no warnings 'once';
  48         88  
  48         25325  
48             # freeze/thaw is the API for Storable string serialization. Some
49             # modules make use of serializing packages on if they use freeze/thaw.
50             *freeze = \ &Dump;
51             *thaw = \ &Load;
52             }
53              
54             sub DumpFile {
55 5     5 1 8647 my $OUT;
56 5         30 my $filename = shift;
57 5 100       68 if (openhandle $filename) {
58 2         17 $OUT = $filename;
59             }
60             else {
61 3         7 my $mode = '>';
62 3 50       18 if ($filename =~ /^\s*(>{1,2})\s*(.*)$/) {
63 0         0 ($mode, $filename) = ($1, $2);
64             }
65 3 100       289 open $OUT, $mode, $filename
66             or YAML::Mo::Object->die('YAML_DUMP_ERR_FILE_OUTPUT', $filename, "$!");
67             }
68 4         50 binmode $OUT, ':utf8'; # if $Config{useperlio} eq 'define';
69 4         50 local $/ = "\n"; # reset special to "sane"
70 4         44 print $OUT Dump(@_);
71 4 50       57 unless (ref $filename eq 'GLOB') {
72             close $OUT
73 4 50       245 or do {
74 0         0 my $errsav = $!;
75 0         0 YAML::Mo::Object->die('YAML_DUMP_ERR_FILE_OUTPUT_CLOSE', $filename, $errsav);
76             }
77             }
78             }
79              
80             sub LoadFile {
81 5     5 1 5429 my $IN;
82 5         26 my $filename = shift;
83 5 100       39 if (openhandle $filename) {
84 2         9 $IN = $filename;
85             }
86             else {
87 3 100       118 open $IN, '<', $filename
88             or YAML::Mo::Object->die('YAML_LOAD_ERR_FILE_INPUT', $filename, "$!");
89             }
90 4         38 binmode $IN, ':utf8'; # if $Config{useperlio} eq 'define';
91 4         8 return Load(do { local $/; <$IN> });
  4         27  
  4         17193  
92             }
93              
94             sub init_action_object {
95 479     479 0 705 my $self = shift;
96 479         729 my $object_class = (shift) . '_class';
97 479         1082 my $module_name = $self->$object_class;
98 479         21292 eval "require $module_name";
99 479 50 33     1781 $self->die("Error in require $module_name - $@")
100             if $@ and "$@" !~ /Can't locate/;
101 479         1490 my $object = $self->$object_class->new;
102 479         1537 $object->set_global_options;
103 479         1724 return $object;
104             }
105              
106             my $global = {};
107             sub Bless {
108 4     4 1 4833 require YAML::Dumper::Base;
109 4         13 YAML::Dumper::Base::bless($global, @_)
110             }
111             sub Blessed {
112 1     1 1 7 require YAML::Dumper::Base;
113 1         5 YAML::Dumper::Base::blessed($global, @_)
114             }
115 509     509 0 1118 sub global_object { $global }
116              
117             1;