blib/lib/YATT/Lite/Constants.pm

filter: Statementstmt 80.5% 62 / 77 Branchbran 54.1% 13 / 24 Conditioncond 71.4% 10 / 14 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 80.0% 20 / 25 Podpod 0.0% 0 / 19 totaltotal 64.2% 106 / 165 CC 19 SCAR 14.8
CC
19
Cov
74%
node_as_hash
20.0
node_unwrap_attlist
7.1
node_body_slot
4.2
CRAP 4.4
« blib/lib/YATT/Lite/Partial.pm ↑ Summary blib/lib/YATT/Lite/NSBuilder.pm »
1 package YATT::Lite::Constants;
2 49 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 49 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 49 ▶use 5.010; no if $] >= 5.017011, warnings => "experimental";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 49 require Carp;
7  
8 #========================================
9 # 今回は LRXML の serializability を捨てる
10 use YATT::Lite::Util::Enum
11 49 ▶ (TYPE_ => [qw(LINEINFO COMMENT
Subroutine BEGIN: called CC=1 SCAR=0.0
12 LCMSG
13 ENTITY PI ELEMENT
14 ATTRIBUTE=ATT_NAMEONLY ATT_BARENAME ATT_TEXT ATT_NESTED
15 ATT_MACRO=DECL_ENTITY)]
16 , NODE_ => [qw(TYPE BEGIN END LNO
17 SYM_END
18 BODY_BEGIN BODY_END
19 PATH REST=VALUE=BODY ATTLIST
20 AELEM_HEAD AELEM_FOOT)]
21 # node item
22 # BODY が必ず配列になるが、代わりに @attlist は配列不要に。 空の [] を pad しなくて済む
23 # XXX: <:yatt:else /> とかもあったじゃん!
24  
25 , ENT_ => [qw(TYPE KEY REST=VALUE=BODY)]
26 49 );
27  
28 # Not worked. why?
29 # BEGIN {
30 # push our @EXPORT_OK, qw/*TYPE_ *NODE_/;
31 # }
32  
33 280 ▶sub cut_first (&@) {
Subroutine cut_first: called CC=3 SCAR=11.2
Pod undocumented
34 280 my ($code, $list) = @_;
35 280 local $_;
36 280 ▶ for (my $i = 0; $i < @$list; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$list) 280 0 280
37 280 $_ = $list->[$i];
38 280 ▶ next unless $code->($_);
Branch: 1 branch
BranchTrueFalseTotal
unless &$code($_) 0 280 280
39 280 splice @$list, $i, 1;
40 280 return $_;
41 }
42 }
43  
44 280 ▶sub cut_first_att {
Subroutine cut_first_att: called CC=1 SCAR=0.0
Pod undocumented
45 280 my ($list) = @_;
46 280 ▶ cut_first {$_->[NODE_TYPE] >= TYPE_ATTRIBUTE} $list;
Subroutine __ANON__: called CC=1 SCAR=0.0
47 }
48  
49 # node expand.
50 994 ▶sub nx {
Subroutine nx: called CC=2 SCAR=6.9
Pod undocumented
51 994 ▶ @{$_[0]}[(NODE_PATH + ($_[1] // 0)) .. $#{$_[0]}];
Condition100%2/2
$_[1] // 0
l!l
60934
MC/DC100%1/1
$_[1] // 0
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
52 }
53 1499 ▶sub bar_escape ($) {
Subroutine bar_escape: called CC=2 SCAR=7.4
Pod undocumented
54 1499 ▶ unless (defined $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0]) 0 1499 1499
55 0 Carp::confess "Undefined text";
56 }
57 1499 my $cp = shift;
58 1499 $cp =~ s{([\|\\])}{\\$1}g;
59 1499 $cp;
60 }
61 1499 ▶sub qtext ($) {
Subroutine qtext: called CC=1 SCAR=0.0
Pod undocumented
62 1499 'q|'.bar_escape($_[0]).'|'
63 }
64 418 ▶sub qqvalue ($) {
Subroutine qqvalue: called CC=1 SCAR=0.0
Pod undocumented
65 418 'q'.qtext($_[0]);
66 }
67  
68 18 ▶sub node_type { $_[1]->[NODE_TYPE] }
Subroutine node_type: called CC=1 SCAR=0.0
Pod undocumented
69 18 ▶sub node_path { $_[1]->[NODE_PATH] }
Subroutine node_path: called CC=1 SCAR=0.0
Pod undocumented
70 0 ▶sub node_attlist { $_[1]->[NODE_ATTLIST] }
Subroutine node_attlist: not called CC=1 SCAR=6.9
Pod undocumented
71  
72 0 ▶sub node_has_name_list {
Subroutine node_has_name_list: not called CC=1 SCAR=6.9
Pod undocumented
73 0 array_of_array($_[1][NODE_PATH]);
74 }
75 301 ▶sub array_of_array {
Subroutine array_of_array: called CC=2 SCAR=6.9
Pod undocumented
76 301 my ($path) = @_;
77 301 ▶ ref $path eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
ref $path eq "ARRAY" and ref $path->[0] eq "ARRAY" 30 271 301
78 && ref $path->[0] eq 'ARRAY'
79 }
80  
81 0 ▶sub node_body {
Subroutine node_body: not called CC=1 SCAR=6.9
Pod undocumented
82 0 shift->node_value(@_);
83 }
84  
85 96 ▶sub node_body_slot {
Subroutine node_body_slot: called CC=4 SCAR=14.5
Pod undocumented
86 96 my ($self, $node) = @_;
87 96 my $type = $node->[NODE_TYPE];
88 96 ▶ if ($type == TYPE_ELEMENT) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type == 5) { } 87 9 96
elsif ($type == 9) { } 9 0 9
89 87 ▶ return $node->[NODE_BODY][NODE_VALUE] if defined $node->[NODE_BODY];
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->[8] 87 0 87
90 }
91 elsif ($type == TYPE_ATT_NESTED) {
92 9 return $node->[NODE_VALUE];
93 }
94 else {
95 0 die "Invalid node type for node_body_slot: $type";
96 }
97 }
98  
99 211 ▶sub node_unwrap_attlist {
Subroutine node_unwrap_attlist: called CC=6 SCAR=19.6
Pod undocumented
100 211 my ($self, $maybeWrappedAttlist) = @_;
101 211 ▶ if ($maybeWrappedAttlist
Branch: 1 branch
BranchTrueFalseTotal
if ($maybeWrappedAttlist and @$maybeWrappedAttlist == 1 and ref $maybeWrappedAttlist->[0] eq 'ARRAY' and @{$maybeWrappedAttlist->[0];} == 1 and ref $maybeWrappedAttlist->[0][0] eq 'ARRAY') { } 0 211 211
Condition66%8/12
$maybeWrappedAttlist and @$maybeWrappedAttlist == 1 and ref $maybeWrappedAttlist->[0] eq "ARRAY" and @{$maybeWrappedAttlist->[0];} == 1 and ref $maybeWrappedAttlist->[0][0] eq "ARRAY"
!ll&&!rl&&r
21100
$maybeWrappedAttlist and @$maybeWrappedAttlist == 1 and ref $maybeWrappedAttlist->[0] eq "ARRAY" and @{$maybeWrappedAttlist->[0];} == 1
!ll&&!rl&&r
731380
$maybeWrappedAttlist and @$maybeWrappedAttlist == 1 and ref $maybeWrappedAttlist->[0] eq "ARRAY"
!ll&&!rl&&r
730138
$maybeWrappedAttlist and @$maybeWrappedAttlist == 1
!ll&&!rl&&r
5815138
MC/DC0%0/5
$maybeWrappedAttlist and @$maybeWrappedAttlist == 1 and ref $maybeWrappedAttlist->[0] eq "ARRAY" and @{$maybeWrappedAttlist->[0];} == 1 and ref $maybeWrappedAttlist->[0][0] eq "ARRAY"
$maybeWrappedAttlist @$maybeWrappedAttlist == 1 ref $maybeWrappedAttlist->[0] eq "ARRAY" @{$maybeWrappedAttlist->[0];} == 1 ref $maybeWrappedAttlist->[0][0] eq "ARRAY"
Truth table50%3/6
A and B and C and D and E
A= $maybeWrappedAttlistB= @$maybeWrappedAttlist == 1C= ref $maybeWrappedAttlist->[0] eq "ARRAY"D= @{$maybeWrappedAttlist->[0];} == 1E= ref $maybeWrappedAttlist->[0][0] eq "ARRAY"
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
102 and @$maybeWrappedAttlist == 1
103 and ref $maybeWrappedAttlist->[0] eq 'ARRAY'
104 138 and @{$maybeWrappedAttlist->[0]} == 1
105 and ref $maybeWrappedAttlist->[0][0] eq 'ARRAY') {
106 0 $maybeWrappedAttlist->[0]
107 } else {
108 211 $maybeWrappedAttlist;
109 }
110 }
111  
112 26 ▶sub node_value {
Subroutine node_value: called CC=2 SCAR=7.2
Pod undocumented
113 26 my ($self, $node) = @_;
114 26 ▶ wantarray ? YATT::Lite::Util::lexpand($node->[NODE_VALUE])
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 26 26
115 : $node->[NODE_VALUE];
116 }
117  
118 0 ▶sub node_extract {
Subroutine node_extract: not called CC=1 SCAR=6.9
Pod undocumented
119 0 my ($self, $node) = splice @_, 0, 2;
120 0 nx($node, @_);
121 }
122  
123 0 ▶sub node_as_hash {
Subroutine node_as_hash: not called CC=4 SCAR=30.0
Pod undocumented
124 0 my ($self, $node) = @_;
125  
126 0 my $hash;
127 0 foreach my $k (qw(TYPE
128 PATH BODY ATTLIST
129 AELEM_HEAD AELEM_FOOT)) {
130 0 my $i = __PACKAGE__->can("NODE_$k")->();
131 0 ▶ next if $#$node <= $i;
Branch: 1 branch
BranchTrueFalseTotal
if $node->$#* <= $i 0 0 0
132 0 ▶ $hash->{lc($k)} = $node->[$i] if defined $node->[$i];
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->[$i] 0 0 0
133 }
134 0 $hash;
135 }
136  
137 #========================================
138 # Entity entpath related wrappers.
139 # Each element in entpath has its own structure.
140  
141 111 ▶sub entx {
Subroutine entx: called CC=1 SCAR=0.0
Pod undocumented
142 111 my ($ent) = @_;
143 111 @{$ent}[ENT_BODY..$#$ent];
144 }
145  
146 # list expand if nested.
147 1228 ▶sub lxnest {
Subroutine lxnest: called CC=2 SCAR=6.9
Pod undocumented
148 1228 ▶ ref $_[0][0] ? @{$_[0]} : $_[0]
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0][0] ? : 17 1211 1228
149 }
150  
151 #========================================
152 49 my $symtab = YATT::Lite::Util::symtab(__PACKAGE__);
153 49 our @EXPORT = grep {*{$symtab->{$_}}{CODE}} keys %$symtab;
154 49 our @EXPORT_OK = @EXPORT;
155  
156 49 require Exporter;
157 49 import Exporter qw(import);
158  
159 49 1;
« blib/lib/YATT/Lite/Partial.pm ↑ Summary blib/lib/YATT/Lite/NSBuilder.pm »