| 1 | # Copyright 2010, 2011, 2012 Kevin Ryde | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # This file is part of Image-Base-Other. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Image-Base-Other is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # it under the terms of the GNU General Public License as published by the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Free Software Foundation; either version 3, or (at your option) any later | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # Image-Base-Other is distributed in the hope that it will be useful, but | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # for more details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # You should have received a copy of the GNU General Public License along | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # with Image-Base-Other. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | package Image::Base::Text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # maybe one day 5.005 for 4-arg substr() replacing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # 5.6 for easier clean open() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | ▶ | use Text::Tabs (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | ▶ | use List::Util 'min','max'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | ▶ | use vars '$VERSION', '@ISA'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | $VERSION = 9; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | ▶ | use Image::Base 1.12; # version 1.12 for ellipse() $fill | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 4 | @ISA = ('Image::Base'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # uncomment this to run the ### lines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | #use Smart::Comments; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | ▶ | use constant default_colour_to_character => { 'black' => ' ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 'clear' => ' ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | '#000000' => ' ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | '#000000000000' => ' ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | other => '*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 53 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 53 | my ($class, %param) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 53 | ▶ | if (ref $class) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # clone by copying fields and data array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $self = bless { %$class }, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $self->{'-rows_array'} = [ @{$class->{'-rows_array'}} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 53 | my $self = bless | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | { -rows_array => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | -width => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | -colour_to_character => $class->default_colour_to_character, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 53 | ▶ | if (defined (my $filename = delete $param{'-file'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | $self->load($filename); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 53 | $self->set (%param); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 53 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1996 | ▶ | sub _get { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1996 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # ### Image-Base-Text _get(): $key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1996 | ▶ | if ($key eq '-height') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 936 | return scalar @{$self->{'-rows_array'}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1060 | return $self->SUPER::_get ($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 81 | ▶ | sub set { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 81 | my ($self, %param) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ### set(): \%param | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 81 | ▶ | if (defined (my $width = delete $param{'-width'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 56 | foreach my $row (@{$self->{'-rows_array'}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 60 | ▶ | if (length($row) < $width) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 20 | $row .= ' ' x ($width - length($row)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 40 | substr($row,$width) = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # ready for -height to use | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 56 | $self->{'-width'} = $width; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 81 | ▶ | if (defined (my $height = delete $param{'-height'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 41 | my $rows_array = $self->{'-rows_array'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 41 | ▶ | if (@$rows_array >= $height) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ### rows_array shorten | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 4 | splice @$rows_array, $height; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ### rows_array extend by: ($height - scalar(@$rows_array)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 37 | my $row = ' ' x $self->{'-width'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 37 | push @$rows_array, ($row) x ($height - scalar(@$rows_array)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 81 | %$self = (%$self, %param); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | ▶ | sub load { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 3 | my ($self, $filename) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ### Image-Base-Text load() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $filename = $self->get('-file'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 3 | $self->set('-file', $filename); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | ### $filename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 3 | ▶ | open my $fh, '<', $filename or croak "Cannot open $filename: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | $self->load_fh ($fh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 3 | ▶ | close $fh or croak "Error closing $filename: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # these undocumented yet ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 3 | ▶ | sub load_fh { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_fh: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | my ($self, $fh) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | ### Image-Base-Text load_fh(): $fh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 3 | $self->load_lines (map {chomp; $_} <$fh>); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 12 | ▶ | sub load_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_string: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 12 | my ($self, $str) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | ### Image-Base-Text load_string(): $str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # split | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 12 | my @lines = split /\n/, $str, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 12 | ▶ | if (@lines && $lines[-1] eq '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@lines and $lines[-1] eq ""
MC/DC100%2/2
@lines and $lines[-1] eq ""
@lines
$lines[-1] eq ""
Truth table100%3/3
A and B
A= @linesB= $lines[-1] eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # drop the empty element after the last newline, but keep a non-empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # final element from chars without a final newline | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 9 | pop @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 12 | $self->load_lines (@lines); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 16 | ▶ | sub load_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_lines: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 16 | my ($self, @rows_array) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | ### load_lines: @rows_array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 16 | my $width = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 16 | foreach my $row (@rows_array) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 29 | $row = Text::Tabs::expand ($row); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 29 | ▶ | if ($width < length($row)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 16 | $width = length($row); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 16 | $self->{'-rows_array'} = \@rows_array; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 16 | $self->set (-width => $width); # pad out shorter lines | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | ▶ | sub save { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save: called CC=5 SCAR=17.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | my ($self, $filename) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | ### Image-Base-Text save(): @_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | ▶ | if (@_ == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | $self->set('-file', $filename); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | $filename = $self->get('-file'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | ### $filename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 2 | my $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 2 | ▶ | (open $fh, '>', $filename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
open $fh, ">", $filename and $self->save_fh($fh) and close $fh
open $fh, ">", $filename and $self->save_fh($fh)
MC/DC0%0/3
open $fh, ">", $filename and $self->save_fh($fh) and close $fh
open $fh, ">", $filename
$self->save_fh($fh)
close $fh
Truth table25%1/4
A and B and C
A= open $fh, ">", $filenameB= $self->save_fh($fh)C= close $fh
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | and $self->save_fh($fh) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | and close $fh) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | or croak "Error writing $filename: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # these undocumented yet ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 2 | ▶ | sub save_fh { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save_fh: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | my ($self, $fh) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 2 | my $rows_array = $self->{'-rows_array'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 2 | local $, = "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 2 | ▶ | return print $fh @$rows_array,(@$rows_array ? '' : ()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 17 | ▶ | sub save_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save_string: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 17 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 17 | my $rows_array = $self->{'-rows_array'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 17 | ▶ | return join ("\n", @$rows_array, (@$rows_array ? '' : ())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # drawing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 5320 | ▶ | sub xy { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xy: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 5320 | my ($self, $x, $y, $colour) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | ### Image-Base-Text xy(): @_[1 .. $#_] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # clip to width,height | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | return if ($x < 0 || $x >= $self->{'-width'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 5320 | ▶ | || $y < 0 || $y >= @{$self->{'-rows_array'}}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$x < 0 or $x >= $self->{"-width"} or $y < 0 or $y >= @{$self->{"-rows_array"};}
$x < 0 or $x >= $self->{"-width"} or $y < 0
$x < 0 or $x >= $self->{"-width"}
MC/DC100%4/4
$x < 0 or $x >= $self->{"-width"} or $y < 0 or $y >= @{$self->{"-rows_array"};}
$x < 0
$x >= $self->{"-width"}
$y < 0
$y >= @{$self->{"-rows_array"};}
Truth table100%5/5
A or B or C or D
A= $x < 0B= $x >= $self->{"-width"}C= $y < 0D= $y >= @{$self->{"-rows_array"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 5295 | my $rows_array = $self->{'-rows_array'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 5295 | ▶ | if (@_ == 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 5023 | return $self->character_to_colour (substr ($rows_array->[$y], $x, 1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 272 | substr ($rows_array->[$y], $x, 1) = $self->colour_to_character($colour); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 79 | ▶ | sub line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
line: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 79 | my ($self, $x1,$y1, $x2,$y2, $colour) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 79 | ▶ | if ($y1 == $y2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | ### horizontal line by substr() block store ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 48 | my $rows_array = $self->{'-rows_array'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 48 | ▶ | return if $y1 < 0 || $y1 > $#$rows_array; # entirely outside | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$y1 < 0 or $y1 > $rows_array->$#*
MC/DC100%2/2
$y1 < 0 or $y1 > $rows_array->$#*
$y1 < 0
$y1 > $rows_array->$#*
Truth table100%3/3
A or B
A= $y1 < 0B= $y1 > $rows_array->$#*
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 44 | ▶ | if ($x1 > $x2) { ($x1,$x2) = ($x2,$x1) } # x1 smaller | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 44 | my $xmax = $self->{'-width'}-1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 44 | ▶ | return if $x2 < 0 || $x1 > $xmax; # entirely outside | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$x2 < 0 or $x1 > $xmax
MC/DC100%2/2
$x2 < 0 or $x1 > $xmax
$x2 < 0
$x1 > $xmax
Truth table100%3/3
A or B
A= $x2 < 0B= $x1 > $xmax
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 42 | $x1 = max($x1,0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 42 | $x2 = min($x2,$xmax); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 42 | my $x_width = $x2-$x1+1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 42 | substr($rows_array->[$y1], $x1, $x_width, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | $self->colour_to_character($colour) x $x_width); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 31 | shift->SUPER::line(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # rectangle() can do a substr() block store on each filled row (either all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # if $fill, or the top and bottom if not). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 369 | ▶ | sub rectangle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rectangle: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 369 | my ($self, $x1,$y1, $x2,$y2, $colour, $fill) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | ### Image-Base-Text xy(): @_[1,$#_] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 369 | my $rows_array = $self->{'-rows_array'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 369 | ▶ | unless ($x2 >= 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$x2 >= 0 and $y2 >= 0 and $x1 < $self->{"-width"} and $y1 <= $rows_array->$#*
$x2 >= 0 and $y2 >= 0 and $x1 < $self->{"-width"}
$x2 >= 0 and $y2 >= 0
MC/DC25%1/4
$x2 >= 0 and $y2 >= 0 and $x1 < $self->{"-width"} and $y1 <= $rows_array->$#*
$x2 >= 0
$y2 >= 0
$x1 < $self->{"-width"}
$y1 <= $rows_array->$#*
Truth table40%2/5
A and B and C and D
A= $x2 >= 0B= $y2 >= 0C= $x1 < $self->{"-width"}D= $y1 <= $rows_array->$#*
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | && $y2 >= 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | && $x1 < $self->{'-width'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | && $y1 <= $#$rows_array) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | ### entirely outside 0,0,width,height ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 363 | my $x1_clip = max($x1,0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 363 | my $x2_clip = min($x2,$self->{'-width'}-1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 363 | my $char = $self->colour_to_character($colour); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 363 | my $x_width = $x2_clip - $x1_clip + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 363 | my $repl = $char x $x_width; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 363 | ▶ | if ($fill) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 266 | foreach my $y (max($y1,0) .. min($y2,$#$rows_array)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 2129 | substr ($rows_array->[$y], $x1_clip, $x_width) = $repl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | ### top, if in range ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 97 | ▶ | if ($y1 >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 91 | substr ($rows_array->[$y1], $x1_clip, $x_width) = $repl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 97 | $y1++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 97 | ▶ | if ($y2 >= $y1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 53 | ▶ | if ($y2 <= $#$rows_array) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | ### bottom in range and not same as top ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 49 | substr ($rows_array->[$y2], $x1_clip, $x_width) = $repl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | ### sides, if any ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 53 | $y2--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 53 | ▶ | if ($y2 >= $y1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 32 | my $y1_clip = max($y1,0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 32 | my $y2_clip = min($y2,$#$rows_array); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 32 | ▶ | if ($x1 == $x1_clip) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 27 | foreach my $y ($y1_clip .. $y2_clip) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 126 | substr ($rows_array->[$y], $x1, 1) = $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 32 | ▶ | if ($x2 == $x2_clip) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 28 | foreach my $y ($y1_clip .. $y2_clip) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 129 | substr ($rows_array->[$y], $x2, 1) = $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 681 | ▶ | sub colour_to_character { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
colour_to_character: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 681 | my ($self, $colour) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | ### colour_to_character(): $colour | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 681 | ▶ | if (defined (my $char = $self->{'-colour_to_character'}->{$colour})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 182 | return $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 499 | ▶ | if (length($colour) == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 69 | return $colour; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 430 | ▶ | if (defined (my $char = $self->{'-colour_to_character'}->{'other'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 430 | return $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | croak "Unknown colour: $colour"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 5023 | ▶ | sub character_to_colour { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
character_to_colour: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 5023 | my ($self, $char) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 5023 | ▶ | if (length ($char) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 5023 | ▶ | if (defined (my $colour = $self->{'-character_to_colour'}->{$char})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 4988 | return $colour; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 35 | return $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||