blib/lib/App/Asciio/Ascii.pm

filter: Statementstmt 76.7% 66 / 86 Branchbran 45.4% 10 / 22 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 9 / 12 Podpod 0.0% 0 / 6 totaltotal 65.6% 86 / 131 CC 20 SCAR 26.9
CC
20
Cov
69%
transform_elements_to_characters_array
27.1
transform_elements_to_array
6.2
transform_elements_to_ascii_buffer
2.0
CRAP 14.7
« blib/lib/App/Asciio/Connections.pm ↑ Summary blib/lib/App/Asciio/stripes/triangle_down.pm »
1  
2 package App::Asciio;
3  
4 4 $|++ ;
5  
6 4 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use App::Asciio::Cross ;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use App::Asciio::String ;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use App::Asciio::Markup ;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 ▶use Readonly ;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 Readonly my $EXPORT_PLAIN_TEXT => 0 ;
14 4 Readonly my $EXPORT_MARKUP => 1 ;
15  
16 #-----------------------------------------------------------------------------
17  
18 sub transform_elements_to_ascii_buffer
19 0 ▶{
Subroutine transform_elements_to_ascii_buffer: not called CC=1 SCAR=6.9
Pod undocumented
20 0 my ($self, @elements) = @_ ;
21  
22 0 my $text = join("\n", $self->transform_elements_to_ascii_array(@elements)) . "\n" ;
23 0 $text =~ s/^\n+|\n\K\n+$//g ;
24  
25 0 return($text) ;
26 }
27  
28 #-----------------------------------------------------------------------------
29  
30 sub transform_elements_to_markup_buffer
31 0 ▶{
Subroutine transform_elements_to_markup_buffer: not called CC=1 SCAR=6.9
Pod undocumented
32 0 my ($self, @elements) = @_ ;
33  
34 0 my $text = join("\n", $self->transform_elements_to_markup(@elements)) . "\n" ;
35 0 $text =~ s/^\n+|\n\K\n+$//g ;
36  
37 0 return($text) ;
38 }
39  
40 #-----------------------------------------------------------------------------
41  
42 sub transform_elements_to_characters_array
43 169 ▶{
Subroutine transform_elements_to_characters_array: called CC=15 SCAR=33.0
Pod undocumented
44 169 my ($self, $format, @elements) = @_ ;
45  
46 169 ▶@elements = @{$self->{ELEMENTS}} unless @elements ;
Branch: 1 branch
BranchTrueFalseTotal
unless @elements 169 0 169
47  
48 169 my @lines ;
49 169 my (%markup_coordinate, %sub_markup_coordinate) ;
50  
51 169 for my $element (@elements)
52 {
53 169 for my $strip (@{$element->get_stripes()})
54 {
55 917 my $line_index = 0 ;
56
57 917 for my $sub_strip (split("\n", $strip->{TEXT}))
58 {
59 1141 my $origin_strip = $sub_strip ;
60 1141 my $y = $element->{Y} + $strip->{Y_OFFSET} + $line_index ;
61
62 1141 $sub_strip = $USE_MARKUP_CLASS->delete_markup_characters($sub_strip) ;
63
64 1141 ▶ if($format != $EXPORT_PLAIN_TEXT)
Branch: 1 branch
BranchTrueFalseTotal
if ($format != $EXPORT_PLAIN_TEXT) 0 1141 1141
65 {
66 0 %sub_markup_coordinate = $USE_MARKUP_CLASS->get_markup_coordinates($element->{X}, $origin_strip, $strip->{X_OFFSET}, $y) ;
67 0 ▶ while (my ($key, $value) = each %sub_markup_coordinate)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %sub_markup_coordinate) 0 0 0
68 {
69 0 $markup_coordinate{$key} = ${value} ;
70 }
71 }
72
73 1141 my $character_index = 0 ;
74
75 1141 for my $character (split '', $sub_strip)
76 {
77 1430 my $x = $element->{X} + $strip->{X_OFFSET} + $character_index ;
78
79 1430 ▶ if($x >= 0 && $y >= 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($x >= 0 and $y >= 0) 1430 0 1430
Condition33%1/3
$x >= 0 and $y >= 0
!ll&&!rl&&r
001430
MC/DC0%0/2
$x >= 0 and $y >= 0
$x >= 0 $y >= 0
Truth table33%1/3
A and B
A= $x >= 0B= $y >= 0
ABresult
0X0
100
111
80 {
81 1430 ▶ if($character =~ /\p{gc:Mn}/)
Branch: 1 branch
BranchTrueFalseTotal
if ($character =~ /\p{gc:Mn}/) { } 0 1430 1430
82 {
83 0 push @{$lines[$y][$x-1]}, $character ;
84 }
85 else
86 {
87 1430 $lines[$y][$x] = [$character] ;
88 }
89 }
90
91 1430 my $character_length = unicode_length($character) ;
92 1430 $character_index += $character_length ;
93 }
94
95 1141 $line_index++ ;
96 }
97 }
98 }
99  
100 # If there is cross overlay, the characters of the cross need to be exported
101 169 ▶if($self->{USE_CROSS_MODE})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"USE_CROSS_MODE"}) 0 169 169
102 {
103 0 for(App::Asciio::Cross::get_cross_mode_overlays($self))
104 {
105 0 ▶ $lines[$_->[1]][$_->[0]] = [$_->[2]] if defined $lines[$_->[1]][$_->[0]] ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $lines[$_->[1]][$_->[0]] 0 0 0
106 }
107 }
108 169 ▶if($format != $EXPORT_PLAIN_TEXT)
Branch: 1 branch
BranchTrueFalseTotal
if ($format != $EXPORT_PLAIN_TEXT) 0 169 169
109 {
110 0 return $USE_MARKUP_CLASS->get_markup_characters_array(\%markup_coordinate, @lines) ;
111 }
112 169 return @lines ;
113  
114 }
115  
116 #-----------------------------------------------------------------------------
117  
118 sub transform_elements_to_array
119 169 ▶{
Subroutine transform_elements_to_array: called CC=6 SCAR=18.2
Pod undocumented
120 169 my ($self, $format, @elements) = @_ ;
121  
122 169 my @lines = $self->transform_elements_to_characters_array($format, @elements) ;
123  
124 169 my @ascii ;
125  
126 169 for my $line (@lines)
127 {
128 1605 ▶ my $ascii_line = join('', map {defined $_ ? join('', @{$_}) : ' '} @{$line}) ;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 1230 5506 6736
129 1605 ▶ if(defined $ascii_line)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ascii_line) { } 1605 0 1605
130 {
131 1605 my ($write_line, $char_len) = ('', 1) ;
132
133 1605 for my $character (split '', $ascii_line)
134 {
135 6736 ▶ if($char_len > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($char_len > 1) { } 0 6736 6736
136 {
137 0 $char_len -= 1;
138 }
139 else
140 {
141 # single char
142 6736 $char_len = unicode_length($character) ;
143 6736 $write_line .= $character;
144 }
145 }
146
147 1605 push @ascii, $write_line;
148 }
149 else
150 {
151 0 push @ascii, $ascii_line ;
152 }
153 }
154  
155 169 return(@ascii) ;
156 }
157  
158 #-----------------------------------------------------------------------------
159  
160 sub transform_elements_to_ascii_array
161 169 ▶{
Subroutine transform_elements_to_ascii_array: called CC=1 SCAR=0.0
Pod undocumented
162 169 my ($self, @elements) = @_ ;
163  
164 169 return($self->transform_elements_to_array($EXPORT_PLAIN_TEXT, @elements));
165 }
166  
167 #-----------------------------------------------------------------------------
168  
169 sub transform_elements_to_markup
170 0 ▶{
Subroutine transform_elements_to_markup: not called CC=1 SCAR=6.9
Pod undocumented
171 0 my ($self, @elements) = @_ ;
172  
173 0 return($self->transform_elements_to_array($EXPORT_MARKUP, @elements));
174 }
175 #-----------------------------------------------------------------------------
176  
177 4 1 ;
« blib/lib/App/Asciio/Connections.pm ↑ Summary blib/lib/App/Asciio/stripes/triangle_down.pm »