| 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
| |||||||||||||||||||||||||||||||||
| 22 | 53 | for my $list (qw(args props children)) { | |||||||||||||||||||||||||||||||
| 23 | 156 | ▶ | next unless defined $fields->{$list}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 24 | Carp::croak(__PACKAGE__ . "->new: '$list' must be an ARRAY reference") | ||||||||||||||||||||||||||||||||
| 25 | 83 | ▶ | unless (Scalar::Util::reftype($fields->{$list}) // '') eq 'ARRAY'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
builtin::reftype($fields->{$list}) // ""
MC/DC0%0/1
builtin::reftype($fields->{$list}) // ""
builtin::reftype($fields->{$list})
Truth table50%1/2
A
A= builtin::reftype($fields->{$list})
| |||||||||||||||||||||||||||||||||
| 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"} // []
$fields->{"props"} // []
$fields->{"children"} // []
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"}
Truth table100%2/2
A
A= $fields->{"props"}
Truth table100%2/2
A
A= $fields->{"children"}
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 61 | 12 | for my $property (reverse @{ $self->{props} }) { | |||||||||||||||||||||||||||||||
| 62 | 14 | ▶ | return $property->[1] if $property->[0] eq $key; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
builtin::blessed($value) and $value->isa("Text::KDL::XS::Value")
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")
| |||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 24 | 1; | |||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||||||