lib/Text/UnicodeStyle.pm

filter: Statementstmt 100% 40 / 40 Branchbran 92.8% 13 / 14 Conditioncond 86.6% 26 / 30 MC/DCmcdc 68.7% 11 / 16 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 90.9% 100 / 110 CC 18 SCAR 22.9
CC
18
Cov
94%
stylize
15.0
_table
4.1
BEGIN
1.0
CRAP 9.9
↑ Summary /usr/local/bin/perldoc »
1 package Text::UnicodeStyle;
2 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 our $VERSION = '0.01';
8 8 our @EXPORT_OK = qw( styles stylize );
9 8 our %EXPORT_TAGS = ( all => \@EXPORT_OK );
10  
11 8 my %STYLE_MODS = (
12 bold => 'Text::UnicodeStyle::Bold',
13 bold_fraktur => 'Text::UnicodeStyle::BoldFraktur',
14 bold_italic => 'Text::UnicodeStyle::BoldItalic',
15 bold_script => 'Text::UnicodeStyle::BoldScript',
16 circled => 'Text::UnicodeStyle::Circled',
17 doublestruck => 'Text::UnicodeStyle::Doublestruck',
18 fraktur => 'Text::UnicodeStyle::Fraktur',
19 fullwidth => 'Text::UnicodeStyle::Fullwidth',
20 italic => 'Text::UnicodeStyle::Italic',
21 monospace => 'Text::UnicodeStyle::Monospace',
22 negative_circled => 'Text::UnicodeStyle::NegativeCircled',
23 negative_squared => 'Text::UnicodeStyle::NegativeSquared',
24 parenthesized => 'Text::UnicodeStyle::Parenthesized',
25 sans_serif => 'Text::UnicodeStyle::SansSerif',
26 sans_serif_bold => 'Text::UnicodeStyle::SansSerifBold',
27 sans_serif_bold_italic => 'Text::UnicodeStyle::SansSerifBoldItalic',
28 sans_serif_italic => 'Text::UnicodeStyle::SansSerifItalic',
29 script => 'Text::UnicodeStyle::Script',
30 squared => 'Text::UnicodeStyle::Squared',
31 );
32  
33 8 my %TABLES;
34  
35 175 ▶sub _module_for {
Subroutine _module_for: called CC=1 SCAR=0.0
36 175 my ($style) = @_;
37 175 return $STYLE_MODS{$style};
38 }
39  
40 175 ▶sub _table {
Subroutine _table: called CC=4 SCAR=14.0
41 175 my ($style) = @_;
42 175 ▶ my $mod = _module_for($style)
Branch: 1 branch
BranchTrueFalseTotal
my $mod = _module_for($style) or die "Unknown style '${style}'. Available: " . join(", ", styles()) . "\n" 174 1 175
43 or die "Unknown style '$style'. Available: " . join(', ', styles()) . "\n";
44 174 ▶ $TABLES{$style} //= do {
Condition66%2/3
$TABLES{$style} //= do { eval "require $mod" or die $@; $mod->table }
l!l&&r!l&&!r
153210
MC/DC0%0/2
$TABLES{$style} //= do { eval "require $mod" or die $@; $mod->table }
$TABLES{$style} do { eval "require $mod" or die $@; $mod->table }
Truth table66%2/3
A //= B
A= $TABLES{$style}B= do { eval "require $mod" or die $@; $mod->table }
ABresult
1X1
011
000
45 21 ▶ eval "require $mod" or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $mod" or die $@ 21 0 21
46 21 $mod->table;
47 };
48 174 return $TABLES{$style};
49 }
50  
51 11 ▶sub styles {
Subroutine styles: called CC=1 SCAR=0.0
Pod documented
52 11 return sort keys %STYLE_MODS;
53 }
54  
55 175 ▶sub stylize {
Subroutine stylize: called CC=15 SCAR=27.1
Pod documented
56 175 my ($s, $style) = @_;
57 175 my $t = _table($style);
58  
59 174 my $out = $s;
60 174 $out =~ s{
61 ([!-~])
62 }{
63 1313 my $c = $1;
64 1313 ▶ if ($t->{fix} && exists $t->{fix}{$c}) {
Branch: 5 branches
BranchTrueFalseTotal
if ($t->{'fix'} and exists $t->{'fix'}{$c}) { } 55 1258 1313
elsif ($c ge 'A' and $c le 'Z' and $t->{'upper'}) { } 521 737 1258
elsif ($c ge 'a' and $c le 'z' and $t->{'lower'}) { } 496 241 737
elsif ($c ge '0' and $c le '9' and $t->{'digit'}) { } 31 210 241
elsif ($t->{'punct'} and $c ge '!' and $c le '~') { } 7 203 210
Condition100%3/3
$t->{"fix"} and exists $t->{"fix"}{$c}
!ll&&!rl&&r
87438455
MC/DC100%2/2
$t->{"fix"} and exists $t->{"fix"}{$c}
$t->{"fix"} exists $t->{"fix"}{$c}
Truth table100%3/3
A and B
A= $t->{"fix"}B= exists $t->{"fix"}{$c}
ABresult
0X0
100
111
65 55 chr $t->{fix}{$c};
66 }
67 ▶ elsif ($c ge 'A' && $c le 'Z' && $t->{upper}) {
Condition83%5/6
$c ge "A" and $c le "Z" and $t->{"upper"}
!ll&&!rl&&r
7370521
$c ge "A" and $c le "Z"
!ll&&!rl&&r
129608521
MC/DC66%2/3
$c ge "A" and $c le "Z" and $t->{"upper"}
$c ge "A" $c le "Z" $t->{"upper"}
Truth table75%3/4
A and B and C
A= $c ge "A"B= $c le "Z"C= $t->{"upper"}
ABCresult
0XX0
10X0
1100
1111
68 521 chr($t->{upper} + ord($c) - ord('A'));
69 }
70 ▶ elsif ($c ge 'a' && $c le 'z' && $t->{lower}) {
Condition100%6/6
$c ge "a" and $c le "z" and $t->{"lower"}
!ll&&!rl&&r
15190496
$c ge "a" and $c le "z"
!ll&&!rl&&r
1501586
MC/DC100%3/3
$c ge "a" and $c le "z" and $t->{"lower"}
$c ge "a" $c le "z" $t->{"lower"}
Truth table100%4/4
A and B and C
A= $c ge "a"B= $c le "z"C= $t->{"lower"}
ABCresult
0XX0
10X0
1100
1111
71 496 chr($t->{lower} + ord($c) - ord('a'));
72 }
73 ▶ elsif ($c ge '0' && $c le '9' && $t->{digit}) {
Condition100%6/6
$c ge 0 and $c le 9 and $t->{"digit"}
!ll&&!rl&&r
1882231
$c ge 0 and $c le 9
!ll&&!rl&&r
5713153
MC/DC100%3/3
$c ge 0 and $c le 9 and $t->{"digit"}
$c ge 0 $c le 9 $t->{"digit"}
Truth table100%4/4
A and B and C
A= $c ge 0B= $c le 9C= $t->{"digit"}
ABCresult
0XX0
10X0
1100
1111
74 31 chr($t->{digit} + ord($c) - ord('0'));
75 }
76 ▶ elsif ($t->{punct} && $c ge '!' && $c le '~') {
Condition66%4/6
$t->{"punct"} and $c ge "!" and $c le "~"
!ll&&!rl&&r
20307
$t->{"punct"} and $c ge "!"
!ll&&!rl&&r
20307
MC/DC33%1/3
$t->{"punct"} and $c ge "!" and $c le "~"
$t->{"punct"} $c ge "!" $c le "~"
Truth table50%2/4
A and B and C
A= $t->{"punct"}B= $c ge "!"C= $c le "~"
ABCresult
0XX0
10X0
1100
1111
77 7 chr(ord($c) + $t->{punct});
78 }
79 else {
80 203 $c;
81 }
82 }gex;
83  
84 174 return $out;
85 }
86  
87 8 1;
88  
89 __END__
↑ Summary /usr/local/bin/perldoc »