web/cgi-bin/yatt.lib/YATT/LRXML.pm

filter: Statementstmt 86.4% 102 / 118 Branchbran 53.5% 15 / 28 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 87.1% 27 / 31 Podpod 0.0% 0 / 3 totaltotal 80.3% 147 / 183 CC 17 SCAR 10.4
CC
17
Cov
80%
read
12.0
number_of_lines
4.2
after_read
4.2
CRAP 2.8
« web/cgi-bin/yatt.lib/YATT/Util/Finalizer.pm ↑ Summary web/cgi-bin/yatt.lib/YATT/Util/CGICompat.pm »
1 # -*- mode: perl; coding: utf-8 -*-
2 package YATT::LRXML;
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 ▶use YATT::Util qw(call_type);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 require YATT::LRXML::Node;
9  
10 sub Parser () { 'YATT::LRXML::Parser' }
11  
12 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # Returns YATT::LRXML::Cursor
15 2 ▶sub read_string {
Subroutine read_string: called CC=1 SCAR=0.0
Pod undocumented
16 2 my $pack = shift;
17 2 my $parser = $pack->call_type(Parser => 'new');
18 2 $parser->parse_string(@_);
19 }
20  
21 0 ▶sub read_handle {
Subroutine read_handle: not called CC=1 SCAR=6.9
Pod undocumented
22 0 my $pack = shift;
23 0 my $parser = $pack->call_type(Parser => 'new');
24 0 $parser->parse_handle(@_);
25 }
26  
27 0 ▶sub read {
Subroutine read: not called CC=3 SCAR=24.8
Pod undocumented
28 0 my ($pack, $filename) = splice @_, 0, 2;
29 0 my $fh;
30 0 ▶ if (ref $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $filename) { } 0 0 0
31 0 $fh = $filename;
32 } else {
33 0 ▶ open $fh, '<', $filename or croak "Can't open '$filename': $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $filename or croak("Can't open '${filename}': $!") 0 0 0
34 0 unshift @_, filename => $filename;
35 }
36 0 $pack->read_handle($fh, @_);
37 }
38  
39 #========================================
40  
41 package YATT::LRXML::Scanner; # To scan tokens.
42 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 7 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
44 7 ▶use base qw(YATT::Class::ArrayScanner);
Subroutine BEGIN: called CC=1 SCAR=0.0
45 use YATT::Fields
46 7 ▶ (['^cf_linenum' => 1]
Subroutine BEGIN: called CC=1 SCAR=0.0
47 , ['^cf_last_nol' => 0] # last number of lines
48 , qw(cf_last_linenum
49 7 cf_path cf_metainfo));
50  
51 635 ▶sub expect {
Subroutine expect: called CC=4 SCAR=14.0
52 635 (my MY $path, my ($patterns)) = @_;
53 635 ▶ return unless $path->readable;
Branch: 1 branch
BranchTrueFalseTotal
unless $path->readable 0 635 635
54 635 my $value = $path->{cf_array}[$path->{cf_index}];
55 635 my @match;
56 635 foreach my $desc (@$patterns) {
57 2453 my ($toktype, $pat) = @$desc;
58 2453 ▶ next unless @match = $value =~ $pat;
Branch: 1 branch
BranchTrueFalseTotal
unless @match = $value =~ /$pat/ 1818 635 2453
59 635 $path->after_read($path->{cf_index}++);
60 635 return ($toktype, @match);
61 }
62 0 return;
63 }
64  
65 156 ▶sub number_of_lines {
Subroutine number_of_lines: called CC=4 SCAR=14.5
66 156 (my MY $path, my ($pos)) = @_;
67 156 ▶ $pos = $path->{cf_index} unless defined $pos;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 156 0 156
68 156 ▶ return 0 unless @{$path->{cf_array}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$path->{"cf_array"};} 0 156 156
69 156 ▶ defined (my $tok = $path->{cf_array}[$pos])
Branch: 1 branch
BranchTrueFalseTotal
defined(my $tok = $path->{"cf_array"}[$pos]) or return undef 156 0 156
70 or return undef;
71 156 $tok =~ tr:\n::;
72 }
73  
74 1450 ▶sub after_read {
Subroutine after_read: called CC=4 SCAR=14.3
75 1450 (my MY $path, my ($pos)) = @_;
76 1450 ▶ if (defined $pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos) 1450 0 1450
77 1450 $$path{cf_last_nol} = $path->{cf_array}[$pos] =~ tr:\n::;
78 }
79 1450 $path->{cf_last_linenum} = $path->{cf_linenum};
80 1450 ▶ unless (defined $$path{cf_linenum}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $path->{'cf_linenum'}) { } 1450 0 1450
81 0 $$path{cf_linenum} = 1;
82 } else {
83 1450 ▶ $$path{cf_linenum} += $$path{cf_last_nol} || 0;
Condition100%2/2
$path->{'cf_last_nol'} || 0
l!l
559891
MC/DC100%1/1
$path->{'cf_last_nol'} || 0
$path->{'cf_last_nol'}
Truth table100%2/2
A
A= $path->{'cf_last_nol'}
Aresult
11
00
84 }
85 }
86  
87 7 ▶use YATT::Exception qw(Exception);
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 0 ▶sub token_error {
Subroutine token_error: not called CC=1 SCAR=6.9
90 0 (my MY $self, my ($mesg)) = @_;
91 $self->Exception->new(error_fmt => $mesg
92 , file => $self->{cf_metainfo}->in_file
93 0 , line => $self->{cf_linenum});
94 }
95  
96 #========================================
97 package YATT::LRXML::Builder; # To build tree.
98 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
99 7 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
100 7 ▶use base qw(YATT::Class::Configurable);
Subroutine BEGIN: called CC=1 SCAR=0.0
101 7 ▶use YATT::Fields qw(^product ^parent ^is_switched
Subroutine BEGIN: called CC=1 SCAR=0.0
102 7 cf_endtag cf_startpos cf_startline cf_linenum);
103  
104 7 ▶use YATT::LRXML::Node qw(node_set_nlines);
Subroutine BEGIN: called CC=1 SCAR=0.0
105 sub Scanner () {'YATT::LRXML::Scanner'}
106  
107 0 ▶sub initargs {qw(product parent)}
Subroutine initargs: not called CC=1 SCAR=6.9
108  
109 323 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
110 323 my $pack = shift;
111 323 my MY $path = $pack->SUPER::new;
112 323 ▶ $path->init(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 323 0 323
113 323 $path;
114 }
115  
116 323 ▶sub init {
Subroutine init: called CC=2 SCAR=7.0
117 323 my MY $path = shift;
118 323 @{$path}{qw(product parent)} = splice @_, 0, 2;
119 323 ▶ $path->configure(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 323 0 323
120 323 $path;
121 }
122  
123 67 ▶sub open {
Subroutine open: called CC=1 SCAR=0.0
124 67 (my MY $parent, my ($product)) = splice @_, 0, 2;
125 ref($parent)->new($product, $parent, $parent->configure
126 , startline => $parent->{cf_linenum}
127 67 , @_);
128 }
129  
130 7 ▶use YATT::Exception qw(Exception);
Subroutine BEGIN: called CC=1 SCAR=0.0
131  
132 1 ▶sub error {
Subroutine error: called CC=1 SCAR=0.0
133 1 (my MY $self, my ($mesg, $param, @other)) = @_;
134 1 $self->Exception->new(error_fmt => $mesg
135 , error_param => $param
136 , @other);
137 }
138  
139 64 ▶sub verify_close {
Subroutine verify_close: called CC=3 SCAR=11.3
140 64 (my MY $self, my ($tagname, $scan)) = @_;
141 64 ▶ unless (defined $self->{cf_endtag}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"cf_endtag"}) 0 64 64
142 0 die $self->error("TAG '/%s' without open", [$tagname]
143 , file => $scan->cget('metainfo')->filename
144 , line => $scan->linenum);
145 }
146 64 ▶ unless ($tagname eq $self->{cf_endtag}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagname eq $self->{"cf_endtag"}) 1 63 64
147 die $self->error("TAG '%s' line %d closed by /%s"
148 1 , [$self->{cf_endtag}, $self->{cf_startline}, $tagname]
149 , file => $scan->cget('metainfo')->filename
150 , line => $scan->linenum);
151 }
152 }
153  
154 996 ▶sub add {
Subroutine add: called CC=1 SCAR=0.0
155 996 (my MY $self, my Scanner $scan) = splice @_, 0, 2;
156 996 push @{$self->{product}}, @_;
157 996 $self->{cf_linenum} = $scan->{cf_linenum};
158 996 $self;
159 }
160  
161 16 ▶sub switch {
Subroutine switch: called CC=2 SCAR=6.9
162 16 (my MY $self, my ($elem)) = @_;
163 16 ▶ unless ($self->{is_switched}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"is_switched"}) 11 5 16
164 11 $self->{is_switched} = $self->{product};
165 }
166 16 push @{$self->{is_switched}}, $elem;
167 16 $self->{product} = $elem;
168 16 $self;
169 }
170  
171 323 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
172 323 my MY $self = shift;
173 # switch した場合は?
174 node_set_nlines($self->{product}
175 323 , $self->{cf_linenum} - $self->{cf_startline});
176 }
177  
178 7 1;
« web/cgi-bin/yatt.lib/YATT/Util/Finalizer.pm ↑ Summary web/cgi-bin/yatt.lib/YATT/Util/CGICompat.pm »