| 1 | package Text::KDL::XS::Document; | ||||||||||||||||||||||
| 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 | 24 | ▶ | use Text::KDL::XS::Node; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 10 | |||||||||||||||||||||||
| 11 | 24 | our @CARP_NOT = qw( | |||||||||||||||||||||
| 12 | Text::KDL::XS Text::KDL::XS::Emitter Text::KDL::XS::Node | ||||||||||||||||||||||
| 13 | Text::KDL::XS::Parser Text::KDL::XS::Value | ||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||
| 15 | |||||||||||||||||||||||
| 16 | 24 | my %IS_FIELD = (nodes => 1); | |||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | 151 | ▶ | sub new { | ||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||
| 19 | 151 | my ($class, @fields) = @_; | |||||||||||||||||||||
| 20 | 151 | my $fields = Text::KDL::XS::_parse_named_arguments(__PACKAGE__ . '->new', 'field', \%IS_FIELD, @fields); | |||||||||||||||||||||
| 21 | 151 | ▶ | my $nodes = $fields->{nodes} // []; | ||||||||||||||||||||
|
Condition100%2/2
$fields->{"nodes"} // []
MC/DC100%1/1
$fields->{"nodes"} // []
$fields->{"nodes"}
Truth table100%2/2
A
A= $fields->{"nodes"}
| |||||||||||||||||||||||
| 22 | 151 | ▶ | Carp::croak(__PACKAGE__ . "->new: 'nodes' must be an ARRAY reference") | ||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
builtin::reftype($nodes) // ""
MC/DC0%0/1
builtin::reftype($nodes) // ""
builtin::reftype($nodes)
Truth table50%1/2
A
A= builtin::reftype($nodes)
| |||||||||||||||||||||||
| 23 | unless (Scalar::Util::reftype($nodes) // '') eq 'ARRAY'; | ||||||||||||||||||||||
| 24 | 150 | return bless { nodes => $nodes }, $class; | |||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||
| 26 | |||||||||||||||||||||||
| 27 | 121 | ▶ | sub nodes { $_[0]->{nodes} } | ||||||||||||||||||||
|
Subroutine
nodes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 28 | |||||||||||||||||||||||
| 29 | 16 | ▶ | sub as_data { | ||||||||||||||||||||
|
Subroutine
as_data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 30 | 16 | my ($self) = @_; | |||||||||||||||||||||
| 31 | 16 | return [ map { $_->as_data } @{ $self->{nodes} } ]; | |||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||
| 33 | |||||||||||||||||||||||
| 34 | # Builds the document from a parser's events. Slashdashed elements and | ||||||||||||||||||||||
| 35 | # comments, which the parser reports only with emit_comments, carry | ||||||||||||||||||||||
| 36 | # commented => 1 and are not part of the document. | ||||||||||||||||||||||
| 37 | 147 | ▶ | sub _build_from_parser { | ||||||||||||||||||||
|
Subroutine
_build_from_parser: called CC=9 SCAR=22.0
| |||||||||||||||||||||||
| 38 | 147 | my ($class, $parser) = @_; | |||||||||||||||||||||
| 39 | 147 | my $document = $class->new; | |||||||||||||||||||||
| 40 | 147 | my @open_nodes; | |||||||||||||||||||||
| 41 | |||||||||||||||||||||||
| 42 | 147 | ▶ | eval { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 43 | 147 | ▶ | while (defined(my $event = $parser->_next_event)) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 44 | 22156 | ▶ | next if $event->{commented}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 45 | 22133 | my $kind = $event->{event}; | |||||||||||||||||||||
| 46 | |||||||||||||||||||||||
| 47 | 22133 | ▶ | if ($kind eq 'argument') { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 48 | 12173 | push @{ $open_nodes[-1]{args} }, $event->{value}; | |||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||
| 50 | elsif ($kind eq 'property') { | ||||||||||||||||||||||
| 51 | 44 | push @{ $open_nodes[-1]{props} }, [ $event->{name}, $event->{value} ]; | |||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||
| 53 | elsif ($kind eq 'start_node') { | ||||||||||||||||||||||
| 54 | 5227 | my $node = Text::KDL::XS::Node->_new_parsed($event->{name}, $event->{type}); | |||||||||||||||||||||
| 55 | 5227 | ▶ | push @{ @open_nodes ? $open_nodes[-1]{children} : $document->{nodes} }, $node; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 56 | 5227 | push @open_nodes, $node; | |||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||
| 58 | elsif ($kind eq 'end_node') { | ||||||||||||||||||||||
| 59 | 4689 | pop @open_nodes; | |||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||
| 61 | else { | ||||||||||||||||||||||
| 62 | 0 | Carp::croak(__PACKAGE__ . ": unexpected parser event '$kind'"); | |||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||
| 65 | 120 | 1; | |||||||||||||||||||||
| 66 | } or Text::KDL::XS::_rethrow($@, __FILE__); | ||||||||||||||||||||||
| 67 | |||||||||||||||||||||||
| 68 | 120 | return $document; | |||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||
| 70 | |||||||||||||||||||||||
| 71 | 24 | 1; | |||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||