lib/Text/FIGlet.pm

filter: Statementstmt 79.1% 76 / 96 Branchbran 50.0% 23 / 46 Conditioncond 42.3% 11 / 26 MC/DCmcdc 6.2% 1 / 16 Subroutinesub 94.7% 18 / 19 Podpod 0.0% 0 / 4 totaltotal 62.3% 129 / 207 CC 33 SCAR 23.8
CC
33
Cov
65%
UTF8chr
42.0
_canonical
18.4
UTF8ord
9.2
CRAP 10.8
« lib/Text/FIGlet/Illuminated.pm ↑ Summary script/charmap.pl »
1 package Text::FIGlet;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use vars qw'$VERSION %RE';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 $VERSION = '2.19.4'; #Actual code version: 2.19.1
5  
6 #~50us penalty w/ 2 constant calls for 5.005
7 4 ▶use constant PRIVb => 0xF0000; #Map neg chars into Unicode's private area
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use constant PRIVe => 0xFFFFD; #0-31 are also available but unused.
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Carp qw(carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use File::Basename 'fileparse';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Text::FIGlet::Control;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Text::FIGlet::Font;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Text::FIGlet::Ransom;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 4 ▶if( $] >= 5.008 ){
Branch: 2 branches
BranchTrueFalseTotal
if ($] >= 5.008) { } 4 0 4
elsif ($] >= 5.006 and $] <= 5.007) { } 0 0 0
18 4 require Encode; #Run-time rather than compile-time, without an eval
19 4 import Encode;
20 21 ▶ eval 'sub _utf8_on {Encode::decode("utf8",shift)}';
Subroutine _utf8_on: called CC=1 SCAR=0.0
21 # sub _utf8_off {Encode::_utf8_off(@_)}';
22 } #Next block from Encode::compat, but broadened from 5.6.1 to 5.6
23 ▶elsif ($] >= 5.006 and $] <= 5.007) {
Condition0%0/3
$] >= "5.006" and $] <= "5.007"
!ll&&!rl&&r
000
MC/DC0%0/2
$] >= "5.006" and $] <= "5.007"
$] >= "5.006" $] <= "5.007"
Truth table0%0/3
A and B
A= $] >= "5.006"B= $] <= "5.007"
ABresult
0X0
100
111
24 0 eval 'sub _utf8_on { $_[0] = pack("U*", unpack("U0U*", $_[0])) }
25 sub Encode::_utf8_off { $_[0] = pack("C*", unpack("C*", $_[0])) }';
26 }
27 else{
28 0 local $^W = 0;
29 0 eval "sub _utf8_on{}; sub Encode::_utf8_off{};";
30 }
31  
32  
33 4 my $thByte = '[\x80-\xBF]';
34 4 %RE = (
35 #XXX Should perhaps put 1 byte UTF-8 last as . instead, to catch ANSI
36 #XXX Alas that catches many other unfortunate things...
37 UTFchar => qr/([\x20-\x7F]|[\xC2-\xDF]$thByte|[\xE0-\xEF]$thByte{2}|[\xF0-\xF4]$thByte{3})/,
38 bytechar=> qr/(.)/s,
39 no => qr/(-?)((0?)(?:x[\da-fA-F]+|\d+))/,
40 );
41  
42  
43 4 ▶sub import{
Subroutine import: called CC=4 SCAR=14.6
44 4 ▶ @_ = qw/UTF8chr UTF8ord UTF8len/ if grep(/:Encode/, @_);
Branch: 1 branch
BranchTrueFalseTotal
if grep /:Encode/, @_ 0 4 4
45  
46 4 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 0 4
47 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
48 0 *{scalar(caller).'::'.$_} = $_ for grep/UTF8chr|UTF8ord|UTF8len/, @_;
49 }
50 }
51  
52  
53 15 ▶sub new {
Subroutine new: called CC=7 SCAR=19.5
Pod undocumented
54 15 local $_;
55 15 my $proto = shift;
56 15 my %opt = @_;
57 15 my($class, @isect, %count);
58 15 my %class = (-f => 'Font', -C => 'Control');
59  
60  
61 15 ▶ if( ref($opt{-f}) =~ /ARRAY|HASH/ ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref($opt{'-f'}) =~ /ARRAY|HASH/) { } 4 11 15
62 4 $class = 'Text::FIGlet::Ransom';
63 }
64 else{
65 11 $count{$_}++ for (keys %opt, keys %class);
66 11 ▶ $count{$_} == 2 && push(@isect, $_) for keys %count;
Branch: 1 branch
BranchTrueFalseTotal
$count{$_} == 2 and push @isect, $_ 5 29 34
67 11 ▶ croak("Cannot new both -C and -f") if scalar @isect > 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @isect > 1 0 11 11
68 11 ▶ $class = 'Text::FIGlet::' . $class{shift(@isect) || '-f'};
Condition100%2/2
shift @isect || '-f'
l!l
56
MC/DC100%1/1
shift @isect || '-f'
shift @isect
Truth table100%2/2
A
A= shift @isect
Aresult
11
00
69 }
70 15 $class->new(@_);
71 }
72  
73  
74 0 ▶sub UTF8chr{
Subroutine UTF8chr: not called CC=6 SCAR=37.4
Pod undocumented
75 0 ▶ my $ord = shift || $_;
Condition0%0/3
shift() || $_
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $_
shift() $_
Truth table0%0/3
A || B
A= shift()B= $_
ABresult
1X1
011
000
76 0 my @n;
77  
78 #x00-x7f #1 byte
79 0 ▶ if( $ord < 0x80 ){
Branch: 4 branches
BranchTrueFalseTotal
if ($ord < 128) { } 0 0 0
elsif ($ord < 2048) { } 0 0 0
elsif ($ord < 65536) { } 0 0 0
elsif ($ord < 131072) { } 0 0 0
80 0 @n = $ord; }
81 #x80-x7ff #2 bytes
82 elsif( $ord < 0x800 ){
83 0 @n = (0xc0|$ord>>6, 0x80|$ord&0x3F ); }
84 #x800-xffff #3 bytes
85 elsif( $ord < 0x10000 ){
86 0 @n = (0xe0|$ord>>12,
87 0x80|($ord>>6)&0x3F,
88 0x80|$ord&0x3F ); }
89 #x10000-x10ffff #4 bytes
90 elsif( $ord<0x20000 ){
91 0 @n = (0xf0|$ord>>18,
92 0x80|($ord>>12)&0x3F,
93 0x80|($ord>>6)&0x3F,
94 0x80|$ord&0x3F); }
95 else{
96 0 warn "Out of range for UTF-8: $ord"; }
97  
98 0 return pack "C*", @n;
99 }
100  
101  
102 38944 ▶sub UTF8len{
Subroutine UTF8len: called CC=2 SCAR=7.1
Pod undocumented
103 38944 ▶ my $str = shift || $_;
Condition66%2/3
shift() || $_
l!l&&r!l&&!r
3893680
MC/DC0%0/2
shift() || $_
shift() $_
Truth table66%2/3
A || B
A= shift()B= $_
ABresult
1X1
011
000
104 38944 my $count = () = $str =~ m/$Text::FIGlet::RE{UTFchar}/g;
105 }
106  
107  
108 10 ▶sub UTF8ord{
Subroutine UTF8ord: called CC=8 SCAR=22.2
Pod undocumented
109 10 ▶ my $str = shift || $_;
Condition33%1/3
shift() || $_
l!l&&r!l&&!r
1000
MC/DC0%0/2
shift() || $_
shift() $_
Truth table33%1/3
A || B
A= shift()B= $_
ABresult
1X1
011
000
110 10 my $len = length ($str);
111  
112 10 ▶ return ord($str) if $len == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $len == 1 0 10 10
113 #This is a FIGlet specific error value
114 10 ▶ return 128 if $len > 4 || $len == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $len > 4 or $len == 0 0 10 10
Condition33%1/3
$len > 4 or $len == 0
l!l&&r!l&&!r
0010
MC/DC0%0/2
$len > 4 or $len == 0
$len > 4 $len == 0
Truth table33%1/3
A or B
A= $len > 4B= $len == 0
ABresult
1X1
011
000
115  
116 10 my @n = unpack "C*", $str;
117 10 $str = (($n[-2] & 0x3F) << 6) + ($n[-1] & 0x3F);
118 10 ▶ $str += (($n[-3] & 0x1F) << 12) if $len ==3;
Branch: 1 branch
BranchTrueFalseTotal
if $len == 3 0 10 10
119 10 ▶ $str += (($n[-3] & 0x3F) << 12) if $len ==4;
Branch: 1 branch
BranchTrueFalseTotal
if $len == 4 2 8 10
120 10 ▶ $str += (($n[-4] & 0x0F) << 18) if $len == 4;
Branch: 1 branch
BranchTrueFalseTotal
if $len == 4 2 8 10
121 10 return $str;
122 }
123  
124  
125 1652 ▶sub _no{
Subroutine _no: called CC=7 SCAR=19.9
126 1652 my($one, $two, $thr, $over) = @_;
127  
128 1652 ▶ my $val = ($one ? -1 : 1) * ( $thr eq 0 ? oct($two) : $two);
Branch: 2 branches
BranchTrueFalseTotal
$one ? : 6 1646 1652
$thr eq 0 ? : 966 686 1652
129  
130 #+2 is to map -2 to offset zero (-1 is forbidden, modern systems have no -0)
131 1652 ▶ $val += PRIVe + 2 if $one;
Branch: 1 branch
BranchTrueFalseTotal
if $one 6 1646 1652
132 1652 ▶ if( $one && $over && $val < PRIVb ){
Branch: 1 branch
BranchTrueFalseTotal
if ($one and $over and $val < 983040) 0 1652 1652
Condition83%5/6
$one and $over and $val < 983040
!ll&&!rl&&r
165110
$one and $over
!ll&&!rl&&r
164651
MC/DC0%0/3
$one and $over and $val < 983040
$one $over $val < 983040
Truth table75%3/4
A and B and C
A= $oneB= $overC= $val < 983040
ABCresult
0XX0
10X0
1100
1111
133 0 carp("Extended character out of bounds");
134 0 return 0;
135 }
136  
137 1652 $val;
138 }
139  
140  
141 19 ▶sub _canonical{
Subroutine _canonical: called CC=5 SCAR=29.1
142 19 my($defdir, $usrfile, $extre, $backslash) = @_;
143 19 ▶ return -e $usrfile ? $usrfile :
Branch: 1 branch
BranchTrueFalseTotal
-e $usrfile ? : 0 19 19
144 File::Spec->catfile($defdir, $usrfile);
145  
146 #Dragons be here, was for pseudo-Windows tests/old Perls?
147  
148 #Split things up
149 0 my($file, $path, $ext) = fileparse($usrfile, $extre);
150  
151 0 ▶ $path =~ y/\\/\// if $backslash;
Branch: 1 branch
BranchTrueFalseTotal
if $backslash 0 0 0
152  
153 #Handle paths relative to current directory
154 0 my $curdir = File::Spec->catfile(File::Spec->curdir, "");
155 0 ▶ $path = $defdir if $path eq $curdir && index($usrfile, $curdir) < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $path eq $curdir and index($usrfile, $curdir) == -1 0 0 0
Condition0%0/3
$path eq $curdir and index($usrfile, $curdir) == -1
!ll&&!rl&&r
000
MC/DC0%0/2
$path eq $curdir and index($usrfile, $curdir) == -1
$path eq $curdir index($usrfile, $curdir) == -1
Truth table0%0/3
A and B
A= $path eq $curdirB= index($usrfile, $curdir) == -1
ABresult
0X0
100
111
156  
157  
158 #return canonicaled path
159 0 return File::Spec->catfile($path, $file.$ext);
160 }
161  
162 4 local $_="Act kind of random and practice less beauty sense --ginoh";
163  
164 __END__
« lib/Text/FIGlet/Illuminated.pm ↑ Summary script/charmap.pl »