File Coverage

blib/lib/YAML/Old/Dumper/Base.pm
Criterion Covered Total %
statement 48 50 96.0
branch 35 46 76.0
condition 5 6 83.3
subroutine 6 7 85.7
pod 0 4 0.0
total 94 113 83.1


line stmt bran cond sub pod time code
1             package YAML::Old::Dumper::Base;
2              
3 32     32   178 use YAML::Old::Mo;
  32         61  
  32         174  
4              
5 32     32   779 use YAML::Old::Node;
  32         95  
  32         20515  
6              
7             # YAML Dumping options
8             has spec_version => default => sub {'1.0'};
9             has indent_width => default => sub {2};
10             has use_header => default => sub {1};
11             has use_version => default => sub {0};
12             has sort_keys => default => sub {1};
13             has anchor_prefix => default => sub {''};
14             has dump_code => default => sub {0};
15             has use_block => default => sub {0};
16             has use_fold => default => sub {0};
17             has compress_series => default => sub {1};
18             has inline_series => default => sub {0};
19             has use_aliases => default => sub {1};
20             has purity => default => sub {0};
21             has stringify => default => sub {0};
22             has quote_numeric_strings => default => sub {0};
23              
24             # Properties
25             has stream => default => sub {''};
26             has document => default => sub {0};
27             has transferred => default => sub {{}};
28             has id_refcnt => default => sub {{}};
29             has id_anchor => default => sub {{}};
30             has anchor => default => sub {1};
31             has level => default => sub {0};
32             has offset => default => sub {[]};
33             has headless => default => sub {0};
34             has blessed_map => default => sub {{}};
35              
36             # Global Options are an idea taken from Data::Dumper. Really they are just
37             # sugar on top of real OO properties. They make the simple Dump/Load API
38             # easy to configure.
39             sub set_global_options {
40 149     149 0 261 my $self = shift;
41 149 50       418 $self->spec_version($YAML::SpecVersion)
42             if defined $YAML::SpecVersion;
43 149 100       371 $self->indent_width($YAML::Indent)
44             if defined $YAML::Indent;
45 149 100       359 $self->use_header($YAML::UseHeader)
46             if defined $YAML::UseHeader;
47 149 50       375 $self->use_version($YAML::UseVersion)
48             if defined $YAML::UseVersion;
49 149 100       354 $self->sort_keys($YAML::SortKeys)
50             if defined $YAML::SortKeys;
51 149 50       351 $self->anchor_prefix($YAML::AnchorPrefix)
52             if defined $YAML::AnchorPrefix;
53 149 100 66     761 $self->dump_code($YAML::DumpCode || $YAML::UseCode)
      100        
54             if defined $YAML::DumpCode or defined $YAML::UseCode;
55 149 100       366 $self->use_block($YAML::UseBlock)
56             if defined $YAML::UseBlock;
57 149 50       398 $self->use_fold($YAML::UseFold)
58             if defined $YAML::UseFold;
59 149 100       355 $self->compress_series($YAML::CompressSeries)
60             if defined $YAML::CompressSeries;
61 149 100       349 $self->inline_series($YAML::InlineSeries)
62             if defined $YAML::InlineSeries;
63 149 100       343 $self->use_aliases($YAML::UseAliases)
64             if defined $YAML::UseAliases;
65 149 50       340 $self->purity($YAML::Purity)
66             if defined $YAML::Purity;
67 149 100       345 $self->stringify($YAML::Stringify)
68             if defined $YAML::Stringify;
69 149 100       469 $self->quote_numeric_strings($YAML::QuoteNumericStrings)
70             if defined $YAML::QuoteNumericStrings;
71             }
72              
73             sub dump {
74 0     0 0 0 my $self = shift;
75 0         0 $self->die('dump() not implemented in this class.');
76             }
77              
78             sub blessed {
79 1     1 0 2 my $self = shift;
80 1         4 my ($ref) = @_;
81 1 50       4 $ref = \$_[0] unless ref $ref;
82 1         5 my (undef, undef, $node_id) = YAML::Old::Mo::Object->node_info($ref);
83 1         15 $self->{blessed_map}->{$node_id};
84             }
85              
86             sub bless {
87 4     4 0 8 my $self = shift;
88 4         9 my ($ref, $blessing) = @_;
89 4         7 my $ynode;
90 4 50       13 $ref = \$_[0] unless ref $ref;
91 4         15 my (undef, undef, $node_id) = YAML::Old::Mo::Object->node_info($ref);
92 4 100       16 if (not defined $blessing) {
    100          
93 2         8 $ynode = YAML::Old::Node->new($ref);
94             }
95             elsif (ref $blessing) {
96 1 50       4 $self->die() unless ynode($blessing);
97 1         3 $ynode = $blessing;
98             }
99             else {
100 32     32   210 no strict 'refs';
  32         67  
  32         3709  
101 1         4 my $transfer = $blessing . "::yaml_dump";
102 1 50       2 $self->die() unless defined &{$transfer};
  1         10  
103 1         3 $ynode = &{$transfer}($ref);
  1         18  
104 1 50       7 $self->die() unless ynode($ynode);
105             }
106 4         12 $self->{blessed_map}->{$node_id} = $ynode;
107 4 50       10 my $object = ynode($ynode) or $self->die();
108 4         46 return $object;
109             }
110              
111             1;