blib/lib/Text/KDL/XS/Node.pm

filter: Statementstmt 100% 52 / 52 Branchbran 100% 12 / 12 Conditioncond 81.8% 9 / 11 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 16 / 16 Podpod 100% 8 / 8 totaltotal 96.1% 101 / 105 CC 14 SCAR 14.1
CC
14
Cov
97%
new
9.0
prop
4.0
_perl_value
3.0
CRAP 4.1
« blib/lib/Text/KDL/XS/Parser.pm ↑ Summary blib/lib/Text/KDL/XS.pm »
1 package Text::KDL::XS::Node;
2  
3 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 24 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 24 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 24 ▶use Text::KDL::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 24 our @CARP_NOT = qw(
11 Text::KDL::XS Text::KDL::XS::Document Text::KDL::XS::Emitter
12 Text::KDL::XS::Parser Text::KDL::XS::Value
13 );
14  
15 24 my %IS_FIELD = map { $_ => 1 } qw(name type_annotation args props children);
16  
17 57 ▶sub new {
Subroutine new: called CC=9 SCAR=22.0
Pod documented
18 57 my ($class, @fields) = @_;
19 57 my $fields = Text::KDL::XS::_parse_named_arguments(__PACKAGE__ . '->new', 'field', \%IS_FIELD, @fields);
20  
21 55 ▶ Carp::croak(__PACKAGE__ . "->new: 'name' is required") unless defined $fields->{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fields->{"name"} 2 53 55
22 53 for my $list (qw(args props children)) {
23 156 ▶ next unless defined $fields->{$list};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fields->{$list} 73 83 156
24 Carp::croak(__PACKAGE__ . "->new: '$list' must be an ARRAY reference")
25 83 ▶ unless (Scalar::Util::reftype($fields->{$list}) // '') eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::reftype($fields->{$list}) // "") eq "ARRAY" 3 80 83
Condition50%1/2
builtin::reftype($fields->{$list}) // ""
l!l
830
MC/DC0%0/1
builtin::reftype($fields->{$list}) // ""
builtin::reftype($fields->{$list})
Truth table50%1/2
A
A= builtin::reftype($fields->{$list})
Aresult
11
00
26 }
27  
28 return bless {
29 name => $fields->{name},
30 type_annotation => $fields->{type_annotation},
31 args => $fields->{args} // [],
32 props => $fields->{props} // [],
33 50 ▶ children => $fields->{children} // [],
Condition100%6/6
$fields->{"args"} // []
l!l
3911
$fields->{"props"} // []
l!l
3911
$fields->{"children"} // []
l!l
248
MC/DC100%1/1
$fields->{"args"} // []
$fields->{"args"}
MC/DC100%1/1
$fields->{"props"} // []
$fields->{"props"}
MC/DC100%1/1
$fields->{"children"} // []
$fields->{"children"}
Truth table100%2/2
A
A= $fields->{"args"}
Aresult
11
00
Truth table100%2/2
A
A= $fields->{"props"}
Aresult
11
00
Truth table100%2/2
A
A= $fields->{"children"}
Aresult
11
00
34 }, $class;
35 }
36  
37 # The constructor used by the tree builder, which only ever passes a name and
38 # an optional type annotation that the parser has already validated.
39 5227 ▶sub _new_parsed {
Subroutine _new_parsed: called CC=1 SCAR=0.0
40 5227 my ($class, $name, $type_annotation) = @_;
41 5227 return bless {
42 name => $name,
43 type_annotation => $type_annotation,
44 args => [],
45 props => [],
46 children => [],
47 }, $class;
48 }
49  
50 177 ▶sub name { $_[0]->{name} }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
51 115 ▶sub type_annotation { $_[0]->{type_annotation} }
Subroutine type_annotation: called CC=1 SCAR=0.0
Pod documented
52 183 ▶sub args { $_[0]->{args} }
Subroutine args: called CC=1 SCAR=0.0
Pod documented
53 116 ▶sub props { $_[0]->{props} }
Subroutine props: called CC=1 SCAR=0.0
Pod documented
54 85 ▶sub children { $_[0]->{children} }
Subroutine children: called CC=1 SCAR=0.0
Pod documented
55  
56 # The value of the rightmost property named $key, as the KDL specification
57 # requires for repeated keys.
58 13 ▶sub prop {
Subroutine prop: called CC=4 SCAR=13.9
Pod documented
59 13 my ($self, $key) = @_;
60 13 ▶ Carp::croak(__PACKAGE__ . "::prop: key is required") unless defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 1 12 13
61 12 for my $property (reverse @{ $self->{props} }) {
62 14 ▶ return $property->[1] if $property->[0] eq $key;
Branch: 1 branch
BranchTrueFalseTotal
if $property->[0] eq $key 10 4 14
63 }
64 2 return undef;
65 }
66  
67 29 ▶sub as_data {
Subroutine as_data: called CC=1 SCAR=0.0
Pod documented
68 29 my ($self) = @_;
69 24 ▶ no warnings 'recursion'; # the parser's max_depth bounds the nesting
Subroutine BEGIN: called CC=1 SCAR=0.0
70 return {
71 name => $self->{name},
72 type => $self->{type_annotation},
73 28 args => [ map { _perl_value($_) } @{ $self->{args} } ],
74 7 props => { map { $_->[0] => _perl_value($_->[1]) } @{ $self->{props} } },
75 29 children => [ map { $_->as_data } @{ $self->{children} } ],
76 };
77 }
78  
79 # Value objects become their natural Perl scalar; plain scalars in hand-built
80 # nodes are already one.
81 35 ▶sub _perl_value {
Subroutine _perl_value: called CC=3 SCAR=11.1
82 35 my ($value) = @_;
83 35 ▶ return Scalar::Util::blessed($value) && $value->isa('Text::KDL::XS::Value') ? $value->as_perl : $value;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($value) && $value->isa('Text::KDL::XS::Value') ? : 31 4 35
Condition66%2/3
builtin::blessed($value) and $value->isa("Text::KDL::XS::Value")
!ll&&!rl&&r
4031
MC/DC50%1/2
builtin::blessed($value) and $value->isa("Text::KDL::XS::Value")
builtin::blessed($value) $value->isa("Text::KDL::XS::Value")
Truth table66%2/3
A and B
A= builtin::blessed($value)B= $value->isa("Text::KDL::XS::Value")
ABresult
0X0
100
111
84 }
85  
86 24 1;
87  
88 __END__
« blib/lib/Text/KDL/XS/Parser.pm ↑ Summary blib/lib/Text/KDL/XS.pm »