File Coverage

blib/lib/YAML/Mo.pm
Criterion Covered Total %
statement 108 136 79.4
branch 44 48 91.6
condition 5 11 45.4
subroutine 28 28 100.0
pod n/a
total 185 223 82.9


line stmt bran cond sub pod time code
1             package YAML::Mo;
2             # use Mo qw[builder default import];
3             # The following line of code was produced from the previous line by
4             # Mo::Inline version 0.4
5 49 100 33 49   1195 no warnings;my$M=__PACKAGE__.'::';*{$M.Object::new}=sub{my$c=shift;my$s=bless{@_},$c;my%n=%{$c.'::'.':E'};map{$s->{$_}=$n{$_}->()if!exists$s->{$_}}keys%n;$s};*{$M.import}=sub{import warnings;$^H|=1538;my($P,%e,%o)=caller.'::';shift;eval"no Mo::$_",&{$M.$_.::e}($P,\%e,\%o,\@_)for@_;return if$e{M};%e=(extends,sub{eval"no $_[0]()";@{$P.ISA}=$_[0]},has,sub{my$n=shift;my$m=sub{$#_?$_[0]{$n}=$_[1]:$_[0]{$n}};@_=(default,@_)if!($#_%2);$m=$o{$_}->($m,$n,@_)for sort keys%o;*{$P.$n}=$m},%e,);*{$P.$_}=$e{$_}for keys%e;@{$P.ISA}=$M.Object};*{$M.'builder::e'}=sub{my($P,$e,$o)=@_;$o->{builder}=sub{my($m,$n,%a)=@_;my$b=$a{builder}or return$m;my$i=exists$a{lazy}?$a{lazy}:!${$P.':N'};$i or ${$P.':E'}{$n}=\&{$P.$b}and return$m;sub{$#_?$m->(@_):!exists$_[0]{$n}?$_[0]{$n}=$_[0]->$b:$m->(@_)}}};*{$M.'default::e'}=sub{my($P,$e,$o)=@_;$o->{default}=sub{my($m,$n,%a)=@_;exists$a{default}or return$m;my($d,$r)=$a{default};my$g='HASH'eq($r=ref$d)?sub{+{%$d}}:'ARRAY'eq$r?sub{[@$d]}:'CODE'eq$r?$d:sub{$d};my$i=exists$a{lazy}?$a{lazy}:!${$P.':N'};$i or ${$P.':E'}{$n}=$g and return$m;sub{$#_?$m->(@_):!exists$_[0]{$n}?$_[0]{$n}=$g->(@_):$m->(@_)}}};my$i=\&import;*{$M.import}=sub{(@_==2 and not$_[1])?pop@_:@_==1?push@_,grep!/import/,@f:();goto&$i};@f=qw[builder default import];use strict;use warnings;
  49 100 33 49   94  
  49 100 33 49   60831  
  49 100   49   443  
  49 100   49   204  
  49 100   48   1710  
  49 100   48   313  
  49 100   48   123  
  49 100   48   4846  
  49 100   48   6766  
  0 100   48   0  
  0 100   48   0  
  49 100   47   5057  
  0 100   47   0  
  0 50   23   0  
  48 100   23   9782  
  0 100   22   0  
  0 50   22   0  
  48     22   5598  
  0     3   0  
  0     3   0  
  48     1   5830  
  0     1   0  
  0     124729   0  
  48         5477  
  0         0  
  0         0  
  48         5536  
  0         0  
  0         0  
  48         5101  
  0         0  
  0         0  
  48         12421  
  2         3  
  2         18  
  47         5157  
  0         0  
  0         0  
  47         718  
  44         126  
  44         621  
  23         2938  
  0         0  
  0         0  
  23         2418  
  2         4  
  2         29  
  22         2640  
  0         0  
  0         0  
  22         2426  
  0         0  
  0         0  
  22         469  
  20         44  
  20         270  
  3         350  
  0         0  
  0         0  
  3         224  
  1         2  
  1         15  
  1         115  
  0         0  
  0         0  
  1         9  
  1         3  
  1         16  
  124729         321039  
  11617         41735  
  16302         63845  
  109314         373115  
  1758         4462  
  2074         25320  
  8255         34506  
  24128         58536  
  921         3851  
  2636         9424  
  14006         51106  
  3195         7829  
  2979         9754  
  3478         13237  
  1797         5625  
  844         2741  
  1088         5761  
  2361         8684  
  921         2341  
  773         5589  
  1073         2363  
  1046         3922  
  1215         5635  
  966         3212  
  1029         3605  
  794         2337  
  812         4337  
  1396         5337  
  649         2921  
  744         2030  
  485         2770  
  1058         3783  
  934         3278  
  818         4280  
  734         2428  
  718         15583  
  557         3878  
  622         2060  
  825         246539  
  744         2682  
  850         2302  
  349         1433  
  733         4367  
  192         1168  
  414         5753  
6              
7             our $DumperModule = 'Data::Dumper';
8              
9             my ($_new_error, $_info, $_scalar_info);
10              
11 49     49   353 no strict 'refs';
  49         119  
  49         43323  
12             *{$M.'Object::die'} = sub {
13 39     39   114 my $self = shift;
14 39         122 my $error = $self->$_new_error(@_);
15 39         122 $error->type('Error');
16 39         199 Carp::croak($error->format_message);
17             };
18              
19             *{$M.'Object::warn'} = sub {
20 7     7   19 my $self = shift;
21 7 50       38 return unless $^W;
22 7         29 my $error = $self->$_new_error(@_);
23 7         26 $error->type('Warning');
24 7         36 Carp::cluck($error->format_message);
25             };
26              
27             # This code needs to be refactored to be simpler and more precise, and no,
28             # Scalar::Util doesn't DWIM.
29             #
30             # Can't handle:
31             # * blessed regexp
32             *{$M.'Object::node_info'} = sub {
33 3846     3846   5856 my $self = shift;
34 3846   100     11904 my $stringify = $_[1] || 0;
35             my ($class, $type, $id) =
36             ref($_[0])
37             ? $stringify
38             ? &$_info("$_[0]")
39 3846 100       8818 : do {
    100          
40 3822         18149 require overload;
41 3822         12348 my @info = &$_info(overload::StrVal($_[0]));
42 3822 100       12277 if (ref($_[0]) eq 'Regexp') {
43 1         5 @info[0, 1] = (undef, 'REGEXP');
44             }
45 3822         11796 @info;
46             }
47             : &$_scalar_info($_[0]);
48 3846 100       8180 ($class, $type, $id) = &$_scalar_info("$_[0]")
49             unless $id;
50 3846 50       13616 return wantarray ? ($class, $type, $id) : $id;
51             };
52              
53             #-------------------------------------------------------------------------------
54             $_info = sub {
55             return (($_[0]) =~ qr{^(?:(.*)\=)?([^=]*)\(([^\(]*)\)$}o);
56             };
57              
58             $_scalar_info = sub {
59             my $id = 'undef';
60             if (defined $_[0]) {
61             \$_[0] =~ /\((\w+)\)$/o or CORE::die();
62             $id = "$1-S";
63             }
64             return (undef, undef, $id);
65             };
66              
67             $_new_error = sub {
68             require Carp;
69             my $self = shift;
70             require YAML::Error;
71              
72             my $code = shift || 'unknown error';
73             my $error = YAML::Error->new(code => $code);
74             $error->line($self->line) if $self->can('line');
75             $error->document($self->document) if $self->can('document');
76             $error->arguments([@_]);
77             return $error;
78             };
79              
80             1;