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

filter: Statementstmt 98.0% 50 / 51 Branchbran 94.4% 17 / 18 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 95.4% 84 / 88 CC 12 SCAR 16.1
CC
12
Cov
96%
_build_from_parser
9.0
new
4.0
BEGIN
1.0
CRAP 5.0
« blib/lib/Text/KDL/XS/Value.pm ↑ Summary blib/lib/Text/KDL/XS/Parser.pm »
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"} // []
l!l
3148
MC/DC100%1/1
$fields->{"nodes"} // []
$fields->{"nodes"}
Truth table100%2/2
A
A= $fields->{"nodes"}
Aresult
11
00
22 151 ▶ Carp::croak(__PACKAGE__ . "->new: 'nodes' must be an ARRAY reference")
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::reftype($nodes) // "") eq "ARRAY" 1 150 151
Condition50%1/2
builtin::reftype($nodes) // ""
l!l
1510
MC/DC0%0/1
builtin::reftype($nodes) // ""
builtin::reftype($nodes)
Truth table50%1/2
A
A= builtin::reftype($nodes)
Aresult
11
00
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
BranchTrueFalseTotal
eval { do { while (defined(my $event = $parser->_next_event)) { do { next if $event->{"commented"}; my $kind = $event->{"event"}; if ($kind eq "argument") { push @{$open_nodes[-1]{"args"};}, $event->{"value"}; } elsif ($kind eq "property") { push @{$open_nodes[-1]{"props"};}, [$event->{"name"}, $event->{"value"}]; } elsif ($kind eq "start_node") { my $node = "Text::KDL::XS::Node"->_new_parsed($event->{"name"}, $event->{"type"}); push @{@open_nodes ? $open_nodes[-1]{"children"} : $$document{"nodes"};}, $node; push @open_nodes, $node; } elsif ($kind eq "end_node") { pop @open_nodes; } else { Carp::croak('Text::KDL::XS::Document' . ": unexpected parser event '${kind}'"); } }; } ; 1 } } or Text::KDL::XS::_rethrow($@, __FILE__) 120 27 147
43 147 ▶ while (defined(my $event = $parser->_next_event)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $event = $parser->_next_event)) 22156 120 22276
44 22156 ▶ next if $event->{commented};
Branch: 1 branch
BranchTrueFalseTotal
if $event->{"commented"} 23 22133 22156
45 22133 my $kind = $event->{event};
46  
47 22133 ▶ if ($kind eq 'argument') {
Branch: 4 branches
BranchTrueFalseTotal
if ($kind eq 'argument') { } 12173 9960 22133
elsif ($kind eq 'property') { } 44 9916 9960
elsif ($kind eq 'start_node') { } 5227 4689 9916
elsif ($kind eq 'end_node') { } 4689 0 4689
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
BranchTrueFalseTotal
@open_nodes ? : 3043 2184 5227
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__
« blib/lib/Text/KDL/XS/Value.pm ↑ Summary blib/lib/Text/KDL/XS/Parser.pm »