lib/Text/FIGlet/Font.pm

filter: Statementstmt 96.4% 188 / 195 Branchbran 74.6% 100 / 134 Conditioncond 73.1% 60 / 82 MC/DCmcdc 55.3% 26 / 47 Subroutinesub 100% 13 / 13 Podpod 100% 2 / 2 totaltotal 82.2% 389 / 473 CC 111 SCAR 37.6
CC
111
Cov
85%
_load_font
66.5
figify
46.5
_load_char
16.0
CRAP 43.1
« script/minifig.pl ↑ Summary lib/Text/FIGlet/Ransom.pm »
1 package Text::FIGlet::Font;
2 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use vars qw($REwhite $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Carp qw(cluck confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Symbol; #5.005 support
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Text::Wrap;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 $VERSION = '2.19.3';
8  
9 #'import' core support functions from parent with circular dependency
10 4 foreach( qw/UTF8len UTF8ord _canonical _no _utf8_on/){
11 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 20 *$_ = *{'Text::FIGlet::'.$_};
13 }
14  
15  
16 17 ▶sub new{
Subroutine new: called CC=7 SCAR=19.9
Pod documented
17 17 shift();
18 17 my $self = {_maxLen=>0, -U=>-1, -m=>-2, @_};
19 17 ▶ $self->{-m} = -3 if defined($self->{-m}) && $self->{-m} eq '-0';
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"-m"} and $self->{"-m"} eq "-0" 1 16 17
Condition100%3/3
defined $self->{"-m"} and $self->{"-m"} eq "-0"
!ll&&!rl&&r
1151
MC/DC100%2/2
defined $self->{"-m"} and $self->{"-m"} eq "-0"
defined $self->{"-m"} $self->{"-m"} eq "-0"
Truth table100%3/3
A and B
A= defined $self->{"-m"}B= $self->{"-m"} eq "-0"
ABresult
0X0
100
111
20 17 ▶ $self->{-f} ||= $ENV{FIGFONT} || 'standard';
Condition60%3/5
$self->{"-f"} ||= $ENV{"FIGFONT"} || "standard"
l!l&&r!l&&!r
1160
$ENV{'FIGFONT'} || 'standard'
l!l
06
MC/DC0%0/2
$self->{"-f"} ||= $ENV{"FIGFONT"} || "standard"
$self->{"-f"} $ENV{'FIGFONT'}
Truth table33%1/3
A ||= B
A= $self->{"-f"}B= $ENV{'FIGFONT'}
ABresult
1X1
011
000
21 17 ▶ $self->{-d} ||= $ENV{FIGLIB} || '/usr/games/lib/figlet/';
Condition60%3/5
$self->{"-d"} ||= $ENV{"FIGLIB"} || "/usr/games/lib/figlet/"
l!l&&r!l&&!r
1160
$ENV{'FIGLIB'} || '/usr/games/lib/figlet/'
l!l
60
MC/DC0%0/2
$self->{"-d"} ||= $ENV{"FIGLIB"} || "/usr/games/lib/figlet/"
$self->{"-d"} $ENV{'FIGLIB'}
Truth table66%2/3
A ||= B
A= $self->{"-d"}B= $ENV{'FIGLIB'}
ABresult
1X1
011
000
22 17 _load_font($self);
23 17 bless($self);
24 }
25  
26 17 ▶sub _load_font{
Subroutine _load_font: called CC=49 SCAR=42.0
27 17 my $self = shift();
28 17 my $font = $self->{_font} = [];
29 17 my(@header, $header, $path, $ext);
30 17 local($_);
31  
32 #MAGIC minifig0
33 17 $self->{_file} = _canonical($self->{-d}, $self->{-f}, qr/\.[ft]lf/,
34 $^O =~ /MSWin32|DOS/i);
35 #XXX bsd_glob .[ft]lf
36 4 ▶ $self->{_file} = (glob($self->{_file}.'.?lf'))[0] unless -e $self->{_file};
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless -e $self->{"_file"} 17 0 17
37  
38 #open(FLF, $self->{_file}) || confess("$!: $self->{_file}");
39 17 $self->{_fh} = gensym; #5.005 support
40 4 ▶ eval "use IO::Uncompress::Unzip"; #XXX sniff for 'PK\003\004'instead?
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
41 17 ▶ unless( $@ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 17 17
42 17 ▶ $self->{_fh} = eval{ IO::Uncompress::Unzip->new($self->{_file}) } ||
Condition50%1/2
eval { do { 'IO::Uncompress::Unzip'->new($self->{'_file'}) } } || confess("No such file or directory: $self->{'_file'}")
l!l
170
MC/DC0%0/1
eval { do { 'IO::Uncompress::Unzip'->new($self->{'_file'}) } } || confess("No such file or directory: $self->{'_file'}")
eval { do { 'IO::Uncompress::Unzip'->new($self->{'_file'}) } }
Truth table50%1/2
A
A= eval { do { 'IO::Uncompress::Unzip'->new($self->{'_file'}) } }
Aresult
11
00
43 confess("No such file or directory: $self->{_file}");
44 }
45 else{
46 0 ▶ open($self->{_fh}, '<'.$self->{_file}) || confess("$!: $self->{_file}");
Branch: 1 branch
BranchTrueFalseTotal
open $self->{"_fh"}, '<' . $self->{"_file"} or confess(qq[$!: $self->{"_file"}]) 0 0 0
47 #$^W isn't mutable at runtime in 5.005, so we have to conditional eval
48 #to avoid "Useless use of constant in void context"
49 0 ▶ eval "binmode(\$fh, ':encoding(utf8)')" unless $] < 5.006;
Branch: 1 branch
BranchTrueFalseTotal
unless $] < "5.006" 0 0 0
50 }
51 #MAGIC minifig1
52  
53 17 my $fh = $self->{_fh}; #5.005 support
54 17 chomp($header = <$fh>); #5.005 hates readline & $self->{_fh} :-/
55 17 ▶ confess("Invalid FIGlet 2/TOIlet font") unless $header =~ /^[ft]lf2/;
Branch: 1 branch
BranchTrueFalseTotal
unless $header =~ /^[ft]lf2/ 0 17 17
56  
57 #flf2ahardblank height up_ht maxlen smushmode cmt_count rtol
58 17 @header = split(/\s+/, $header);
59 17 $header[0] =~ s/^[ft]lf2.//;
60 #$header[0] = qr/@{[sprintf "\\%o", ord($header[0])]}/;
61 17 $header[0] = quotemeta($header[0]);
62 17 $self->{_header} = \@header;
63  
64 17 ▶ if( defined($self->{-m}) && $self->{-m} eq '-2' ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"-m"} and $self->{"-m"} eq -2) 3 14 17
Condition100%3/3
defined $self->{"-m"} and $self->{"-m"} eq -2
!ll&&!rl&&r
1133
MC/DC100%2/2
defined $self->{"-m"} and $self->{"-m"} eq -2
defined $self->{"-m"} $self->{"-m"} eq -2
Truth table100%3/3
A and B
A= defined $self->{"-m"}B= $self->{"-m"} eq -2
ABresult
0X0
100
111
65 3 $self->{-m} = $header[4];
66 }
67  
68 #Discard comments
69 17 ▶ <$fh> for 1 .. $header[5] || cluck("Unexpected end of font file") && last;
Condition20%1/5
$header[5] || cluck('Unexpected end of font file') && (last)
l!l&&r!l&&!r
1700
cluck("Unexpected end of font file") and last
!ll
00
MC/DC0%0/2
$header[5] || cluck('Unexpected end of font file') && (last)
$header[5] cluck("Unexpected end of font file")
Truth table33%1/3
A || B
A= $header[5]B= cluck("Unexpected end of font file")
ABresult
1X1
011
000
70  
71 #Get ASCII characters
72 17 foreach my $i(32..126){
73 1615 ▶ &_load_char($self, $i) || last;
Branch: 1 branch
BranchTrueFalseTotal
&_load_char($self, $i) or last 1615 0 1615
74 }
75  
76 #German characters?
77 17 ▶ unless( eof($fh) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (eof $fh) 17 0 17
78 17 my %D =(91=>196, 92=>214, 93=>220, 123=>228, 124=>246, 125=>252, 126=>223);
79  
80 17 foreach my $k ( sort {$a <=> $b} keys %D ){
81 119 ▶ &_load_char($self, $D{$k}) || last;
Branch: 1 branch
BranchTrueFalseTotal
&_load_char($self, $D{$k}) or last 119 0 119
82 }
83 17 ▶ if( $self->{-D} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"-D"}) 1 16 17
84 1 $font->[$_] = $font->[$D{$_}] for keys %D;
85 #removal is necessary to prevent 2nd reference to same figchar,
86 #which would then become over-smushed; alas 5.005 can't delete arrays
87 1 $#{$font} = 126; #undef($font->[$_]) for values %D;
88 }
89 }
90  
91 #ASCII bypass
92 17 ▶ close($fh) unless $self->{-U};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"-U"} 8 9 17
93  
94 #Extended characters, with extra readline to get code
95 17 ▶ until( eof($fh) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (eof $fh) 1636 17 1653
96 1636 ▶ $_ = <$fh> || cluck("Unexpected end of font file") && last;
Condition20%1/5
readline $fh || cluck('Unexpected end of font file') && (last)
l!l&&r!l&&!r
163600
cluck("Unexpected end of font file") and last
!ll
00
MC/DC0%0/2
readline $fh || cluck('Unexpected end of font file') && (last)
readline $fh cluck("Unexpected end of font file")
Truth table33%1/3
A || B
A= readline $fhB= cluck("Unexpected end of font file")
ABresult
1X1
011
000
97
98 1636 /^\s*$Text::FIGlet::RE{no}/;
99 1636 ▶ last unless $2;
Branch: 1 branch
BranchTrueFalseTotal
unless $2 0 1636 1636
100 1636 my $val = _no($1, $2, $3, 1);
101
102 #Bypass negative chars?
103 1636 ▶ if( $val > Text::FIGlet->PRIVb && $self->{-U} == -1 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($val > 'Text::FIGlet'->PRIVb and $self->{'-U'} == -1) { } 0 1636 1636
Condition66%2/3
$val > "Text::FIGlet"->PRIVb and $self->{"-U"} == -1
!ll&&!rl&&r
163510
MC/DC0%0/2
$val > "Text::FIGlet"->PRIVb and $self->{"-U"} == -1
$val > "Text::FIGlet"->PRIVb $self->{"-U"} == -1
Truth table66%2/3
A and B
A= $val > "Text::FIGlet"->PRIVbB= $self->{"-U"} == -1
ABresult
0X0
100
111
104 0 readline($fh) for 0..$self->{_header}->[1]-1;
105 }
106 else{
107 #Clobber German chars
108 1636 $font->[$val] = '';
109 1636 ▶ &_load_char($self, $val) || last;
Branch: 1 branch
BranchTrueFalseTotal
&_load_char($self, $val) or last 1636 0 1636
110 }
111 }
112 17 close($fh);
113  
114  
115 #Fixed width
116 17 ▶ if( defined($self->{-m}) && $self->{-m} == -3 ){
Branch: 3 branches
BranchTrueFalseTotal
if (defined $self->{'-m'} and $self->{'-m'} == -3) { } 1 16 17
elsif (defined $self->{'-m'} and $self->{'-m'} == -1) { } 11 5 16
elsif (not defined $self->{'-m'} or $self->{'-m'} > -1) { } 5 0 5
Condition100%3/3
defined $self->{"-m"} and $self->{"-m"} == -3
!ll&&!rl&&r
1151
MC/DC100%2/2
defined $self->{"-m"} and $self->{"-m"} == -3
defined $self->{"-m"} $self->{"-m"} == -3
Truth table100%3/3
A and B
A= defined $self->{"-m"}B= $self->{"-m"} == -3
ABresult
0X0
100
111
117 1 my $pad;
118 1 ▶ for(my $ord=0; $ord < scalar @{$font}; $ord++){
Branch: 1 branch
BranchTrueFalseTotal
if ($ord < scalar @{$font;}) 734 1 735
119 734 ▶ next unless defined $font->[$ord];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $font->[$ord] 410 324 734
120 324 foreach my $i (-$header[1]..-1){
121 #next unless exists($font->[$ord]->[2]); #55compat
122 1944 ▶ next unless defined($font->[$ord]->[2]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $font->[$ord][2] 0 1944 1944
123  
124 # The if protects from a a 5.6(.0)? bug
125 1944 ▶ $font->[$ord]->[$i] =~ s/^\s{1,$font->[$ord]->[1]}//
Branch: 1 branch
BranchTrueFalseTotal
if $font->[$ord][1] 1944 0 1944
126 if $font->[$ord]->[1];
127  
128 1944 $pad = $self->{_maxLen} - UTF8len($font->[$ord]->[$i]);
129 # print STDERR "$pad = $self->{_maxLen} - UTF8len($font->[$ord]->[$i]);\n";
130 1944 $font->[$ord]->[$i] = " " x int($pad/2) .
131 $font->[$ord]->[$i] . " " x ($pad-int($pad/2));
132 }
133 }
134 }
135 #Full width
136 ▶ elsif( defined($self->{-m}) && $self->{-m} == -1 ){
Condition100%3/3
defined $self->{"-m"} and $self->{"-m"} == -1
!ll&&!rl&&r
1411
MC/DC100%2/2
defined $self->{"-m"} and $self->{"-m"} == -1
defined $self->{"-m"} $self->{"-m"} == -1
Truth table100%3/3
A and B
A= defined $self->{"-m"}B= $self->{"-m"} == -1
ABresult
0X0
100
111
137 11 ▶ for(my $ord=32; $ord < scalar @{$font}; $ord++){
Branch: 1 branch
BranchTrueFalseTotal
if ($ord < scalar @{$font;}) 23988 11 23999
138 23988 ▶ next unless defined $font->[$ord];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $font->[$ord] 22612 1376 23988
139 1376 foreach my $i (-$header[1]..-1){
140 6528 ▶ next unless $font->[$ord]->[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless $font->[$ord][$i] 0 6528 6528
141 # The if protects from a a 5.6(.0)? bug
142 6528 ▶ $font->[$ord]->[$i] =~ s/^\s{1,$font->[$ord]->[1]}//
Branch: 1 branch
BranchTrueFalseTotal
if $font->[$ord][1] 5281 1247 6528
143 if $font->[$ord]->[1];
144 6528 substr($font->[$ord]->[$i], 0, 0, ' 'x$font->[$ord]->[1]);
145 6528 $font->[$ord]->[$i] .= ' 'x$font->[$ord]->[2];
146 }
147 }
148 }
149 #Kern glyph boxes
150 ▶ elsif( !defined($self->{-m}) || $self->{-m} > -1 ){
Condition66%2/3
not defined $self->{"-m"} or $self->{"-m"} > -1
l!l&&r!l&&!r
140
MC/DC0%0/2
not defined $self->{"-m"} or $self->{"-m"} > -1
not defined $self->{"-m"} $self->{"-m"} > -1
Truth table66%2/3
not(A) or B
A= not defined $self->{"-m"}B= $self->{"-m"} > -1
ABresult
1X1
011
000
151 5 ▶ for(my $ord=32; $ord < scalar @{$font}; $ord++){
Branch: 1 branch
BranchTrueFalseTotal
if ($ord < scalar @{$font;}) 1047305 5 1047310
152 1047305 ▶ next unless defined $font->[$ord];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $font->[$ord] 1045684 1621 1047305
153 1621 foreach my $i (-$header[1]..-1){
154 9726 ▶ next unless $font->[$ord]->[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless $font->[$ord][$i] 0 9726 9726
155 # The if protects from a a 5.6(.0)? bug
156 9726 ▶ $font->[$ord]->[$i] =~ s/^\s{1,$font->[$ord]->[1]}//
Branch: 1 branch
BranchTrueFalseTotal
if $font->[$ord][1] 9720 6 9726
157 if $font->[$ord]->[1];
158 }
159 }
160 }
161 }
162  
163  
164 3370 ▶sub _load_char{
Subroutine _load_char: called CC=15 SCAR=27.7
165 3370 my($self, $i) = @_;
166 3370 my $font = $self->{_font};
167 3370 my($length, $wLead, $wTrail, $end, $line, $l) = 0;
168
169 3370 $wLead = $wTrail = $self->{_header}->[3];
170  
171 3370 my $fh = $self->{_fh}; #5.005 support
172
173 3370 my $REtrail;
174 3370 foreach my $j (0..$self->{_header}->[1]-1){
175 18492 ▶ $line = $_ = <$fh> ||
Condition20%1/5
readline $fh || cluck('Unexpected end of font file') && (return 0)
l!l&&r!l&&!r
1849200
cluck("Unexpected end of font file") and return 0
!ll
00
MC/DC0%0/2
readline $fh || cluck('Unexpected end of font file') && (return 0)
readline $fh cluck("Unexpected end of font file")
Truth table33%1/3
A || B
A= readline $fhB= cluck("Unexpected end of font file")
ABresult
1X1
011
000
176 cluck("Unexpected end of font file") && return 0;
177 #This is the end.... this is the end my friend
178 18492 ▶ unless( $REtrail ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($REtrail) 3370 15122 18492
179 3370 /(.)\s*$/;
180 3370 $end = $1;
181 #The negative leading anchor is for term.flf 0x40
182 3370 $REtrail = qr/(?<!^)([ $self->{_header}->[0]]+)\Q$end{1,2}\E?\s*$/;
183 }
184 18492 ▶ if( $wLead && s/^(\s+)// ){
Branch: 1 branch
BranchTrueFalseTotal
if ($wLead and s/^(\s+)//) { } 17359 1133 18492
Condition100%3/3
$wLead and s/^(\s+)//
!ll&&!rl&&r
71741617359
MC/DC100%2/2
$wLead and s/^(\s+)//
$wLead s/^(\s+)//
Truth table100%3/3
A and B
A= $wLeadB= s/^(\s+)//
ABresult
0X0
100
111
185 17359 ▶ $wLead = $l if ($l = length($1)) < $wLead;
Branch: 1 branch
BranchTrueFalseTotal
if ($l = length $1) < $wLead 7578 9781 17359
186 }
187 else{
188 1133 $wLead = 0;
189 }
190 18492 ▶ if( $wTrail && /$REtrail/ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($wTrail and /$REtrail/) { } 0 18492 18492
Condition66%2/3
$wTrail and /$REtrail/
!ll&&!rl&&r
1512233700
MC/DC0%0/2
$wTrail and /$REtrail/
$wTrail /$REtrail/
Truth table66%2/3
A and B
A= $wTrailB= /$REtrail/
ABresult
0X0
100
111
191 0 ▶ $wTrail = $l if ($l = length($1)) < $wTrail;
Branch: 1 branch
BranchTrueFalseTotal
if ($l = length $1) < $wTrail 0 0 0
192 }
193 else{
194 18492 $wTrail = 0;
195 }
196 18492 ▶ $length = $l if ($l = UTF8len($_)
Branch: 1 branch
BranchTrueFalseTotal
if ($l = UTF8len($_) - (s/(\Q$end\E+)$/$end/ && UTF8len($1))) > $length 7345 11147 18492
Condition100%3/3
s/(\Q$end\E+)$/$end/ && UTF8len($1)
!ll&&!rl&&r
28418406
MC/DC100%2/2
s/(\Q$end\E+)$/$end/ && UTF8len($1)
s/(\Q$end\E+)$/$end/ UTF8len($1)
Truth table100%3/3
A && B
A= s/(\Q$end\E+)$/$end/B= UTF8len($1)
ABresult
0X0
100
111
197 -(s/(\Q$end\E+)$/$end/&&UTF8len($1)) ) > $length;
198 18492 $font->[$i] .= $line;
199 }
200 #XXX :-/ stop trying at 125 in case of charmap in ~ or extended....
201 3370 ▶ $self->{_maxLen} = $length if $i < 126 && $self->{_maxLen} < $length;
Branch: 1 branch
BranchTrueFalseTotal
if $i < 126 and $self->{"_maxLen"} < $length 79 3291 3370
Condition100%3/3
$i < 126 and $self->{"_maxLen"} < $length
!ll&&!rl&&r
1772151979
MC/DC100%2/2
$i < 126 and $self->{"_maxLen"} < $length
$i < 126 $self->{"_maxLen"} < $length
Truth table100%3/3
A and B
A= $i < 126B= $self->{"_maxLen"} < $length
ABresult
0X0
100
111
202  
203 #Ideally this would be /o but then all figchar's must have same EOL
204 3370 $font->[$i] =~ s/\015|\Q$end\E{1,2}\s*\r?$//mg;
205 3370 $font->[$i] = [$length,#maxLen
206 $wLead, #wLead
207 $wTrail,#wTrail
208 split(/\r|\r?\n/, $font->[$i])];
209 3370 return 1;
210 }
211  
212  
213 21 ▶sub figify{
Subroutine figify: called CC=43 SCAR=38.4
Pod documented
214 21 my $self = shift();
215 21 my $font = $self->{_font};
216 21 my %opts = (-A=>'', -X=>'', -x=>'', -w=>'', -U=>0, @_);
217 21 my @buffer;
218 21 local $_;
219  
220 21 ▶ $opts{-w} ||= 80;
Condition100%2/2
$opts{"-w"} ||= 80
l!l
120
MC/DC100%1/1
$opts{"-w"} ||= 80
$opts{"-w"}
Truth table100%2/2
A
A= $opts{"-w"}
Aresult
11
00
221  
222 #Prepare the input
223 21 ▶ $opts{-X} ||= $self->{_header}->[6] ? 'R' : 'L';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_header'}[6] ? : 0 20 20
Condition66%2/3
$opts{"-X"} ||= $self->{"_header"}[6] ? "R" : "L"
l!l&&r!l&&!r
1200
MC/DC0%0/2
$opts{"-X"} ||= $self->{"_header"}[6] ? "R" : "L"
$opts{"-X"} $self->{"_header"}[6] ? "R" : "L"
Truth table66%2/3
A ||= B
A= $opts{"-X"}B= $self->{"_header"}[6] ? "R" : "L"
ABresult
1X1
011
000
224 21 ▶ if( $opts{-X} eq 'R' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"-X"} eq "R") 1 20 21
225 1 $opts{-A} = join('', reverse(split('', $opts{-A})));
226 }
227  
228 21 $opts{-A} =~ y/\t/ /;
229 21 ▶ $opts{-A} =~ s%$/%\n% unless $/ eq "\n";
Branch: 1 branch
BranchTrueFalseTotal
unless $/ eq "\n" 0 21 21
230 21 ▶ if( defined($self->{-m}) && $self->{-m} == -3 ){
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'-m'} and $self->{'-m'} == -3) { } 1 20 21
elsif ($opts{'-w'} > 0) { } 20 0 20
Condition100%3/3
defined $self->{"-m"} and $self->{"-m"} == -3
!ll&&!rl&&r
1191
MC/DC100%2/2
defined $self->{"-m"} and $self->{"-m"} == -3
defined $self->{"-m"} $self->{"-m"} == -3
Truth table100%3/3
A and B
A= defined $self->{"-m"}B= $self->{"-m"} == -3
ABresult
0X0
100
111
231 1 $Text::Wrap::columns = int($opts{-w} / $self->{_maxLen})+1;
232 1 ▶ $Text::Wrap::columns =2 if $Text::Wrap::columns < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $Text::Wrap::columns < 2 0 1 1
233 1 $opts{-A} = Text::Wrap::wrap('', '', $opts{-A});
234 1 ▶ &Encode::_utf8_off($opts{-A}) if $] >= 5.008;
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.008" 1 0 1
235 }
236 elsif( $opts{-w} > 0 ){
237 20 ▶ &Encode::_utf8_off($opts{-A}) if $] >= 5.008;
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.008" 20 0 20
238 20 $Text::Wrap::columns = $opts{-w}+1;
239 20 ▶ unless( $opts{-w} == 1 ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"-w"} == 1) 20 0 20
240 20 ($_, $opts{-A}) = ($opts{-A}, '');
241 # $opts{-A} .= "\0"x(($font->[ ord($1) ]->[0]||1)-1) . $1 while /(.)/g;
242 20 ▶ while( $opts{-U} ?
Branch: 2 branches
BranchTrueFalseTotal
if ($opts{"-U"} ? /$Text::FIGlet::RE{"UTFchar"}/g : /$Text::FIGlet::RE{"bytechar"}/g) 102 20 122
$opts{'-U'} ? : 8 114 122
243 /$Text::FIGlet::RE{UTFchar}/g :
244 /$Text::FIGlet::RE{bytechar}/g ){
245 $opts{-A} .= "\0"x(($font->[
246 102 ▶ $opts{-U} ? UTF8ord($1) : ord($1)
Branch: 1 branch
BranchTrueFalseTotal
$opts{'-U'} ? : 5 97 102
Condition100%2/2
$$font[$opts{'-U'} ? UTF8ord($1) : ord $1][0] || 1
l!l
1011
MC/DC100%1/1
$$font[$opts{'-U'} ? UTF8ord($1) : ord $1][0] || 1
$$font[$opts{'-U'} ? UTF8ord($1) : ord $1][0]
Truth table100%2/2
A
A= $$font[$opts{'-U'} ? UTF8ord($1) : ord $1][0]
Aresult
11
00
247 ]->[0]||1)-1) . $1;
248 }
249 }
250 #XXX pre 5.8 Text::Wrap is not Unicode happy?
251 20 $opts{-A} = Text::Wrap::wrap('', '', $opts{-A});
252 20 $opts{-A} =~ tr/\0//d;
253 }
254  
255 #Assemble glyphs
256 21 ▶ my $X = defined($self->{-m}) && $self->{-m} < 0 ? '' : "\000";
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'-m'} && $self->{'-m'} < 0 ? : 9 12 21
Condition100%3/3
defined $self->{"-m"} and $self->{"-m"} < 0
!ll&&!rl&&r
1119
MC/DC100%2/2
defined $self->{"-m"} and $self->{"-m"} < 0
defined $self->{"-m"} $self->{"-m"} < 0
Truth table100%3/3
A and B
A= defined $self->{"-m"}B= $self->{"-m"} < 0
ABresult
0X0
100
111
257 21 foreach( split("\n", $opts{-A}) ){
258 23 my(@lchars, @lines);
259 23 s/^\s*//o; #XXX
260 # push(@lchars, ord $1) while /(.)/g;
261 23 ▶ while( $opts{-U} ?
Branch: 2 branches
BranchTrueFalseTotal
if ($opts{"-U"} ? /$Text::FIGlet::RE{"UTFchar"}/g : /$Text::FIGlet::RE{"bytechar"}/g) 111 23 134
$opts{'-U'} ? : 8 126 134
262 /$Text::FIGlet::RE{UTFchar}/g :
263 /$Text::FIGlet::RE{bytechar}/g ){
264 111 ▶ push @lchars, ($opts{-U} ? UTF8ord($1) : ord($1));
Branch: 1 branch
BranchTrueFalseTotal
$opts{'-U'} ? : 5 106 111
265 }
266  
267 23 foreach my $i (-$self->{_header}->[1]..-1){
268 129 my $line='';
269 129 foreach my $lchar (@lchars){
270 585 ▶ if( $font->[$lchar] ){
Branch: 1 branch
BranchTrueFalseTotal
if ($font->[$lchar]) { } 585 0 585
271 585 ▶ $line .= $font->[$lchar]->[$i] . $X if $font->[$lchar]->[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $font->[$lchar][$i] 585 0 585
272 }
273 else{
274 0 $line .= $font->[32]->[$i] . $X;
275 }
276 }
277  
278 129 $line =~ s/\000$//;
279 129 push @lines, $line;
280 }
281  
282 #Kern glyphs?
283 23 ▶ if( !defined($self->{-m}) || $self->{-m} > -1 ){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"-m"} or $self->{"-m"} > -1) 13 10 23
Condition100%3/3
not defined $self->{"-m"} or $self->{"-m"} > -1
l!l&&r!l&&!r
11210
MC/DC100%2/2
not defined $self->{"-m"} or $self->{"-m"} > -1
not defined $self->{"-m"} $self->{"-m"} > -1
Truth table100%3/3
not(A) or B
A= not defined $self->{"-m"}B= $self->{"-m"} > -1
ABresult
1X1
011
000
284 13 ▶ for(my $nulls = 0; $nulls < scalar @lchars ; $nulls++){
Branch: 1 branch
BranchTrueFalseTotal
if ($nulls < scalar @lchars) 47 13 60
285 47 my $matches = 0;
286 47 my @temp;
287 47 ▶ for(my $i=0; $i<scalar @lines; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @lines) 300 47 347
288 300 $matches += ($temp[$i] = $lines[$i]) =~
289 s/^([^\000]*(?:\000[^\000]*){$nulls})(?: \000|\000(?: |\Z))/$1\000/;
290
291 #($_ = $temp[$i]) =~ s/(${stem}{$nulls})/$1@/;
292 #print "$nulls, $i) $matches == @{[scalar @lines]} #$_\n";
293 300 ▶ if( $i == scalar(@lines)-1 && $matches == scalar @lines ){
Branch: 1 branch
BranchTrueFalseTotal
if ($i == scalar(@lines) - 1 and $matches == scalar @lines) 3 297 300
Condition100%3/3
$i == scalar(@lines) - 1 and $matches == scalar @lines
!ll&&!rl&&r
250473
MC/DC100%2/2
$i == scalar(@lines) - 1 and $matches == scalar @lines
$i == scalar(@lines) - 1 $matches == scalar @lines
Truth table100%3/3
A and B
A= $i == scalar(@lines) - 1B= $matches == scalar @lines
ABresult
0X0
100
111
294 3 @lines = @temp;
295 3 $matches = 0;
296 3 $i = -1;
297 }
298 }
299 }
300 }
301  
302 23 push @buffer, @lines;
303 }
304  
305  
306 #Layout
307 21 ▶ $opts{-x} ||= $opts{-X} eq 'R' ? 'r' : 'l';
Branch: 1 branch
BranchTrueFalseTotal
$opts{'-X'} eq 'R' ? : 1 18 19
Condition66%2/3
$opts{"-x"} ||= $opts{"-X"} eq "R" ? "r" : "l"
l!l&&r!l&&!r
2190
MC/DC0%0/2
$opts{"-x"} ||= $opts{"-X"} eq "R" ? "r" : "l"
$opts{"-x"} $opts{"-X"} eq "R" ? "r" : "l"
Truth table66%2/3
A ||= B
A= $opts{"-x"}B= $opts{"-X"} eq "R" ? "r" : "l"
ABresult
1X1
011
000
308 21 foreach my $line (@buffer){
309 #Smush
310 129 ▶ if( !defined($self->{-m}) || $self->{-m} > 0 ){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'-m'} or $self->{'-m'} > 0) { } 18 111 129
Condition100%3/3
not defined $self->{"-m"} or $self->{"-m"} > 0
l!l&&r!l&&!r
612111
MC/DC100%2/2
not defined $self->{"-m"} or $self->{"-m"} > 0
not defined $self->{"-m"} $self->{"-m"} > 0
Truth table100%3/3
not(A) or B
A= not defined $self->{"-m"}B= $self->{"-m"} > 0
ABresult
1X1
011
000
311
312  
313 #Universal smush/overlap
314 18 $line =~ s/\000 //g;
315 18 $line =~ s/$Text::FIGlet::RE{UTFchar}\000//g;
316 }
317 else{
318 111 $line =~ y/\000//d;
319 }
320  
321 #Alignment
322 129 ▶ if( $opts{-x} eq 'c' ){
Branch: 2 branches
BranchTrueFalseTotal
if ($opts{'-x'} eq 'c') { } 6 123 129
elsif ($opts{'-x'} eq 'r') { } 12 111 123
323 6 $line = " "x(($opts{-w}-UTF8len($line))/2) . $line;
324 }
325 elsif( $opts{-x} eq 'r' ){
326 12 $line = " "x($opts{-w}-UTF8len($line)) . $line;
327 }
328  
329 #Replace hardblanks
330 129 $line =~ s/$self->{_header}->[0]/ /g;
331 }
332  
333  
334 21 ▶ if( $] < 5.006 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($] < 5.006) { } 0 21 21
335 0 ▶ return wantarray ? @buffer : join($/, @buffer).$/;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
336 }
337 else{
338 #Properly promote (back) to utf-8
339 0 ▶ return wantarray ? map{_utf8_on($_)} @buffer :
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 21 21
340 _utf8_on($_=join($/, @buffer).$/);
341 }
342  
343  
344 }
345 4 1;
346 __END__
« script/minifig.pl ↑ Summary lib/Text/FIGlet/Ransom.pm »