| 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
| |||||||||||||||||||||||||||||||||||||||||||||
| 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
}
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
}
| |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 21 | ▶ | eval "require $mod" or die $@; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$t->{"fix"} and exists $t->{"fix"}{$c}
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}
| |||||||||||||||||||||||||||||||||||||||||||||
| 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"}
$c ge "A" and $c le "Z"
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"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 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"}
$c ge "a" and $c le "z"
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"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 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"}
$c ge 0 and $c le 9
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"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 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 "~"
$t->{"punct"} and $c ge "!"
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 "~"
| |||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||