blib/lib/YATT/Lite/LanguageServer/Spec2Types.pm

filter: Statementstmt 11.7% 24 / 204 Branchbran 1.0% 1 / 98 Conditioncond 0.0% 0 / 41 MC/DCmcdc 0.0% 0 / 24 Subroutinesub 26.0% 6 / 23 Podpod 0.0% 0 / 15 totaltotal 7.6% 31 / 405 CC 70 SCAR 50.0
CC
70
Cov
7%
spec_dependency_of__interface
506.0
spec_dependency_of__namespace
110.0
spec_dependency_of
72.0
CRAP 148.8
« blib/lib/YATT/Lite/Test/XHFTest2.pm ↑ Summary blib/lib/YATT/Lite/Walker.pm »
1 #!/usr/bin/env perl
2 package YATT::Lite::LanguageServer::Spec2Types;
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use File::AddInc;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use MOP4Import::Base::CLI_JSON -as_base
Subroutine BEGIN: called CC=1 SCAR=4.1
7 , [fields =>
8 [with_field_docs => doc => "generate field document too"],
9 [with_field_typeinfos => doc => "generate field typeinfo too"],
10 ]
11 0 ▶ , [output_format => pairlist => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
12 0 my ($self, $outFH, @args) = @_;
13 0 require Data::Dumper;
14 0 foreach my $list (@args) {
15 0 my @list = @$list;
16 0 ▶ while (my ($k, $v) = splice @list, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@list, 0, 2)) 0 0 0
17 # Data::Dumper always quotes numbers but it is not ideal for JSON.
18 0 my $vd = join("", _toy_dump_numeric_as_is($v, 0));
19 0 print $outFH do {
20 0 ▶ defined $k ? MOP4Import::Util::terse_dump($k) : "undef()";
Branch: 1 branch
BranchTrueFalseTotal
defined $k ? : 0 0 0
21 }, " => $vd";
22 }
23 }
24 1 }];
25  
26 1 ▶use YATT::Lite::LanguageServer::SpecParser qw/Interface Decl Annotated/
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 , [as => 'SpecParser'];
28  
29 # % parser=./Lite/LanguageServer/SpecParser.pm
30 # % ./Lite/LanguageServer/Spec2Types.pm --output=indented make_spec_from "$(
31 # $parser extract_codeblock typescript $specFn|
32 # $parser cli_xargs_json extract_statement_list|
33 # grep -v 'interface ParameterInformation'|
34 # $parser cli_xargs_json --slurp tokenize_statement_list|
35 # $parser --flatten=0 cli_xargs_json --slurp parse_statement_list
36 # )" Message
37 # 'Message'
38 # [
39 # [
40 # 'fields',
41 # 'jsonrpc'
42 # ]
43 # ]
44  
45 use MOP4Import::Types
46 1 ▶ CollectedItem => [
Subroutine BEGIN: called CC=1 SCAR=0.0
47 [fields => qw/kind name spec items parent subtypes dependency/]
48 1 ];
49  
50 0 ▶sub make_typedefs_from {
Subroutine make_typedefs_from: not called CC=3 SCAR=24.8
Pod undocumented
51 0 (my MY $self, my ($specDictOrArrayOrFile, @names)) = @_;
52 0 my $specDict = $self->specdict_from($specDictOrArrayOrFile);
53 0 my $collectedDict = $self->collect_spec_from($specDict, @names);
54 0 my %seen;
55 my @result = map {
56 0 my CollectedItem $item = $_;
57 0 ▶ if ($seen{$item->{name}}++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seen{$item->{'name'}}++) { } 0 0 0
58 ()
59 0 } else {
60 0 $self->typedefs_of_collected_item($item, \%seen);
61 }
62 } $self->reorder_collected_items($collectedDict);
63 0 ▶ wantarray ? @result : \@result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
64 }
65  
66 0 ▶sub reorder_collected_items {
Subroutine reorder_collected_items: not called CC=4 SCAR=30.0
Pod undocumented
67 0 (my MY $self, my ($collectedDict)) = @_;
68 0 my (@result, %seen, $lastKeys);
69 0 $lastKeys = keys %$collectedDict;
70 0 ▶ while (keys %$collectedDict) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$collectedDict) 0 0 0
71 my @ready = sort(grep {
72 0 my CollectedItem $item = $collectedDict->{$_};
73 not $item->{parent}
74 0 ▶ or $seen{$item->{parent}};
Condition0%0/3
!$item->{'parent'} || $seen{$item->{'parent'}}
l!l&&r!l&&!r
000
MC/DC0%0/2
!$item->{'parent'} || $seen{$item->{'parent'}}
!$item->{'parent'} $seen{$item->{'parent'}}
Truth table0%0/3
not(A) || B
A= !$item->{'parent'}B= $seen{$item->{'parent'}}
ABresult
1X1
011
000
75 } keys %$collectedDict);
76 push @result, map {
77 0 delete $collectedDict->{$seen{$_} = $_};
78 } @ready;
79 0 ▶ if ($lastKeys == keys %$collectedDict) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lastKeys == keys %$collectedDict) 0 0 0
80 0 die "Can't reorder types. Possibly circular deps? "
81 . MOP4Import::Util::terse_dump([remains => sort keys %$collectedDict]
82 , [ok => @result]);
83 }
84 0 $lastKeys = keys %$collectedDict;
85 }
86 0 @result;
87 }
88  
89 0 ▶sub collect_spec_from {
Subroutine collect_spec_from: not called CC=2 SCAR=17.9
Pod undocumented
90 0 (my MY $self, my ($specDictOrArrayOrFile, @names)) = @_;
91 0 my $specDict = $self->specdict_from($specDictOrArrayOrFile);
92 0 my $collectedDict = {};
93 0 foreach my $name (@names) {
94 0 $self->spec_dependency_of($name, $specDict, $collectedDict);
95 }
96 0 $collectedDict;
97 }
98  
99 0 ▶sub spec_dependency_of {
Subroutine spec_dependency_of: not called CC=8 SCAR=42.8
Pod undocumented
100 0 (my MY $self, my ($declOrName, $specDictOrArrayOrFile, $collectedDict, $opts)) = @_;
101 0 ▶ $collectedDict //= {};
Condition0%0/2
$collectedDict //= {}
l!l
00
MC/DC0%0/1
$collectedDict //= {}
$collectedDict
Truth table0%0/2
A
A= $collectedDict
Aresult
11
00
102 0 my $specDict = $self->specdict_from($specDictOrArrayOrFile);
103 0 ▶ my Decl $decl = ref $declOrName ? $declOrName : $specDict->{$declOrName};
Branch: 1 branch
BranchTrueFalseTotal
ref $declOrName ? : 0 0 0
104 0 ▶ unless (defined $decl) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $decl) 0 0 0
105 0 Carp::croak "No such type: ". MOP4Import::Util::terse_dump($declOrName);
106 }
107 0 ▶ my $sub = $self->can("spec_dependency_of__$decl->{kind}") or do {
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $self->can(qq[spec_dependency_of__$decl->{"kind"}]) or do { print STDERR qq[Skipped: not yet supported in spec_dependency_of($decl->{"name"}): $decl->{"kind"}] . MOP4Import::Util::terse_dump($decl), "\n" unless $self->{"quiet"}; return } 0 0 0
108 print STDERR "Skipped: not yet supported in spec_dependency_of($decl->{name}): $decl->{kind}"
109 0 ▶ . MOP4Import::Util::terse_dump($decl), "\n" unless $self->{quiet};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"quiet"} 0 0 0
110 0 return;
111 };
112 my CollectedItem $item = $collectedDict->{$decl->{name}}
113 0 ▶ //= $sub->($self, $decl, $specDict, $collectedDict, $opts);
Condition0%0/3
$$collectedDict{$decl->{"name"}} //= &$sub($self, $decl, $specDict, $collectedDict, $opts)
l!l&&r!l&&!r
000
MC/DC0%0/2
$$collectedDict{$decl->{"name"}} //= &$sub($self, $decl, $specDict, $collectedDict, $opts)
$$collectedDict{$decl->{"name"}} &$sub($self, $decl, $specDict, $collectedDict, $opts)
Truth table0%0/3
A //= B
A= $$collectedDict{$decl->{"name"}}B= &$sub($self, $decl, $specDict, $collectedDict, $opts)
ABresult
1X1
011
000
114  
115 0 ▶ wantarray ? ($item, $collectedDict) : $item;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
116 }
117  
118 0 ▶sub unwrap_annotation {
Subroutine unwrap_annotation: not called CC=5 SCAR=34.0
Pod undocumented
119 0 (my Annotated $rec) = @_;
120 0 ▶ if (not ref $rec) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $rec) { } 0 0 0
elsif (ref $rec eq 'ARRAY') { } 0 0 0
elsif (ref $rec eq 'HASH') { } 0 0 0
121 0 $rec;
122 } elsif (ref $rec eq 'ARRAY') {
123 0 [map {unwrap_annotation($_)} @$rec];
124 } elsif (ref $rec eq 'HASH') {
125 0 my $body = $rec->{body};
126 0 ▶ if (not ref $body) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $body) { } 0 0 0
127 0 $body;
128 } else {
129 0 [map {unwrap_annotation($_)} @$body];
130 }
131 }
132 }
133  
134 1 *spec_dependency_of__class = *spec_dependency_of__interface; *spec_dependency_of__class = *spec_dependency_of__interface;
135  
136 0 ▶sub spec_dependency_of__interface {
Subroutine spec_dependency_of__interface: not called CC=22 SCAR=62.3
Pod undocumented
137 0 (my MY $self, my Interface $decl, my ($specDictOrArrayOrFile, $collectedDict, $opts)) = @_;
138 0 ▶ $collectedDict //= {};
Condition0%0/2
$collectedDict //= {}
l!l
00
MC/DC0%0/1
$collectedDict //= {}
$collectedDict
Truth table0%0/2
A
A= $collectedDict
Aresult
11
00
139 0 my $specDict = $self->specdict_from($specDictOrArrayOrFile);
140  
141 # Origin of dependency references
142 0 my CollectedItem $from = $self->intern_collected_item_in($collectedDict, $decl);
143 0 ▶ if (my $nm = $decl->{extends}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $nm = $decl->{"extends"}) 0 0 0
144 0 $from->{parent} = $nm;
145 0 ▶ my Decl $superSpec = $specDict->{$nm}
Branch: 1 branch
BranchTrueFalseTotal
my YATT::Lite::LanguageServer::SpecParser::Decl $superSpec = $specDict->{$nm} or Carp::croak(qq[Unknown base type for $decl->{"name"}: $nm]) 0 0 0
146 or Carp::croak "Unknown base type for $decl->{name}: $nm";
147 0 my CollectedItem $superItem
148 = $self->spec_dependency_of($superSpec, $specDict, $collectedDict, $opts);
149 0 push @{$superItem->{subtypes}}, $from;
150 }
151 0 foreach my Annotated $slot (@{$decl->{body}}) {
152 0 ▶ next if ref $slot eq 'HASH' and $slot->{deprecated};
Branch: 1 branch
BranchTrueFalseTotal
if ref $slot eq "HASH" and $slot->{"deprecated"} 0 0 0
Condition0%0/3
ref $slot eq "HASH" and $slot->{"deprecated"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $slot eq "HASH" and $slot->{"deprecated"}
ref $slot eq "HASH" $slot->{"deprecated"}
Truth table0%0/3
A and B
A= ref $slot eq "HASH"B= $slot->{"deprecated"}
ABresult
0X0
100
111
153 0 ▶ my $slotDesc = ref $slot eq 'HASH' ? $slot->{body} : $slot;
Branch: 1 branch
BranchTrueFalseTotal
ref $slot eq 'HASH' ? : 0 0 0
154 0 ▶ unless (ref $slotDesc) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $slotDesc) 0 0 0
155 0 die "Invalid slotDesc: $slotDesc";
156 }
157 0 my ($slotName, @typeUnion) = @$slotDesc;
158 0 $slotName =~ s/\?\z//;
159 0 my @fieldOpts;
160 0 ▶ if ($self->{with_field_docs} and ref $slot eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"with_field_docs"} and ref $slot eq "HASH") 0 0 0
Condition0%0/3
$self->{"with_field_docs"} and ref $slot eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"with_field_docs"} and ref $slot eq "HASH"
$self->{"with_field_docs"} ref $slot eq "HASH"
Truth table0%0/3
A and B
A= $self->{"with_field_docs"}B= ref $slot eq "HASH"
ABresult
0X0
100
111
161 0 push @fieldOpts, doc => $slot->{comment};
162 }
163 0 ▶ if ($self->{with_field_typeinfos}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"with_field_typeinfos"}) 0 0 0
164 0 my @tu = map { unwrap_annotation($_) } @typeUnion;
165 0 ▶ push @fieldOpts, typeinfo => (@tu == 1 ? $tu[0] : \@tu);
Branch: 1 branch
BranchTrueFalseTotal
@tu == 1 ? : 0 0 0
166 }
167 0 ▶ push @{$from->{items}}, @fieldOpts ? [$slotName, @fieldOpts] : $slotName;
Branch: 1 branch
BranchTrueFalseTotal
@fieldOpts ? : 0 0 0
168 0 foreach my $typeExprItem (@typeUnion) {
169 0 my $typeExprString = do {
170 0 ▶ if (not ref $typeExprItem) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $typeExprItem) { } 0 0 0
elsif (ref $typeExprItem eq 'ARRAY' and @$typeExprItem == 2 and $typeExprItem->[-1] eq '[]') { } 0 0 0
171 0 $typeExprItem;
172 ▶ } elsif (ref $typeExprItem eq 'ARRAY' and @$typeExprItem == 2 and $typeExprItem->[-1] eq '[]') {
Condition0%0/6
ref $typeExprItem eq "ARRAY" and @$typeExprItem == 2 and $typeExprItem->[-1] eq "[]"
!ll&&!rl&&r
000
ref $typeExprItem eq "ARRAY" and @$typeExprItem == 2
!ll&&!rl&&r
000
MC/DC0%0/3
ref $typeExprItem eq "ARRAY" and @$typeExprItem == 2 and $typeExprItem->[-1] eq "[]"
ref $typeExprItem eq "ARRAY" @$typeExprItem == 2 $typeExprItem->[-1] eq "[]"
Truth table0%0/4
A and B and C
A= ref $typeExprItem eq "ARRAY"B= @$typeExprItem == 2C= $typeExprItem->[-1] eq "[]"
ABCresult
0XX0
10X0
1100
1111
173 0 $typeExprItem->[0];
174 } else {
175 0 warn "Skipped: not yet implemented type item: "
176 .MOP4Import::Util::terse_dump($typeExprItem);
177 0 next;
178 }
179 };
180 0 ▶ $typeExprString =~ /[A-Z]/
Branch: 1 branch
BranchTrueFalseTotal
$typeExprString =~ /[A-Z]/ or next 0 0 0
181 or next;
182 0 ▶ my Decl $typeSpec = $specDict->{$typeExprString}
Branch: 1 branch
BranchTrueFalseTotal
my YATT::Lite::LanguageServer::SpecParser::Decl $typeSpec = $specDict->{$typeExprString} or next 0 0 0
183 or next;
184 0 ▶ $from->{dependency}{$typeExprString}
Condition0%0/3
$from->{"dependency"}{$typeExprString} //= $self->spec_dependency_of($typeSpec, $specDict, $collectedDict, $opts)
l!l&&r!l&&!r
000
MC/DC0%0/2
$from->{"dependency"}{$typeExprString} //= $self->spec_dependency_of($typeSpec, $specDict, $collectedDict, $opts)
$from->{"dependency"}{$typeExprString} $self->spec_dependency_of($typeSpec, $specDict, $collectedDict, $opts)
Truth table0%0/3
A //= B
A= $from->{"dependency"}{$typeExprString}B= $self->spec_dependency_of($typeSpec, $specDict, $collectedDict, $opts)
ABresult
1X1
011
000
185 //= $self->spec_dependency_of($typeSpec, $specDict, $collectedDict, $opts);
186 }
187 }
188 0 $from;
189 }
190  
191 0 ▶sub unwrap_comment_decl {
Subroutine unwrap_comment_decl: not called CC=4 SCAR=30.0
Pod undocumented
192 0 (my MY $self, my Decl $decl) = @_;
193 0 ▶ if (not defined $decl->{kind}
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $decl->{'kind'} and exists $decl->{'comment'} and exists $decl->{'body'}) { } 0 0 0
Condition0%0/6
not defined $decl->{"kind"} and exists $decl->{"comment"} and exists $decl->{"body"}
!ll&&!rl&&r
000
not defined $decl->{"kind"} and exists $decl->{"comment"}
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $decl->{"kind"} and exists $decl->{"comment"} and exists $decl->{"body"}
not defined $decl->{"kind"} exists $decl->{"comment"} exists $decl->{"body"}
Truth table0%0/4
not(A) and B and C
A= not defined $decl->{"kind"}B= exists $decl->{"comment"}C= exists $decl->{"body"}
ABCresult
0XX0
10X0
1100
1111
194 and exists $decl->{comment} and exists $decl->{body}) {
195 $decl->{body}
196 0 } else {
197 0 $decl;
198 }
199 }
200  
201 0 ▶sub spec_dependency_of__namespace {
Subroutine spec_dependency_of__namespace: not called CC=10 SCAR=47.0
Pod undocumented
202 0 (my MY $self, my Decl $decl, my ($specDictOrArrayOrFile, $collectedDict, $opts)) = @_;
203 0 ▶ $collectedDict //= {};
Condition0%0/2
$collectedDict //= {}
l!l
00
MC/DC0%0/1
$collectedDict //= {}
$collectedDict
Truth table0%0/2
A
A= $collectedDict
Aresult
11
00
204 0 my $specDict = $self->specdict_from($specDictOrArrayOrFile);
205  
206 0 my CollectedItem $from = $self->intern_collected_item_in($collectedDict, $decl);
207  
208 0 foreach my Decl $slot (map {$self->unwrap_comment_decl($_)} @{$decl->{body}}) {
209 0 ▶ next unless ($slot->{kind} // '') eq 'const';
Branch: 1 branch
BranchTrueFalseTotal
unless ($slot->{"kind"} // "") eq "const" 0 0 0
Condition0%0/2
$slot->{"kind"} // ""
l!l
00
MC/DC0%0/1
$slot->{"kind"} // ""
$slot->{"kind"}
Truth table0%0/2
A
A= $slot->{"kind"}
Aresult
11
00
210 0 my ($typeExprString, $value) = do {
211 0 ▶ if (ref $slot->{body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $slot->{'body'}) { } 0 0 0
212 0 @{$slot->{body}};
213 } else {
214 0 (undef,$slot->{body});
215 }
216 };
217  
218 0 push @{$from->{items}}, [$slot->{name}, $value];
219  
220 0 ▶ if (defined $typeExprString) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $typeExprString) 0 0 0
221 0 ▶ $typeExprString =~ /[A-Z]/
Branch: 1 branch
BranchTrueFalseTotal
$typeExprString =~ /[A-Z]/ or next 0 0 0
222 or next;
223 0 ▶ my Decl $typeSpec = $specDict->{$typeExprString}
Branch: 1 branch
BranchTrueFalseTotal
my YATT::Lite::LanguageServer::SpecParser::Decl $typeSpec = $specDict->{$typeExprString} or next 0 0 0
224 or next;
225  
226 0 ▶ $from->{dependency}{$typeExprString}
Condition0%0/3
$from->{"dependency"}{$typeExprString} //= $self->spec_dependency_of($typeSpec, $specDict, $collectedDict, $opts)
l!l&&r!l&&!r
000
MC/DC0%0/2
$from->{"dependency"}{$typeExprString} //= $self->spec_dependency_of($typeSpec, $specDict, $collectedDict, $opts)
$from->{"dependency"}{$typeExprString} $self->spec_dependency_of($typeSpec, $specDict, $collectedDict, $opts)
Truth table0%0/3
A //= B
A= $from->{"dependency"}{$typeExprString}B= $self->spec_dependency_of($typeSpec, $specDict, $collectedDict, $opts)
ABresult
1X1
011
000
227 //= $self->spec_dependency_of($typeSpec, $specDict, $collectedDict, $opts);
228 }
229 }
230  
231 0 $from;
232 }
233  
234 0 ▶sub intern_collected_item_in {
Subroutine intern_collected_item_in: not called CC=3 SCAR=24.8
Pod undocumented
235 0 (my MY $self, my $collectedDict, my Decl $decl, my $opts) = @_;
236 0 ▶ $collectedDict->{$decl->{name}} //= do {
Condition0%0/3
$$collectedDict{$decl->{"name"}} //= do { my YATT::Lite::LanguageServer::Spec2Types::CollectedItem $item = {}; $item->{"kind"} = $decl->{"kind"}; $item->{"name"} = $decl->{"name"}; if ($opts->{"spec"}) { $item->{"spec"} = $decl; } ; $item }
l!l&&r!l&&!r
000
MC/DC0%0/2
$$collectedDict{$decl->{"name"}} //= do { my YATT::Lite::LanguageServer::Spec2Types::CollectedItem $item = {}; $item->{"kind"} = $decl->{"kind"}; $item->{"name"} = $decl->{"name"}; if ($opts->{"spec"}) { $item->{"spec"} = $decl; } ; $item }
$$collectedDict{$decl->{"name"}} do { my YATT::Lite::LanguageServer::Spec2Types::CollectedItem $item = {}; $item->{"kind"} = $decl->{"kind"}; $item->{"name"} = $decl->{"name"}; if ($opts->{"spec"}) { $item->{"spec"} = $decl; } ; $item }
Truth table0%0/3
A //= B
A= $$collectedDict{$decl->{"name"}}B= do { my YATT::Lite::LanguageServer::Spec2Types::CollectedItem $item = {}; $item->{"kind"} = $decl->{"kind"}; $item->{"name"} = $decl->{"name"}; if ($opts->{"spec"}) { $item->{"spec"} = $decl; } ; $item }
ABresult
1X1
011
000
237 0 my CollectedItem $item = {};
238 0 $item->{kind} = $decl->{kind};
239 0 $item->{name} = $decl->{name};
240 0 ▶ if ($opts->{spec}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"spec"}) 0 0 0
241 0 $item->{spec} = $decl;
242 }
243 0 $item;
244 };
245 }
246  
247 0 ▶sub extract_spec_from {
Subroutine extract_spec_from: not called CC=1 SCAR=6.9
Pod undocumented
248 0 (my MY $self, my ($specDictOrArrayOrFile, @names)) = @_;
249 0 my $specDict = $self->specdict_from($specDictOrArrayOrFile);
250 map {
251 0 $specDict->{$_}
252 } @names;
253 }
254  
255 0 ▶sub specdict_from {
Subroutine specdict_from: not called CC=5 SCAR=34.0
Pod undocumented
256 0 (my MY $self, my ($specDictOrArrayOrFile)) = @_;
257 0 ▶ if (not ref $specDictOrArrayOrFile) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $specDictOrArrayOrFile) { } 0 0 0
elsif (ref $specDictOrArrayOrFile eq 'ARRAY') { } 0 0 0
elsif (ref $specDictOrArrayOrFile eq 'HASH') { } 0 0 0
258 0 my @decls = do {
259 0 ▶ if ($specDictOrArrayOrFile =~ /\.md\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($specDictOrArrayOrFile =~ /\.md\z/) { } 0 0 0
260 0 $self->SpecParser->new->parse_files($specDictOrArrayOrFile)
261 } else {
262 # $self->cli_read_file__json($specDictOrArrayOrFile);
263 0 $self->cli_slurp_xargs_json($specDictOrArrayOrFile);
264 }
265 };
266 0 $self->gather_by_name(@decls);
267 } elsif (ref $specDictOrArrayOrFile eq 'ARRAY') {
268 0 $self->gather_by_name(
269 @$specDictOrArrayOrFile
270 );
271 } elsif (ref $specDictOrArrayOrFile eq 'HASH') {
272 0 $specDictOrArrayOrFile;
273 } else {
274 0 Carp::croak "Unsupported specDict: "
275 . MOP4Import::Util::terse_dump($specDictOrArrayOrFile);
276 }
277 }
278  
279 #========================================
280  
281 0 ▶sub typedefs_of_collected_item {
Subroutine typedefs_of_collected_item: not called CC=2 SCAR=17.9
Pod undocumented
282 0 (my MY $self, my CollectedItem $item, my $seen) = @_;
283 0 $seen->{$item->{name}}++;
284  
285 0 ▶ my $sub = $self->can("typedefs_of_collected_item_of__$item->{kind}") or do {
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $self->can(qq[typedefs_of_collected_item_of__$item->{"kind"}]) or do { warn qq[Skipped: not yet implemented to generate typedefs of $item->{"kind"} for $item->{"name"};]; return } 0 0 0
286 0 warn "Skipped: not yet implemented to generate typedefs of $item->{kind} for $item->{name};";
287 0 return;
288 };
289  
290 0 $sub->($self, $item, $seen);
291 }
292  
293 1 *typedefs_of_collected_item_of__class = *typedefs_of_collected_item_of__interface; *typedefs_of_collected_item_of__class = *typedefs_of_collected_item_of__interface;
294  
295 0 ▶sub typedefs_of_collected_item_of__interface {
Subroutine typedefs_of_collected_item_of__interface: not called CC=3 SCAR=24.8
Pod undocumented
296 0 (my MY $self, my CollectedItem $item, my $seen) = @_;
297 # Type is not used currently.
298  
299 # If item has no fields, no need to generate field specs.
300 0 ▶ return unless $item->{items};
Branch: 1 branch
BranchTrueFalseTotal
unless $item->{"items"} 0 0 0
301  
302 0 my @defs = ([fields => @{$item->{items}}]);
303 0 ▶ if ($item->{subtypes}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{"subtypes"}) 0 0 0
304 push @defs, [subtypes => map {
305 0 $self->typedefs_of_collected_item($_, $seen)
306 0 } @{$item->{subtypes}}]
307 }
308 0 ($item->{name}, \@defs);
309 }
310  
311 0 ▶sub typedefs_of_collected_item_of__namespace {
Subroutine typedefs_of_collected_item_of__namespace: not called CC=2 SCAR=17.9
Pod undocumented
312 0 (my MY $self, my CollectedItem $item, my $seen) = @_;
313  
314 0 ▶ return unless $item->{items};
Branch: 1 branch
BranchTrueFalseTotal
unless $item->{"items"} 0 0 0
315  
316 (undef, [map {
317 0 my ($name, $value) = @$_;
318 0 [constant => "$item->{name}__$name" => $value];
319 0 } @{$item->{items}}]);
320 }
321  
322 #========================================
323  
324 0 ▶sub gather_by_name {
Subroutine gather_by_name: not called CC=3 SCAR=24.8
Pod undocumented
325 0 (my MY $self, my @decls) = @_;
326 0 my %dict;
327 0 foreach my Interface $if (@decls) {
328 0 ▶ next unless ref $if eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $if eq "HASH" 0 0 0
329 0 $dict{$if->{name}} = $if;
330 }
331 0 \%dict;
332 }
333  
334 0 ▶sub _toy_dump_numeric_as_is {
Subroutine _toy_dump_numeric_as_is: not called CC=5 SCAR=34.0
335 0 my ($obj, $depth) = @_;
336 0 my $indent = " " x $depth;
337 0 ▶ if (not defined $obj) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $obj) { } 0 0 0
elsif (not ref $obj) { } 0 0 0
elsif (ref $obj eq 'ARRAY') { } 0 0 0
338 0 ($indent."undef(),\n");
339 } elsif (not ref $obj) {
340 0 ▶ if ($obj =~ /^[-+]?\d+\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj =~ /^[-+]?\d+\z/) { } 0 0 0
341 0 ($indent."$obj,\n");
342 } else {
343 0 $obj =~ s/\'/\\'/g;
344 0 ($indent."'$obj',\n");
345 }
346 } elsif (ref $obj eq 'ARRAY') {
347 $indent."[\n".join("", map {
348 0 _toy_dump_numeric_as_is($_, $depth+1);
349 } @$obj).$indent."],\n";
350 } else {
351 0 Carp::croak "Not supported type: ". ref $obj;
352 }
353 }
354  
355 1 ▶MY->run(\@ARGV) unless caller;
Branch: 1 branch
BranchTrueFalseTotal
unless caller 0 1 1
356  
357 1 1;
« blib/lib/YATT/Lite/Test/XHFTest2.pm ↑ Summary blib/lib/YATT/Lite/Walker.pm »