blib/lib/Text/Flowchart.pm

filter: Statementstmt 83.0% 396 / 477 Branchbran 56.3% 142 / 252 Conditioncond 48.2% 69 / 143 MC/DCmcdc 16.2% 13 / 80 Subroutinesub 95.8% 69 / 72 Podpod 62.5% 5 / 8 totaltotal 67.2% 694 / 1032 CC 191 SCAR 33.1
CC
191
Cov
70%
render
210.0
draw
68.5
relate
42.4
CRAP 27.3
↑ Summary
1 package Text::Flowchart;
2  
3 #Copyright (c) 1999 James A Thomason III (jim3@psynet.net). All rights reserved.
4 #This program is free software; you can redistribute it under the terms of the licence listed at the end
5 #of the module.
6  
7 1 $VERSION = "1.00";
8  
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 {
13 1 my $i = 0;
14 1 foreach ($boxes, $grid, $lines, $directed){
15 4 $_ = $i++
16 };
17
18 };
19  
20 68 ▶sub accessor {
Subroutine accessor: called CC=2 SCAR=6.9
Pod undocumented
21 68 my $self = shift;
22 68 my $prop = shift;
23
24 68 ▶ $self->[$prop] = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 5 63 68
25
26 68 return $self->[$prop];
27 };
28  
29 17 ▶sub directed{ shift->accessor($directed, @_)};
Subroutine directed: called CC=1 SCAR=0.0
Pod documented
30  
31 1 ▶sub new {
Subroutine new: called CC=4 SCAR=14.3
Pod documented
32  
33 1 my $class = shift;
34 1 my %init = @_;
35 1 my $self = []; #why not a hash? An array is a smidgen bit faster and no one is gonna see the underlying structure anyway
36 1 bless $self, $class; #Hey! What are you doing looking in here anyway? Use the nice OO interface I wrote you!
37
38 $self->size(
39 "width" => $init{"width"} ? $init{"width"} : -1,
40 "height" => $init{"height"} ? $init{"height"} : -1,
41 "pad" => $init{"pad"},
42 1 ▶ "debug" => $init{"debug"}
Branch: 2 branches
BranchTrueFalseTotal
$init{'width'} ? : 1 0 1
$init{'height'} ? : 0 1 1
43 );
44
45 1 ▶ $self->directed($init{"directed"} || 0);
Condition50%1/2
$init{'directed'} || 0
l!l
10
MC/DC0%0/1
$init{'directed'} || 0
$init{'directed'}
Truth table50%1/2
A
A= $init{'directed'}
Aresult
11
00
46
47 1 return $self;
48
49 };
50  
51 5 ▶sub box {
Subroutine box: called CC=3 SCAR=11.2
Pod documented
52  
53 5 my $self = shift;
54
55 5 my $box = Text::Flowchart::Shape::Box->new(@_, "parent" => $self);
56
57 5 ▶ croak("Box was not created properly\n") unless $box;
Branch: 1 branch
BranchTrueFalseTotal
unless $box 0 5 5
58
59
60 5 ▶ push @{$self->[$boxes]}, $box || croak("Cannot add box to flowchart stack\n");
Condition50%1/2
$box || croak("Cannot add box to flowchart stack\n")
l!l
50
MC/DC0%0/1
$box || croak("Cannot add box to flowchart stack\n")
$box
Truth table50%1/2
A
A= $box
Aresult
11
00
61
62 5 return $self->[$boxes]->[-1];
63 };
64  
65 5 ▶sub line {
Subroutine line: called CC=6 SCAR=19.1
Pod undocumented
66  
67 5 my $self = shift;
68
69 5 my %init = @_;
70
71 5 my $line;
72 5 ▶ if ($init{"orientation"} eq "V"){
Branch: 3 branches
BranchTrueFalseTotal
if ($init{'orientation'} eq 'V') { } 0 5 5
elsif ($init{'orientation'} =~ /^(T|B)C$/) { } 4 1 5
elsif ($init{'orientation'} eq 'H') { } 1 0 1
73 0 $line = Text::Flowchart::Shape::Line::Vertical->new(@_, "parent" => $self);
74 }
75 elsif ($init{"orientation"} =~ m/^(T|B)C$/){
76 4 $line = Text::Flowchart::Shape::Line::Corner->new(@_, "parent" => $self);
77 }
78 elsif ($init{"orientation"} eq "H"){
79 1 $line = Text::Flowchart::Shape::Line::Horizontal->new(@_, "parent" => $self);
80 }
81 0 else {croak("Invalid orientation. Must be 'H', 'V', 'TC', or 'BC'\n")};
82
83 5 ▶ croak("Line was not created properly.\n") unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 5 5
84
85
86
87 5 ▶ push @{$self->[$lines]}, $line || croak("Cannot add line to flowchart stack\n");
Condition50%1/2
$line || croak("Cannot add line to flowchart stack\n")
l!l
50
MC/DC0%0/1
$line || croak("Cannot add line to flowchart stack\n")
$line
Truth table50%1/2
A
A= $line
Aresult
11
00
88
89 5 return $self->[$lines]->[-1];
90 };
91  
92 12 ▶sub size {
Subroutine size: called CC=3 SCAR=11.0
Pod undocumented
93
94 12 my $self = shift;
95
96 12 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 11 12
97 1 my $_grid = Text::Flowchart::Grid->new(@_);
98 1 ▶ croak("Cannot create grid\n") unless $_grid;
Branch: 1 branch
BranchTrueFalseTotal
unless $_grid 0 1 1
99 1 $self->[$grid] = $_grid;
100 };
101
102 12 return $self->[$grid];
103  
104 };
105  
106 1 ▶sub draw {
Subroutine draw: called CC=11 SCAR=42.3
Pod documented
107 1 my $self = shift;
108
109 1 local *OUTPUT;
110 1 ▶ *OUTPUT = shift || *STDOUT;
Condition33%1/3
shift() || *STDOUT
l!l&&r!l&&!r
010
MC/DC0%0/2
shift() || *STDOUT
shift() *STDOUT
Truth table33%1/3
A || B
A= shift()B= *STDOUT
ABresult
1X1
011
000
111
112 1 my $grid = $self->size();
113 1 my ($x, $y, $x2, $y2) = (0,0,0,0);
114
115 1 foreach $box (@{$self->[$boxes]}){
116 5 $grid->insert($box)
117 };
118
119 0 foreach $line (@{$self->[$lines]}){
120 0 $grid->insert($line)
121 };
122
123 #print OUTPUT "\n";
124
125 0 $grid->repair();
126
127 0 ▶ if ($grid->debug()){
Branch: 1 branch
BranchTrueFalseTotal
if ($grid->debug) 0 0 0
128 0 print OUTPUT " ";
129 0 my $width = $grid->width();
130 0 ▶ while ($width-- > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($width-- > 0) 0 0 0
131 0 ▶ print OUTPUT ($x++ % 10 || $x2++);
Condition0%0/3
$x++ % 10 || $x2++
l!l&&r!l&&!r
000
MC/DC0%0/2
$x++ % 10 || $x2++
$x++ % 10 $x2++
Truth table0%0/3
A || B
A= $x++ % 10B= $x2++
ABresult
1X1
011
000
132 };
133 0 print OUTPUT "\n";
134 };
135 0 foreach (0..$#{$grid->grid()}){
136 0 ▶ print OUTPUT ($y++ % 10 || $y2++) if $grid->debug();
Branch: 1 branch
BranchTrueFalseTotal
if $grid->debug 0 0 0
Condition0%0/3
$y++ % 10 || $y2++
l!l&&r!l&&!r
000
MC/DC0%0/2
$y++ % 10 || $y2++
$y++ % 10 $y2++
Truth table0%0/3
A || B
A= $y++ % 10B= $y2++
ABresult
1X1
011
000
137 0 ▶ if (length $grid->grid->[$_] == $grid->width()){print OUTPUT $grid->grid->[$_], "\n"}
Branch: 1 branch
BranchTrueFalseTotal
if (length $grid->grid->[$_] == $grid->width) { } 0 0 0
138 0 else {print OUTPUT $grid->pad() x $grid->width(), "\n"};
139 };
140 };
141  
142 5 ▶sub relate {
Subroutine relate: called CC=7 SCAR=22.4
Pod documented
143 5 my $self = shift;
144  
145 5 my $from_array = shift;
146 5 my $to_array = shift;
147
148 5 my %init = @_;
149  
150 5 my ($from, $from_side, $from_offset) = @{$from_array};
151 5 my ($to, $to_side, $to_offset) = @{$to_array};
152 0 ▶ if ($from->parent() ne $self){croak("Cannot relate from a box not inside this flowchart.\n")};
Branch: 1 branch
BranchTrueFalseTotal
if ($from->parent ne $self) 0 5 5
153 0 ▶ if ($to->parent() ne $self){croak("Cannot relate to a box not inside this flowchart.\n")};
Branch: 1 branch
BranchTrueFalseTotal
if ($to->parent ne $self) 0 5 5
154 0 ▶ if ($from_side !~ /^(top|bottom|right|left)$/){croak("Invalid side. Side must be 'top', 'bottom', 'left', or 'right'.\n")};
Branch: 1 branch
BranchTrueFalseTotal
unless ($from_side =~ /^(top|bottom|right|left)$/) 0 5 5
155 0 ▶ if ($to_side !~ /^(top|bottom|right|left)$/){croak("Invalid side. Side must be 'top', 'bottom', 'left', or 'right'.\n")};
Branch: 1 branch
BranchTrueFalseTotal
unless ($to_side =~ /^(top|bottom|right|left)$/) 0 5 5
156 0 ▶ if ($from_side eq $to_side){croak("Cannot relate the same sides of boxes. Use different sides.\n")};
Branch: 1 branch
BranchTrueFalseTotal
if ($from_side eq $to_side) 0 5 5
157 0 ▶ if (length $init{"reason"} > 1){croak("Reasons must be a single character.\n")};
Branch: 1 branch
BranchTrueFalseTotal
if (length $init{"reason"} > 1) 0 5 5
158
159 return $from->relate(
160 "to" => $to,
161 "from_side" => $from_side,
162 "to_side" => $to_side,
163 "from_offset" => $from_offset,
164 "to_offset" => $to_offset,
165 5 "reason" => $init{"reason"}
166 );
167
168 };
169  
170 package Text::Flowchart::Grid;
171  
172 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
173  
174 1 @ISA = qw(Text::Flowchart);
175  
176 1 $def_width = 72;
177 1 $def_height = 0;
178 1 $def_pad = " ";
179  
180 {
181 1 my $i = 0;
182 1 foreach ($width, $height, $grid, $pad, $debug){
183 5 $_ = $i++
184 };
185
186 };
187  
188 23 ▶sub width {shift->accessor($width, @_)};
Subroutine width: called CC=1 SCAR=0.0
189 10 ▶sub height {shift->accessor($height, @_)};
Subroutine height: called CC=1 SCAR=0.0
190 0 ▶sub grid {shift->accessor($grid, @_)};
Subroutine grid: not called CC=1 SCAR=6.9
191 17 ▶sub pad {shift->accessor($pad, @_)};
Subroutine pad: called CC=1 SCAR=0.0
192 1 ▶sub debug {shift->accessor($debug, @_)};
Subroutine debug: called CC=1 SCAR=0.0
193  
194 1 ▶sub new {
Subroutine new: called CC=8 SCAR=22.6
195 1 my $class = shift;
196 1 my $self = [];
197 1 bless $self, $class;
198 1 my %init = @_;
199
200 1 my $width = $init{"width"};
201 1 my $height = $init{"height"};
202 1 my $pad = $init{"pad"};
203 1 my $debug = $init{"debug"};
204
205 1 ▶ croak("Invalid dimensions.\n") unless $width =~ /^-?\d*$/ && $height =~ /^-?\d*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $width =~ /^-?\d*$/ and $height =~ /^-?\d*$/ 0 1 1
Condition33%1/3
$width =~ /^-?\d*$/ and $height =~ /^-?\d*$/
!ll&&!rl&&r
001
MC/DC0%0/2
$width =~ /^-?\d*$/ and $height =~ /^-?\d*$/
$width =~ /^-?\d*$/ $height =~ /^-?\d*$/
Truth table33%1/3
A and B
A= $width =~ /^-?\d*$/B= $height =~ /^-?\d*$/
ABresult
0X0
100
111
206
207 1 ▶ $self->width($width > 0 ? $width : $def_width);
Branch: 1 branch
BranchTrueFalseTotal
$width > 0 ? : 1 0 1
208 1 ▶ $self->height($height >= 0 ? $height : $def_height);
Branch: 1 branch
BranchTrueFalseTotal
$height >= 0 ? : 0 1 1
209 1 ▶ $self->pad(length $pad == 1 ? $pad : $def_pad);
Branch: 1 branch
BranchTrueFalseTotal
length $pad == 1 ? : 0 1 1
210 1 ▶ $self->debug($debug || 0);
Condition50%1/2
$debug || 0
l!l
01
MC/DC0%0/1
$debug || 0
$debug
Truth table50%1/2
A
A= $debug
Aresult
11
00
211 1 $self->[$grid] = [];
212 1 foreach (1..$self->height){
213 0 push @{$self->[$grid]}, $pad x $self->width();
214 };
215
216 1 return $self;
217  
218 };
219  
220 5 ▶sub insert {
Subroutine insert: called CC=10 SCAR=24.4
221 5 my $self = shift;
222 5 my $box = shift;
223 5 my $x = $box->x_coord();
224 5 my $y = $box->y_coord();
225
226 5 ▶ defined $box || croak("Nothing to insert.\n");
Branch: 1 branch
BranchTrueFalseTotal
defined $box or croak("Nothing to insert.\n") 5 0 5
227 5 ▶ if (($x < 0 || $x + length $box->render->[0] > $self->width) && $self->width != 0) {croak("Your object is too wide for the page.\n")};
Branch: 1 branch
BranchTrueFalseTotal
if ($x < 0 || $x + length($box->render->[0]) > $self->width and $self->width != 0) 1 4 5
Condition66%4/6
$x < 0 || $x + length($box->render->[0]) > $self->width and $self->width != 0
!ll&&!rl&&r
401
$x < 0 or $x + length($box->render->[0]) > $self->width
l!l&&r!l&&!r
014
MC/DC33%1/3
$x < 0 || $x + length($box->render->[0]) > $self->width and $self->width != 0
$x < 0 $x + length($box->render->[0]) > $self->width $self->width != 0
Truth table40%2/5
A or B and C
A= $x < 0B= $x + length($box->render->[0]) > $self->widthC= $self->width != 0
ABCresult
00X0
1X00
0100
1X11
0111
228 0 ▶ if (($y < 0 || $y + @{$box->render()} > $self->height) && $self->height != 0) {croak("Your object is too tall for the page.\n")};
Branch: 1 branch
BranchTrueFalseTotal
if ($y < 0 || $y + @{$box->render;} > $self->height and $self->height != 0) 0 4 4
Condition33%2/6
$y < 0 || $y + @{$box->render;} > $self->height and $self->height != 0
!ll&&!rl&&r
040
$y < 0 or $y + @{$box->render;} > $self->height
l!l&&r!l&&!r
040
MC/DC0%0/3
$y < 0 || $y + @{$box->render;} > $self->height and $self->height != 0
$y < 0 $y + @{$box->render;} > $self->height $self->height != 0
Truth table20%1/5
A or B and C
A= $y < 0B= $y + @{$box->render;} > $self->heightC= $self->height != 0
ABCresult
00X0
1X00
0100
1X11
0111
229 4 foreach $entry (@{$box->render()}){
230 22 my ($line, $offset) = @{$entry};
231 22 ▶ $self->[$grid]->[$y] = $self->pad() x $self->width() unless $self->[$grid]->[$y];
Branch: 1 branch
BranchTrueFalseTotal
unless $self->[$grid][$y] 16 6 22
232 22 substr($self->[$grid]->[$y++], $x + $offset, length $line) = $line;
233 };
234
235 4 return 1;
236 };
237  
238 0 ▶sub repair {
Subroutine repair: not called CC=1 SCAR=6.9
239 0 my $self = shift;
240  
241  
242 0 return 1;
243 };
244  
245  
246  
247 package Text::Flowchart::Shape;
248  
249 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
250  
251 1 $def_width = 15;
252 1 $def_height = 0;
253  
254 1 $PROP_COUNT = 0;
255 1 foreach ($string, $width, $height, $x_coord, $y_coord, $parent,
256 $real_width, $real_height, $rendered){
257 9 $_ = $PROP_COUNT++;
258 };
259  
260  
261 946 ▶sub accessor {
Subroutine accessor: called CC=2 SCAR=6.9
262  
263 946 my $self = shift;
264 946 my $prop = shift;
265  
266 946 ▶ $self->[$prop] = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 215 731 946
267
268 946 return $self->[$prop];
269 };
270  
271 15 ▶sub string {shift->accessor($string, @_)};
Subroutine string: called CC=1 SCAR=0.0
272 15 ▶sub width {shift->accessor($width, @_)};
Subroutine width: called CC=1 SCAR=0.0
273 20 ▶sub height {shift->accessor($height, @_)};
Subroutine height: called CC=1 SCAR=0.0
274 30 ▶sub x_coord {shift->accessor($x_coord, @_)};
Subroutine x_coord: called CC=1 SCAR=0.0
275 30 ▶sub y_coord {shift->accessor($y_coord, @_)};
Subroutine y_coord: called CC=1 SCAR=0.0
276 61 ▶sub parent {shift->accessor($parent, @_)};
Subroutine parent: called CC=1 SCAR=0.0
277 18 ▶sub real_width {shift->accessor($real_width, @_)};
Subroutine real_width: called CC=1 SCAR=0.0
278 17 ▶sub real_height {shift->accessor($real_height, @_)};
Subroutine real_height: called CC=1 SCAR=0.0
279 46 ▶sub rendered {shift->accessor($rendered, @_)};
Subroutine rendered: called CC=1 SCAR=0.0
280  
281 10 ▶sub init {
Subroutine init: called CC=6 SCAR=18.1
282 10 my $class = shift;
283 10 my $self = [];
284 10 bless $self, $class;
285  
286 10 my %init = @_;
287
288 10 ▶ $self->string($init{"string"} || undef);
Condition100%2/2
$init{'string'} || undef
l!l
55
MC/DC100%1/1
$init{'string'} || undef
$init{'string'}
Truth table100%2/2
A
A= $init{'string'}
Aresult
11
00
289 10 ▶ $self->width($init{"width"} > 0 ? $init{"width"} : $def_width);
Branch: 1 branch
BranchTrueFalseTotal
$init{'width'} > 0 ? : 2 8 10
290 10 ▶ $self->height($init{"height"} > 0 ? $init{"height"} : $def_height);
Branch: 1 branch
BranchTrueFalseTotal
$init{'height'} > 0 ? : 0 10 10
291 10 ▶ $self->x_coord($init{"x_coord"} >= 0 ? $init{"x_coord"} : croak("X coordinate must be specified and non-negative\n"));
Branch: 1 branch
BranchTrueFalseTotal
$init{'x_coord'} >= 0 ? : 10 0 10
292 10 ▶ $self->y_coord($init{"y_coord"} >= 0 ? $init{"y_coord"} : croak("X coordinate must be specified and non-negative\n"));
Branch: 1 branch
BranchTrueFalseTotal
$init{'y_coord'} >= 0 ? : 10 0 10
293
294 10 return $self;
295  
296 };
297  
298 package Text::Flowchart::Shape::Box;
299  
300 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
301  
302  
303 1 @ISA = qw(Text::Flowchart::Shape);
304  
305 1 $def_x_pad = 1;
306 1 $def_y_pad = 1;
307  
308 {
309 1 my $PROP_COUNT = $Text::Flowchart::Shape::PROP_COUNT;
310 1 foreach ($x_pad, $y_pad, $format_char, $top_links, $bottom_links, $left_links, $right_links){
311 7 $_ = $PROP_COUNT++;
312 };
313 };
314  
315 15 ▶sub x_pad {shift->accessor($x_pad, @_)};
Subroutine x_pad: called CC=1 SCAR=0.0
316 15 ▶sub y_pad {shift->accessor($y_pad, @_)};
Subroutine y_pad: called CC=1 SCAR=0.0
317 5 ▶sub format_char {shift->accessor($format_char, @_)};
Subroutine format_char: called CC=1 SCAR=0.0
318 7 ▶sub top_links {shift->accessor($top_links, @_)};
Subroutine top_links: called CC=1 SCAR=0.0
319 7 ▶sub bottom_links{shift->accessor($bottom_links, @_)};
Subroutine bottom_links: called CC=1 SCAR=0.0
320 8 ▶sub left_links {shift->accessor($left_links, @_)};
Subroutine left_links: called CC=1 SCAR=0.0
321 8 ▶sub right_links {shift->accessor($right_links, @_)};
Subroutine right_links: called CC=1 SCAR=0.0
322  
323 5 ▶sub relate {
Subroutine relate: called CC=24 SCAR=37.5
324 5 my $from = shift;
325
326 5 my %init = @_;
327
328 5 ▶ my $to = $init{"to"} || croak("No shape to relate to.\n");
Condition50%1/2
$init{'to'} || croak("No shape to relate to.\n")
l!l
50
MC/DC0%0/1
$init{'to'} || croak("No shape to relate to.\n")
$init{'to'}
Truth table50%1/2
A
A= $init{'to'}
Aresult
11
00
329 5 ▶ my $from_side = $init{"from_side"} || croak("No shape to relate from.\n");
Condition50%1/2
$init{'from_side'} || croak("No shape to relate from.\n")
l!l
50
MC/DC0%0/1
$init{'from_side'} || croak("No shape to relate from.\n")
$init{'from_side'}
Truth table50%1/2
A
A= $init{'from_side'}
Aresult
11
00
330 5 ▶ my $to_side = $init{"to_side"} || croak("No side to relate to.\n");
Condition50%1/2
$init{'to_side'} || croak("No side to relate to.\n")
l!l
50
MC/DC0%0/1
$init{'to_side'} || croak("No side to relate to.\n")
$init{'to_side'}
Truth table50%1/2
A
A= $init{'to_side'}
Aresult
11
00
331 5 ▶ my $from_offset = $init{"from_offset"} || 0;
Condition100%2/2
$init{'from_offset'} || 0
l!l
41
MC/DC100%1/1
$init{'from_offset'} || 0
$init{'from_offset'}
Truth table100%2/2
A
A= $init{'from_offset'}
Aresult
11
00
332 5 ▶ my $to_offset = $init{"to_offset"} || 0;
Condition50%1/2
$init{'to_offset'} || 0
l!l
50
MC/DC0%0/1
$init{'to_offset'} || 0
$init{'to_offset'}
Truth table50%1/2
A
A= $init{'to_offset'}
Aresult
11
00
333 5 ▶ my $reason = $init{"reason"} || undef;
Condition100%2/2
$init{'reason'} || undef
l!l
23
MC/DC100%1/1
$init{'reason'} || undef
$init{'reason'}
Truth table100%2/2
A
A= $init{'reason'}
Aresult
11
00
334  
335 0 ▶ if ($from->parent() ne $to->parent){croak("No shape to relate to.\n")};
Branch: 1 branch
BranchTrueFalseTotal
if ($from->parent ne $to->parent) 0 5 5
336 0 ▶ if ($from_side !~ /^(top|bottom|right|left)$/){croak("Invalid side. Side must be 'top', 'bottom', 'left', or 'right'.\n")};
Branch: 1 branch
BranchTrueFalseTotal
unless ($from_side =~ /^(top|bottom|right|left)$/) 0 5 5
337 0 ▶ if ($to_side !~ /^(top|bottom|right|left)$/){croak("Invalid side. Side must be 'top', 'bottom', 'left', or 'right'.\n")};
Branch: 1 branch
BranchTrueFalseTotal
unless ($to_side =~ /^(top|bottom|right|left)$/) 0 5 5
338 0 ▶ if ($from_side eq $to_side){croak("Cannot relate the same sides of boxes. Use different sides.\n")};
Branch: 1 branch
BranchTrueFalseTotal
if ($from_side eq $to_side) 0 5 5
339 0 ▶ if (length $reason > 1){croak("Reasons must be a single character.\n")};
Branch: 1 branch
BranchTrueFalseTotal
if (length $reason > 1) 0 5 5
340  
341  
342 5 my $from_coords = $from->get_next_coord($from_side, $from_offset);
343 5 my $to_coords = $to->get_next_coord($to_side, $to_offset);
344  
345 5 my $orientation = undef;
346
347 5 ▶ if ($from_side =~ m/^(lef|righ)t$/ && $to_side =~ m/^(lef|righ)t$/){$orientation = "H"}
Branch: 6 branches
BranchTrueFalseTotal
if ($from_side =~ /^(lef|righ)t$/ and $to_side =~ /^(lef|righ)t$/) { } 1 4 5
elsif ($from_side =~ /^(top|bottom)$/ and $to_side =~ /^(top|bottom)$/) { } 0 4 4
elsif ($from_side eq 'top' and $to_side =~ /^(lef|righ)t$/) { } 0 4 4
elsif ($from_side eq 'bottom' and $to_side =~ /^(lef|righ)t$/) { } 1 3 4
elsif ($from_side =~ /^(lef|righ)t$/ and $to_side eq 'bottom') { } 1 2 3
elsif ($from_side =~ /^(lef|righ)t$/ and $to_side eq 'top') { } 2 0 2
Condition100%3/3
$from_side =~ /^(lef|righ)t$/ and $to_side =~ /^(lef|righ)t$/
!ll&&!rl&&r
131
MC/DC100%2/2
$from_side =~ /^(lef|righ)t$/ and $to_side =~ /^(lef|righ)t$/
$from_side =~ /^(lef|righ)t$/ $to_side =~ /^(lef|righ)t$/
Truth table100%3/3
A and B
A= $from_side =~ /^(lef|righ)t$/B= $to_side =~ /^(lef|righ)t$/
ABresult
0X0
100
111
348 0 ▶ elsif ($from_side =~ m/^(top|bottom)$/ && $to_side =~ m/^(top|bottom)$/){$orientation = "V"}
Condition66%2/3
$from_side =~ /^(top|bottom)$/ and $to_side =~ /^(top|bottom)$/
!ll&&!rl&&r
310
MC/DC0%0/2
$from_side =~ /^(top|bottom)$/ and $to_side =~ /^(top|bottom)$/
$from_side =~ /^(top|bottom)$/ $to_side =~ /^(top|bottom)$/
Truth table66%2/3
A and B
A= $from_side =~ /^(top|bottom)$/B= $to_side =~ /^(top|bottom)$/
ABresult
0X0
100
111
349 0 ▶ elsif ($from_side eq "top" && $to_side =~ m/^(lef|righ)t$/){$orientation = "TC"}
Condition33%1/3
$from_side eq "top" and $to_side =~ /^(lef|righ)t$/
!ll&&!rl&&r
400
MC/DC0%0/2
$from_side eq "top" and $to_side =~ /^(lef|righ)t$/
$from_side eq "top" $to_side =~ /^(lef|righ)t$/
Truth table33%1/3
A and B
A= $from_side eq "top"B= $to_side =~ /^(lef|righ)t$/
ABresult
0X0
100
111
350 1 ▶ elsif ($from_side eq "bottom" && $to_side =~ m/^(lef|righ)t$/){$orientation = "BC"}
Condition66%2/3
$from_side eq "bottom" and $to_side =~ /^(lef|righ)t$/
!ll&&!rl&&r
301
MC/DC50%1/2
$from_side eq "bottom" and $to_side =~ /^(lef|righ)t$/
$from_side eq "bottom" $to_side =~ /^(lef|righ)t$/
Truth table66%2/3
A and B
A= $from_side eq "bottom"B= $to_side =~ /^(lef|righ)t$/
ABresult
0X0
100
111
351 1 ▶ elsif ($from_side =~ m/^(lef|righ)t$/ && $to_side eq "bottom"){$orientation = "BC"}
Condition66%2/3
$from_side =~ /^(lef|righ)t$/ and $to_side eq "bottom"
!ll&&!rl&&r
021
MC/DC50%1/2
$from_side =~ /^(lef|righ)t$/ and $to_side eq "bottom"
$from_side =~ /^(lef|righ)t$/ $to_side eq "bottom"
Truth table66%2/3
A and B
A= $from_side =~ /^(lef|righ)t$/B= $to_side eq "bottom"
ABresult
0X0
100
111
352 2 ▶ elsif ($from_side =~ m/^(lef|righ)t$/ && $to_side eq "top"){$orientation = "TC"};
Condition33%1/3
$from_side =~ /^(lef|righ)t$/ and $to_side eq "top"
!ll&&!rl&&r
002
MC/DC0%0/2
$from_side =~ /^(lef|righ)t$/ and $to_side eq "top"
$from_side =~ /^(lef|righ)t$/ $to_side eq "top"
Truth table33%1/3
A and B
A= $from_side =~ /^(lef|righ)t$/B= $to_side eq "top"
ABresult
0X0
100
111
353 5 $from->parent->line(
354 "from" => $from_coords,
355 "to" => $to_coords,
356 "orientation" => $orientation,
357 "reason" => $reason
358 );
359
360 5 return 1;
361
362 };
363  
364 10 ▶sub get_next_coord {
Subroutine get_next_coord: called CC=8 SCAR=21.1
365 10 my $self = shift;
366 10 $i =0;
367 10 ▶ my $side = shift || return "SIDE";
Condition50%1/2
shift() || (return 'SIDE')
l!l
100
MC/DC0%0/1
shift() || (return 'SIDE')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
368 10 ▶ my $offset = shift || "0";
Condition100%2/2
shift() || '0'
l!l
91
MC/DC100%1/1
shift() || '0'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
369 10 my %map = ("top" => $top_links, "bottom" => $bottom_links,
370 "left" => $left_links, "right" => $right_links);
371  
372 10 my $side_num = $map{$side};
373 10 ▶ return "COUNT $side" if scalar $self->[$side_num] <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar $self->[$side_num] <= 0 0 10 10
374
375
376 10 ▶ if ($side eq "top"){
Branch: 4 branches
BranchTrueFalseTotal
if ($side eq 'top') { } 2 8 10
elsif ($side eq 'bottom') { } 2 6 8
elsif ($side eq 'left') { } 3 3 6
elsif ($side eq 'right') { } 3 0 3
377 2 return [$self->x_coord() + $self->_get_offset($self->top_links(), $offset), $self->y_coord()];
378
379 }
380 elsif ($side eq "bottom"){
381 2 return [$self->x_coord() + $self->_get_offset($self->bottom_links(), $offset), $self->y_coord() + $self->real_height() - 1];
382 }
383 elsif ($side eq "left"){
384 3 return [$self->x_coord(), $self->y_coord() + $self->_get_offset($self->left_links(), $offset)];
385 }
386 elsif ($side eq "right"){
387 3 return [$self->x_coord() + $self->real_width() - 1, $self->y_coord() + $self->_get_offset($self->right_links(), $offset)];
388 }
389 0 else {return "ORIENT"};
390
391 };
392  
393 10 ▶sub _get_offset {
Subroutine _get_offset: called CC=7 SCAR=20.3
394 10 my $self = shift;
395 10 ▶ my $side = shift || croak("No side supplied to _get_offset.\n");
Condition50%1/2
shift() || croak("No side supplied to _get_offset.\n")
l!l
100
MC/DC0%0/1
shift() || croak("No side supplied to _get_offset.\n")
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
396 10 my $offset = shift;
397 10 my $real_offset = 0;
398
399 10 ▶ if ($offset == 0){$real_offset = shift @{$side}; $real_offset++}
Branch: 2 branches
BranchTrueFalseTotal
if ($offset == 0) { } 1 9 10
elsif ($offset == -1) { } 0 9 9
400 0 elsif ($offset == -1){$real_offset = pop @{$side};}
401 else {
402 9 my ($i, $found) = (0,0);
403 9 foreach $i (0.. $#{$side}){
404 37 ▶ if ($side->[$i] == $offset){
Branch: 1 branch
BranchTrueFalseTotal
if ($side->[$i] == $offset) 9 28 37
405 9 $found++;
406 9 $real_offset = $side->[$i] + 1;
407 9 splice(@{$side}, $i, 1);
408 9 last;
409 };
410 };
411 0 ▶ unless ($found){$real_offset = shift @{$side}; $real_offset++};
Branch: 1 branch
BranchTrueFalseTotal
unless ($found) 0 9 9
412  
413 };
414  
415 10 return $real_offset;
416 };
417  
418 5 ▶sub new {
Subroutine new: called CC=15 SCAR=28.9
419 5 my $class = shift;
420 5 my $self = $class->init(@_);
421  
422 5 my %init = @_;
423
424 5 ▶ $self->x_pad(defined $init{"x_pad"} && $init{"x_pad"} >= 0 ? $init{"x_pad"} : $def_x_pad);
Branch: 1 branch
BranchTrueFalseTotal
defined $init{'x_pad'} && $init{'x_pad'} >= 0 ? : 0 5 5
Condition33%1/3
defined $init{"x_pad"} and $init{"x_pad"} >= 0
!ll&&!rl&&r
500
MC/DC0%0/2
defined $init{"x_pad"} and $init{"x_pad"} >= 0
defined $init{"x_pad"} $init{"x_pad"} >= 0
Truth table33%1/3
A and B
A= defined $init{"x_pad"}B= $init{"x_pad"} >= 0
ABresult
0X0
100
111
425 5 ▶ $self->y_pad(defined $init{"y_pad"} && $init{"y_pad"} >= 0 ? $init{"y_pad"} : $def_y_pad);
Branch: 1 branch
BranchTrueFalseTotal
defined $init{'y_pad'} && $init{'y_pad'} >= 0 ? : 1 4 5
Condition66%2/3
defined $init{"y_pad"} and $init{"y_pad"} >= 0
!ll&&!rl&&r
401
MC/DC50%1/2
defined $init{"y_pad"} and $init{"y_pad"} >= 0
defined $init{"y_pad"} $init{"y_pad"} >= 0
Truth table66%2/3
A and B
A= defined $init{"y_pad"}B= $init{"y_pad"} >= 0
ABresult
0X0
100
111
426 5 ▶ $self->format_char(defined $init{"format_char"} ? $init{"format_char"} : undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $init{'format_char'} ? : 0 5 5
427 5 ▶ $self->parent($init{"parent"} || undef);
Condition50%1/2
$init{'parent'} || undef
l!l
50
MC/DC0%0/1
$init{'parent'} || undef
$init{'parent'}
Truth table50%1/2
A
A= $init{'parent'}
Aresult
11
00
428  
429 5 ▶ croak("Invalid width.\n") if $self->width() - 2 - $self->x_pad() * 2 < 1 && $self->width() > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->width - 2 - $self->x_pad * 2 < 1 and $self->width > 0 0 5 5
Condition33%1/3
$self->width - 2 - $self->x_pad * 2 < 1 and $self->width > 0
!ll&&!rl&&r
500
MC/DC0%0/2
$self->width - 2 - $self->x_pad * 2 < 1 and $self->width > 0
$self->width - 2 - $self->x_pad * 2 < 1 $self->width > 0
Truth table33%1/3
A and B
A= $self->width - 2 - $self->x_pad * 2 < 1B= $self->width > 0
ABresult
0X0
100
111
430 5 ▶ croak("Invalid height.\n") if $self->height() - 2 - $self->y_pad() * 2 < 1 && $self->height() > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->height - 2 - $self->y_pad * 2 < 1 and $self->height > 0 0 5 5
Condition33%1/3
$self->height - 2 - $self->y_pad * 2 < 1 and $self->height > 0
!ll&&!rl&&r
050
MC/DC0%0/2
$self->height - 2 - $self->y_pad * 2 < 1 and $self->height > 0
$self->height - 2 - $self->y_pad * 2 < 1 $self->height > 0
Truth table33%1/3
A and B
A= $self->height - 2 - $self->y_pad * 2 < 1B= $self->height > 0
ABresult
0X0
100
111
431
432 5 $self->render();
433
434 5 my @top_links = ();
435 5 my @bottom_links = ();
436 5 my @left_links = ();
437 5 my @right_links = ();
438
439 5 foreach my $i (0..$self->real_width() - 2){push @top_links, $i};
440 5 foreach my $i (0..$self->real_width() - 2){push @bottom_links, $i};
441 5 foreach my $i (0..$self->real_height() - 2){push @left_links, $i};
442 5 foreach my $i (0..$self->real_height() - 2){push @right_links, $i};
443  
444 5 $self->top_links(\@top_links);
445 5 $self->bottom_links(\@bottom_links);
446 5 $self->left_links(\@left_links);
447 5 $self->right_links(\@right_links);
448  
449 5 return $self;
450  
451 };
452  
453 18 ▶sub render {
Subroutine render: called CC=18 SCAR=31.7
454 18 my $self = shift;
455
456 18 ▶ return $self->rendered() if $self->rendered();
Branch: 1 branch
BranchTrueFalseTotal
if $self->rendered 13 5 18
457
458 5 my $string = $self->string();
459 5 my $width = $self->width();
460 5 my $height = $self->height();
461 5 my $x_pad = $self->x_pad();
462 5 my $y_pad = $self->y_pad();
463 5 my $page_width = $self->parent->size->[0];
464 5 my $page_height = $self->parent->size->[1];
465
466 5 ▶ my $box_width = ($width < $page_width || $page_width == 0 ? $width : $page_width );
Branch: 1 branch
BranchTrueFalseTotal
$width < $page_width || $page_width == 0 ? : 5 0 5
Condition33%1/3
$width < $page_width or $page_width == 0
l!l&&r!l&&!r
500
MC/DC0%0/2
$width < $page_width or $page_width == 0
$width < $page_width $page_width == 0
Truth table33%1/3
A or B
A= $width < $page_widthB= $page_width == 0
ABresult
1X1
011
000
467 5 ▶ my $box_height = ($height < $page_height || $page_height == 0 ? $height : $page_height);
Branch: 1 branch
BranchTrueFalseTotal
$height < $page_height || $page_height == 0 ? : 5 0 5
Condition33%1/3
$height < $page_height or $page_height == 0
l!l&&r!l&&!r
050
MC/DC0%0/2
$height < $page_height or $page_height == 0
$height < $page_height $page_height == 0
Truth table33%1/3
A or B
A= $height < $page_heightB= $page_height == 0
ABresult
1X1
011
000
468
469 5 my $wrap_width = $box_width - 2 - $x_pad * 2;
470 5 my $wrap_height = $box_height - 2 - $y_pad * 2;
471
472
473  
474 5 ▶ $string =~ s/(.{1,$wrap_width}(?:\b|$)|\S{$wrap_width})\s*/$1\n$2/g unless $box_width == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $box_width == 0 5 0 5
475 5 my @string = split(/\n/, $string);
476 5 foreach (@string){
477 11 ▶ if (length $_ + 2 * $x_pad < $wrap_width) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_ + 2 * $x_pad < $wrap_width) 11 0 11
478 11 $_ .= " " x ($wrap_width - (length $_));
479 };
480 11 s/^/"|" . " " x $x_pad/gme;
481 11 s/$/(" " x $x_pad) . "|"/gme;
482 11 $_ = [$_, 0];
483 };
484 5 ▶ @string = splice(@string, 0, $wrap_height) unless $box_height == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $box_height == 0 0 5 5
485
486 5 ▶ while ($y_pad-- > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y_pad-- > 0) 4 5 9
487 4 ▶ push @string, ["|" . " " x ($box_width ? $box_width - 2 : (length $string) + $x_pad * 2) . "|", 0];
Branch: 1 branch
BranchTrueFalseTotal
$box_width ? : 4 0 4
488 4 ▶ unshift @string, ["|" . " " x ($box_width ? $box_width - 2 : (length $string) + $x_pad * 2) . "|", 0];
Branch: 1 branch
BranchTrueFalseTotal
$box_width ? : 4 0 4
489 };
490
491 5 my $remaining_height = $box_height - @string - 2; #don't forget to drop 2 for the top and bottom lines!
492
493 5 ▶ while ($remaining_height-- > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remaining_height-- > 0) 0 5 5
494 0 ▶ push @string, ["|" . " " x ($box_width ? $box_width - 2 : (length $string) + $x_pad * 2) . "|", 0];
Branch: 1 branch
BranchTrueFalseTotal
$box_width ? : 0 0 0
495 };
496
497 5 ▶ push @string, ["+" . "-" x ($box_width ? $box_width - 2 : (length $string) + $x_pad * 2) . "+", 0];
Branch: 1 branch
BranchTrueFalseTotal
$box_width ? : 5 0 5
498 5 ▶ unshift @string, ["+" . "-" x ($box_width ? $box_width - 2 : (length $string) + $x_pad * 2) . "+", 0];
Branch: 1 branch
BranchTrueFalseTotal
$box_width ? : 5 0 5
499
500 5 ▶ $self->real_width($box_width ? $box_width : (length $string) + $x_pad * 2 + 2);
Branch: 1 branch
BranchTrueFalseTotal
$box_width ? : 5 0 5
501 5 $self->real_height(scalar @string);
502
503 5 return $self->rendered(\@string);
504
505  
506 };
507  
508  
509  
510 package Text::Flowchart::Shape::Line;
511  
512 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
513  
514  
515 1 @ISA = qw(Text::Flowchart::Shape);
516  
517 {
518 1 my $PROP_COUNT = $Text::Flowchart::Shape::PROP_COUNT;
519 1 foreach ($from, $to, $reason, $orientation, $xfrom, $xto, $yfrom, $yto, $xdistance, $ydistance,
520 $xleft, $xright, $ytop, $ybottom, $xmiddle, $ymiddle, $width, $height){
521 18 $_ = $PROP_COUNT++;
522 };
523
524 };
525  
526 15 ▶sub from {shift->accessor($from, @_)};
Subroutine from: called CC=1 SCAR=0.0
527 15 ▶sub to {shift->accessor($to, @_)};
Subroutine to: called CC=1 SCAR=0.0
528 17 ▶sub reason {shift->accessor($reason, @_)};
Subroutine reason: called CC=1 SCAR=0.0
529 11 ▶sub orientation {shift->accessor($orientation, @_)};
Subroutine orientation: called CC=1 SCAR=0.0
530 98 ▶sub xfrom {shift->accessor($xfrom, @_)};
Subroutine xfrom: called CC=1 SCAR=0.0
531 95 ▶sub xto {shift->accessor($xto, @_)};
Subroutine xto: called CC=1 SCAR=0.0
532 99 ▶sub yfrom {shift->accessor($yfrom, @_)};
Subroutine yfrom: called CC=1 SCAR=0.0
533 96 ▶sub yto {shift->accessor($yto, @_)};
Subroutine yto: called CC=1 SCAR=0.0
534 53 ▶sub xdistance {shift->accessor($xdistance, @_)};
Subroutine xdistance: called CC=1 SCAR=0.0
535 37 ▶sub ydistance {shift->accessor($ydistance, @_)};
Subroutine ydistance: called CC=1 SCAR=0.0
536 14 ▶sub xleft {shift->accessor($xleft, @_)};
Subroutine xleft: called CC=1 SCAR=0.0
537 8 ▶sub xright {shift->accessor($xright, @_)};
Subroutine xright: called CC=1 SCAR=0.0
538 13 ▶sub ytop {shift->accessor($ytop, @_)};
Subroutine ytop: called CC=1 SCAR=0.0
539 7 ▶sub ybottom {shift->accessor($ybottom, @_)};
Subroutine ybottom: called CC=1 SCAR=0.0
540 6 ▶sub xmiddle {shift->accessor($xmiddle, @_)};
Subroutine xmiddle: called CC=1 SCAR=0.0
541 5 ▶sub ymiddle {shift->accessor($ymiddle, @_)};
Subroutine ymiddle: called CC=1 SCAR=0.0
542 25 ▶sub width {shift->accessor($width, @_)};
Subroutine width: called CC=1 SCAR=0.0
543 15 ▶sub height {shift->accessor($height, @_)};
Subroutine height: called CC=1 SCAR=0.0
544  
545 5 ▶sub new {
Subroutine new: called CC=16 SCAR=33.2
546  
547 5 my $class = shift;
548 5 my $self = $class->init(@_);
549  
550 5 ▶ if ($class eq "Text::Flowchart::Shape::Line"){
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq 'Text::Flowchart::Shape::Line') { } 0 5 5
551 0 ▶ if ($class eq "Text::Flowchart::Shape::Line::Horizontal"){
Branch: 3 branches
BranchTrueFalseTotal
if ($class eq 'Text::Flowchart::Shape::Line::Horizontal') { } 0 0 0
elsif ($class eq 'Text::Flowchart::Shape::Line::Vertical') { } 0 0 0
elsif ($class eq 'Text::Flowchart::Shape::Line::Corner') { } 0 0 0
552 0 return Text::Flowcahrt::Shape::Line::Horizontal->new(@_);
553 }
554 elsif ($class eq "Text::Flowchart::Shape::Line::Vertical"){
555 0 return Text::Flowcahrt::Shape::Line::Vertical->new(@_);
556 }
557 elsif ($class eq "Text::Flowchart::Shape::Line::Corner"){
558 0 return Text::Flowcahrt::Shape::Line::Corner->new(@_);
559 };
560 }
561 else {
562  
563 5 my %init = @_;
564
565
566 5 ▶ if (ref $init{"from"} eq "ARRAY" && @{$init{"from"}} == 2){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $init{'from'} eq 'ARRAY' and @{$init{'from'};} == 2) { } 5 0 5
Condition33%1/3
ref $init{"from"} eq "ARRAY" and @{$init{"from"};} == 2
!ll&&!rl&&r
005
MC/DC0%0/2
ref $init{"from"} eq "ARRAY" and @{$init{"from"};} == 2
ref $init{"from"} eq "ARRAY" @{$init{"from"};} == 2
Truth table33%1/3
A and B
A= ref $init{"from"} eq "ARRAY"B= @{$init{"from"};} == 2
ABresult
0X0
100
111
567 5 $self->from($init{"from"});
568 }
569 else {
570 0 croak("Invalid from coordinates, should be [x,y]");
571 };
572
573 5 ▶ if (ref $init{"to"} eq "ARRAY" && @{$init{"from"}} == 2){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $init{'to'} eq 'ARRAY' and @{$init{'from'};} == 2) { } 5 0 5
Condition33%1/3
ref $init{"to"} eq "ARRAY" and @{$init{"from"};} == 2
!ll&&!rl&&r
005
MC/DC0%0/2
ref $init{"to"} eq "ARRAY" and @{$init{"from"};} == 2
ref $init{"to"} eq "ARRAY" @{$init{"from"};} == 2
Truth table33%1/3
A and B
A= ref $init{"to"} eq "ARRAY"B= @{$init{"from"};} == 2
ABresult
0X0
100
111
574 5 $self->to($init{"to"});
575 }
576 else {
577 0 croak("Invalid to coordinates, should be [x,y]");
578 };
579
580 5 ▶ $self->reason($init{"reason"} || undef);
Condition100%2/2
$init{'reason'} || undef
l!l
23
MC/DC100%1/1
$init{'reason'} || undef
$init{'reason'}
Truth table100%2/2
A
A= $init{'reason'}
Aresult
11
00
581 5 ▶ $self->orientation($init{"orientation"} || croak("I require an orientation. 'HR', 'HL', 'VT', 'VB' please.\n"));
Condition50%1/2
$init{'orientation'} || croak("I require an orientation. 'HR', 'HL', 'VT', 'VB' please.\n")
l!l
50
MC/DC0%0/1
$init{'orientation'} || croak("I require an orientation. 'HR', 'HL', 'VT', 'VB' please.\n")
$init{'orientation'}
Truth table50%1/2
A
A= $init{'orientation'}
Aresult
11
00
582 5 ▶ $self->parent($init{"parent"} || undef);
Condition50%1/2
$init{'parent'} || undef
l!l
50
MC/DC0%0/1
$init{'parent'} || undef
$init{'parent'}
Truth table50%1/2
A
A= $init{'parent'}
Aresult
11
00
583
584 5 $self->xfrom($self->from->[0]);
585 5 $self->yfrom($self->from->[1]);
586
587 5 $self->xto($self->to->[0]);
588 5 $self->yto($self->to->[1]);
589
590 5 $self->width(abs ($self->xfrom() - $self->xto()) + 1);
591 5 $self->height(abs ($self->yfrom() - $self->yto()) + 1);
592
593 0 ▶ unless ($self->width() == 1 || $self->width() > 2){croak("Invalid width. Make your shape wider.\n")};
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->width == 1 or $self->width > 2) 0 5 5
Condition33%1/3
$self->width == 1 or $self->width > 2
l!l&&r!l&&!r
050
MC/DC0%0/2
$self->width == 1 or $self->width > 2
$self->width == 1 $self->width > 2
Truth table33%1/3
A or B
A= $self->width == 1B= $self->width > 2
ABresult
1X1
011
000
594
595 5 $self->xdistance($self->width() - 2);
596 5 $self->ydistance($self->height() - 2);
597
598 5 $self->xleft(int ($self->xdistance() / 2));
599 5 $self->ytop(int ($self->ydistance() / 2));
600
601 5 $self->xright($self->xdistance() - $self->xleft() - 1);
602 5 $self->ybottom($self->ydistance() - $self->ytop() - 1);
603
604
605 5 ▶ $self->xmiddle(1 + ($self->offset() ? $self->xleft() : $self->xright()));
Branch: 1 branch
BranchTrueFalseTotal
$self->offset ? : 3 2 5
606 5 ▶ $self->ymiddle(1 + ($self->offset() ? $self->ytop() : $self->ybottom()));
Branch: 1 branch
BranchTrueFalseTotal
$self->offset ? : 3 2 5
607  
608 5 $self->render();
609
610 5 return $self;
611
612 };
613  
614 };
615  
616 55 ▶sub offset {
Subroutine offset: called CC=4 SCAR=15.0
617 55 my $self = shift;
618  
619 55 ▶ return (($self->xfrom() > $self->xto()) xor ($self->yto() > $self->yfrom())) ||
Condition63%7/11
$self->xfrom > $self->xto ^^ $self->yto > $self->yfrom || ($self->xfrom < $self->xto ^^ $self->yto < $self->yfrom)
l!l&&r!l&&!r
38017
$self->xfrom > $self->xto xor $self->yto > $self->yfrom
l&&rl&&!r!l&&r!l&&!r
100387
$self->xfrom < $self->xto xor $self->yto < $self->yfrom
l&&rl&&!r!l&&r!l&&!r
70010
MC/DC50%2/4
$self->xfrom > $self->xto ^^ $self->yto > $self->yfrom || ($self->xfrom < $self->xto ^^ $self->yto < $self->yfrom)
$self->xfrom > $self->xto $self->yto > $self->yfrom $self->xfrom < $self->xto $self->yto < $self->yfrom
Truth table30%3/10
A xor B || C xor D
A= $self->xfrom > $self->xtoB= $self->yto > $self->yfromC= $self->xfrom < $self->xtoD= $self->yto < $self->yfrom
ABCDresult
10XX1
01XX1
11101
11011
00101
00011
11110
11000
00110
00000
620 (($self->xfrom() < $self->xto()) xor ($self->yto() < $self->yfrom()));
621 };
622  
623 10 ▶sub end_char {
Subroutine end_char: called CC=15 SCAR=31.7
624 10 my $self = shift;
625
626 10 my $direction = shift;
627 10 ▶ if ($direction =~ /V/){
Branch: 2 branches
BranchTrueFalseTotal
if ($direction =~ /V/) { } 4 6 10
elsif ($direction =~ /H/) { } 6 0 6
628 4 ▶ if ($self->reason()){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->reason) 2 2 4
629 2 ▶ if (($self->yfrom() < $self->yto() && $direction eq "VT")
Branch: 1 branch
BranchTrueFalseTotal
if ($self->yfrom < $self->yto and $direction eq "VT" or $self->yfrom > $self->yto and $direction eq "VB") 0 2 2
Condition33%3/9
$self->yfrom < $self->yto and $direction eq "VT" or $self->yfrom > $self->yto and $direction eq "VB"
l!l&&r!l&&!r
002
$self->yfrom < $self->yto and $direction eq "VT"
!ll&&!rl&&r
020
$self->yfrom > $self->yto and $direction eq "VB"
!ll&&!rl&&r
200
MC/DC0%0/4
$self->yfrom < $self->yto and $direction eq "VT" or $self->yfrom > $self->yto and $direction eq "VB"
$self->yfrom < $self->yto $direction eq "VT" $self->yfrom > $self->yto $direction eq "VB"
Truth table14%1/7
A and B or C and D
A= $self->yfrom < $self->ytoB= $direction eq "VT"C= $self->yfrom > $self->ytoD= $direction eq "VB"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
630 || ($self->yfrom() > $self->yto() && $direction eq "VB")){
631 0 return $self->reason()};
632 };
633
634 4 ▶ if ($self->yfrom() < $self->yto()){return "V"}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->yfrom < $self->yto) { } 3 1 4
635 1 else {return "^"};
636 }
637 elsif ($direction =~ /H/){
638 6 ▶ if ($self->reason()){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->reason) 2 4 6
639 2 ▶ if (($self->xfrom() < $self->xto() && $direction eq "HL")
Branch: 1 branch
BranchTrueFalseTotal
if ($self->xfrom < $self->xto and $direction eq "HL" or $self->xfrom > $self->xto and $direction eq "HR") 2 0 2
Condition55%5/9
$self->xfrom < $self->xto and $direction eq "HL" or $self->xfrom > $self->xto and $direction eq "HR"
l!l&&r!l&&!r
110
$self->xfrom < $self->xto and $direction eq "HL"
!ll&&!rl&&r
101
$self->xfrom > $self->xto and $direction eq "HR"
!ll&&!rl&&r
001
MC/DC0%0/4
$self->xfrom < $self->xto and $direction eq "HL" or $self->xfrom > $self->xto and $direction eq "HR"
$self->xfrom < $self->xto $direction eq "HL" $self->xfrom > $self->xto $direction eq "HR"
Truth table28%2/7
A and B or C and D
A= $self->xfrom < $self->xtoB= $direction eq "HL"C= $self->xfrom > $self->xtoD= $direction eq "HR"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
640 || ($self->xfrom() > $self->xto() && $direction eq "HR")){
641 2 return $self->reason()};
642 };
643
644 4 ▶ if ($self->xfrom() < $self->xto()){return ">"}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->xfrom < $self->xto) { } 4 0 4
645 0 else {return "<"};
646 }
647 0 else {croak("Invalid direction for end_char. Must be 'HR', 'HL', 'VT', or 'VB'.\n")};
648 };
649  
650 16 ▶sub end {
Subroutine end: called CC=8 SCAR=21.4
651 16 my $self = shift;
652  
653 16 ▶ return "+" unless $self->parent->directed();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->parent->directed 0 16 16
654  
655 16 my $arg = shift;
656 16 my $direction = shift;
657
658 16 ▶ if ($self->xdistance >= 0 && $self->ydistance >= 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->xdistance >= 0 and $self->ydistance >= 0) { } 16 0 16
Condition33%1/3
$self->xdistance >= 0 and $self->ydistance >= 0
!ll&&!rl&&r
0016
MC/DC0%0/2
$self->xdistance >= 0 and $self->ydistance >= 0
$self->xdistance >= 0 $self->ydistance >= 0
Truth table33%1/3
A and B
A= $self->xdistance >= 0B= $self->ydistance >= 0
ABresult
0X0
100
111
659  
660 16 ▶ if ($arg == 1) {return $self->offset() ? "+" : $self->end_char($direction)}
Branch: 3 branches
BranchTrueFalseTotal
if ($arg == 1) { } 6 10 16
elsif ($arg == 2) { } 6 4 10
$self->offset ? : 4 2 6
661 6 ▶ elsif ($arg == 2) {return $self->offset() ? $self->end_char($direction) : "+"}
Branch: 1 branch
BranchTrueFalseTotal
$self->offset ? : 4 2 6
662 4 else {return $self->end_char($direction)};
663 }
664 0 else {return $self->end_char($direction)};
665
666 };
667  
668 package Text::Flowchart::Shape::Line::Horizontal;
669  
670 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
671  
672  
673 1 @ISA = qw(Text::Flowchart::Shape::Line);
674  
675 1 ▶sub render {
Subroutine render: called CC=10 SCAR=28.7
676 1 my $self = shift;
677
678 1 ▶ return $self->rendered() if $self->rendered();
Branch: 1 branch
BranchTrueFalseTotal
if $self->rendered 0 1 1
679
680
681 1 my @string = ();
682
683 1 ▶ if ($self->xdistance() >= 0 && $self->ydistance() >= 0){
Branch: 2 branches
BranchTrueFalseTotal
if ($self->xdistance >= 0 and $self->ydistance >= 0) { } 1 0 1
elsif ($self->xdistance > 0) { } 0 0 0
Condition33%1/3
$self->xdistance >= 0 and $self->ydistance >= 0
!ll&&!rl&&r
001
MC/DC0%0/2
$self->xdistance >= 0 and $self->ydistance >= 0
$self->xdistance >= 0 $self->ydistance >= 0
Truth table33%1/3
A and B
A= $self->xdistance >= 0B= $self->ydistance >= 0
ABresult
0X0
100
111
684 1 ▶ push @string, [$self->end(2, "HL") . ("-" x $self->xleft()) . $self->end(1, "HR"), $self->offset() ? 0 : $self->xmiddle()];
Branch: 1 branch
BranchTrueFalseTotal
$self->offset ? : 1 0 1
685 1 my $yd2 = $self->ydistance();
686 1 ▶ while ($yd2-- > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($yd2-- > 0) 0 1 1
687 0 push @string, ["|", $self->xmiddle()];
688 };
689
690 1 ▶ push @string, [$self->end(1, "HL") . ("-" x $self->xright()) . $self->end(2, "HR"), $self->offset() ? $self->xmiddle() : 0];
Branch: 1 branch
BranchTrueFalseTotal
$self->offset ? : 1 0 1
691  
692 }
693 elsif ($self->xdistance() > 0) {
694 0 push @string, [$self->end(0, "HL") . ("-" x $self->xdistance()) . $self->end(0, "HR"), 0];
695 }
696 0 else {croak("You're trying to draw a vertical line with a horizontal object. Use a Vertical line.\n")};
697  
698 1 ▶ $self->x_coord($self->xfrom() > $self->xto() ? $self->xto() : $self->xfrom());
Branch: 1 branch
BranchTrueFalseTotal
$self->xfrom > $self->xto ? : 0 1 1
699 1 ▶ $self->y_coord($self->yfrom() > $self->yto() ? $self->yto() : $self->yfrom());
Branch: 1 branch
BranchTrueFalseTotal
$self->yfrom > $self->yto ? : 0 1 1
700 1 return $self->rendered(\@string);
701 };
702  
703 package Text::Flowchart::Shape::Line::Vertical;
704  
705 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
706  
707  
708 1 @ISA = qw(Text::Flowchart::Shape::Line);
709  
710 0 ▶sub render {
Subroutine render: not called CC=14 SCAR=53.5
711 0 my $self = shift;
712
713 0 ▶ return $self->rendered() if $self->rendered();
Branch: 1 branch
BranchTrueFalseTotal
if $self->rendered 0 0 0
714
715 0 my @string = ();
716
717 0 ▶ if ($self->xdistance() >= 0 && $self->ydistance() >= 0){
Branch: 2 branches
BranchTrueFalseTotal
if ($self->xdistance >= 0 and $self->ydistance >= 0) { } 0 0 0
elsif ($self->ydistance > 0) { } 0 0 0
Condition0%0/3
$self->xdistance >= 0 and $self->ydistance >= 0
!ll&&!rl&&r
000
MC/DC0%0/2
$self->xdistance >= 0 and $self->ydistance >= 0
$self->xdistance >= 0 $self->ydistance >= 0
Truth table0%0/3
A and B
A= $self->xdistance >= 0B= $self->ydistance >= 0
ABresult
0X0
100
111
718 0 ▶ push @string, [$self->end(0, "VT"), $self->offset() ? 0 : $self->xdistance() + 1];
Branch: 1 branch
BranchTrueFalseTotal
$self->offset ? : 0 0 0
719 0 my $yd2 = $self->ytop();
720 0 ▶ while ($yd2-- > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($yd2-- > 0) 0 0 0
721 0 ▶ push @string, ["|", $self->offset() ? 0 : $self->xdistance() + 1];
Branch: 1 branch
BranchTrueFalseTotal
$self->offset ? : 0 0 0
722 };
723
724 0 push @string, ["+" . ("-" x $self->xdistance()) . "+", 0];
725
726 0 $yd2 = $self->ybottom();
727 0 ▶ while ($yd2-- > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($yd2-- > 0) 0 0 0
728 0 ▶ push @string, ["|", $self->offset() ? $self->xdistance() + 1: 0];
Branch: 1 branch
BranchTrueFalseTotal
$self->offset ? : 0 0 0
729 };
730
731 0 ▶ push @string, [$self->end(0, "VB"), $self->offset() ? $self->xdistance() + 1 : 0];
Branch: 1 branch
BranchTrueFalseTotal
$self->offset ? : 0 0 0
732  
733 }
734 elsif ($self->ydistance() > 0 ) {
735 0 push @string, [$self->end(0, "VT"), 0];
736 0 my $yd2 = $self->ydistance();
737 0 ▶ while ($yd2-- > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($yd2-- > 0) 0 0 0
738 0 push @string, ["|", 0];
739 };
740 0 push @string, [$self->end(0, "VB"), 0];
741 }
742 0 else {croak("You're trying to draw a horizontal line with a hertical object. Use a Vertical line.\n")};
743  
744 0 ▶ $self->x_coord($self->xfrom() > $self->xto() ? $self->xto() : $self->xfrom());
Branch: 1 branch
BranchTrueFalseTotal
$self->xfrom > $self->xto ? : 0 0 0
745 0 ▶ $self->y_coord($self->yfrom() > $self->yto() ? $self->yto() : $self->yfrom());
Branch: 1 branch
BranchTrueFalseTotal
$self->yfrom > $self->yto ? : 0 0 0
746 0 return $self->rendered(\@string);
747 };
748  
749 package Text::Flowchart::Shape::Line::Corner;
750  
751 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
752  
753  
754 1 @ISA = qw(Text::Flowchart::Shape::Line);
755  
756 4 ▶sub render {
Subroutine render: called CC=12 SCAR=24.9
757 4 my $self = shift;
758
759 4 ▶ return $self->rendered() if $self->rendered();
Branch: 1 branch
BranchTrueFalseTotal
if $self->rendered 0 4 4
760
761
762 4 my @string = ();
763
764 4 ▶ if ($self->orientation() eq "BC"){
Branch: 2 branches
BranchTrueFalseTotal
if ($self->orientation eq 'BC') { } 2 2 4
elsif ($self->orientation eq 'TC') { } 2 0 2
765 2 my $yd2 = $self->ydistance();
766 2 ▶ while ($yd2-- > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($yd2-- > 0) 9 2 11
767 9 ▶ push @string, ["|", $self->offset() ? 0 : $self->xdistance() + 1];
Branch: 1 branch
BranchTrueFalseTotal
$self->offset ? : 7 2 9
768 };
769 2 push @string, [$self->end(1, "HL") . ("-" x $self->xdistance()) . $self->end(2, "HR"), 0];
770 2 ▶ unshift @string, [$self->end(0, "VT"), $self->offset() ? 0 : $self->xdistance() + 1];
Branch: 1 branch
BranchTrueFalseTotal
$self->offset ? : 1 1 2
771  
772 }
773 elsif ($self->orientation() eq "TC") {
774 2 my $yd2 = $self->ydistance();
775 2 ▶ while ($yd2-- > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($yd2-- > 0) 18 2 20
776 18 ▶ push @string, ["|", $self->offset() ? $self->xdistance() + 1: 0];
Branch: 1 branch
BranchTrueFalseTotal
$self->offset ? : 13 5 18
777 };
778 2 unshift @string, [$self->end(2, "HL") . ("-" x $self->xdistance()) . $self->end(1, "HR"), 0];
779 2 ▶ push @string, [$self->end(0, "VB"), $self->offset() ? $self->xdistance() + 1: 0];
Branch: 1 branch
BranchTrueFalseTotal
$self->offset ? : 1 1 2
780 }
781 0 else {croak("Invalid orientation for Line::Corner::render. Must be 'TC' or 'BC'.\n")}
782  
783  
784 4 ▶ $self->x_coord($self->xfrom() > $self->xto() ? $self->xto() : $self->xfrom());
Branch: 1 branch
BranchTrueFalseTotal
$self->xfrom > $self->xto ? : 1 3 4
785 4 ▶ $self->y_coord($self->yfrom() > $self->yto() ? $self->yto() : $self->yfrom());
Branch: 1 branch
BranchTrueFalseTotal
$self->yfrom > $self->yto ? : 1 3 4
786 4 return $self->rendered(\@string);
787 };
788  
789 1 1;
790  
791 __END__
↑ Summary