blib/lib/Acme/AwesomeQuotes.pm

filter: Statementstmt 100% 51 / 51 Branchbran 100% 16 / 16 Conditioncond 66.6% 4 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 10 / 10 Podpod 50.0% 1 / 2 totaltotal 94.3% 83 / 88 CC 11 SCAR 14.1
CC
11
Cov
97%
checkstring
7.0
GetAwesome
5.0
BEGIN
1.0
CRAP 4.1
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use 5.008_003;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Acme::AwesomeQuotes;
7 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 $Acme::AwesomeQuotes::VERSION = '0.02';
9 }
10  
11 1 binmode STDIN, ':utf8';
12 1 binmode STDOUT, ':utf8';
13 1 binmode STDERR, ':utf8';
14  
15 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 our @ISA = qw(Exporter);
17 1 our @EXPORT_OK = qw(GetAwesome);
18 1 our @EXPORT = qw(GetAwesome);
19  
20 1 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Unicode::Normalize qw(NFC NFD);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 # ABSTRACT: Make your text awesome!
24  
25  
26 1 my %chartypes = (
27 'all' => qr/[\x{030C}\x{0300}\x{0301}]/,
28 'notgrave' => qr/[^\P{NonspacingMark}\x{0300}]/,
29 'notacute' => qr/[^\P{NonspacingMark}\x{0301}]/,
30 'notcaron' => qr/[^\P{NonspacingMark}\x{030C}]/,
31 'puncsep' => qr/[\p{Separator}\p{Punctuation}]/,
32 );
33  
34  
35 20 ▶sub GetAwesome {
Subroutine GetAwesome: called CC=5 SCAR=16.1
Pod documented
36 20 (my $string = NFD($_[0])) =~ s/(?:^${chartypes{puncsep}}+|${chartypes{puncsep}}+$)//g;
37  
38 20 ▶ eval {checkstring($string)} or croak $@;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { checkstring($string) } } or croak($@) 15 5 20
39  
40 # For individual characters, use a caron instead of terminal acute/grave accents:
41 15 ▶ if ($string =~ /^\p{Letter}\p{NonspacingMark}*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /^\p{Letter}\p{NonspacingMark}*$/) { } 3 12 15
42 # Prep string – remove extant carons/accents:
43 3 $string =~ s/^(\p{Letter}${chartypes{notcaron}}*)${chartypes{all}}+(${chartypes{notcaron}}*)$/$1$2/;
44  
45 # Make string awesome!
46 3 $string = NFC($string);
47 3 $string =~ s/^(.*)$/`$1\x{030C}´/;
48 }
49 else {
50 # If there are initial acute/terminal grave accents, use a caron instead:
51 12 ▶ my $initialaccent = ($string =~ s/^(\p{Letter}\p{NonspacingMark}*)[\x{0301}\x{030C}]+/${1}/g)
Branch: 1 branch
BranchTrueFalseTotal
$string =~ s/^(\p{Letter}\p{NonspacingMark}*)[\x{0301}\x{030C}]+/$1/g ? : 4 8 12
52 ? "\x{030C}" : "\x{0300}";
53 12 ▶ my $finalaccent = ($string =~ s/(\p{Letter}\p{NonspacingMark}*)[\x{0300}\x{030C}]+(\p{NonspacingMark}*)$/${1}${2}/g)
Branch: 1 branch
BranchTrueFalseTotal
$string =~ s/(\p{Letter}\p{NonspacingMark}*)[\x{0300}\x{030C}]+(\p{NonspacingMark}*)$/$1$2/g ? : 3 9 12
54 ? "\x{030C}" : "\x{0301}";
55  
56 # Prep string – remove extant terminal acute/grave accents:
57 12 $string =~ s/^(\p{Letter}${chartypes{notgrave}}*)\x{0300}/$1/;
58 12 $string =~ s/(\p{Letter}${chartypes{notacute}}*)\x{0301}(${chartypes{notacute}}*)$/$1$2/;
59  
60 # Make string awesome!
61 12 $string = NFC($string);
62 12 $string =~ s/^(\p{Letter}\p{ModifierLetter}*)/`${1}${initialaccent}/;
63 12 $string =~ s/(\p{Letter}\p{ModifierLetter}*)$/${1}${finalaccent}´/;
64 }
65  
66 15 return(NFC($string));
67 }
68  
69  
70 20 ▶sub checkstring {
Subroutine checkstring: called CC=7 SCAR=19.5
Pod undocumented
71 20 my $string = $_[0];
72 20 ▶ if ($string eq '') {
Branch: 4 branches
BranchTrueFalseTotal
if ($string eq '') { } 1 19 20
elsif ($string =~ /^`\p{Letter}$chartypes{'notgrave'}*\x{0300}/ and $string =~ /\p{Letter}$chartypes{'notacute'}*\x{0301}$chartypes{'notacute'}*\264$/ or $string =~ /^`\p{Letter}$chartypes{'notcaron'}*\x{030C}$chartypes{'notcaron'}*\264$/) { } 1 18 19
elsif (not $string =~ /^\p{Letter}/) { } 2 16 18
elsif (not $string =~ /\p{Letter}\p{NonspacingMark}*$/) { } 1 15 16
73 1 die "String is empty!\n";
74 }
75 ▶ elsif ((($string =~ /^`\p{Letter}${chartypes{notgrave}}*\x{0300}/) &&
Condition66%4/6
$string =~ /^`\p{Letter}$chartypes{"notgrave"}*\x{0300}/ and $string =~ /\p{Letter}$chartypes{"notacute"}*\x{0301}$chartypes{"notacute"}*\264$/ or $string =~ /^`\p{Letter}$chartypes{"notcaron"}*\x{030C}$chartypes{"notcaron"}*\264$/
l!l&&r!l&&!r
1018
$string =~ /^`\p{Letter}$chartypes{"notgrave"}*\x{0300}/ and $string =~ /\p{Letter}$chartypes{"notacute"}*\x{0301}$chartypes{"notacute"}*\264$/
!ll&&!rl&&r
1801
MC/DC33%1/3
$string =~ /^`\p{Letter}$chartypes{"notgrave"}*\x{0300}/ and $string =~ /\p{Letter}$chartypes{"notacute"}*\x{0301}$chartypes{"notacute"}*\264$/ or $string =~ /^`\p{Letter}$chartypes{"notcaron"}*\x{030C}$chartypes{"notcaron"}*\264$/
$string =~ /^`\p{Letter}$chartypes{"notgrave"}*\x{0300}/ $string =~ /\p{Letter}$chartypes{"notacute"}*\x{0301}$chartypes{"notacute"}*\264$/ $string =~ /^`\p{Letter}$chartypes{"notcaron"}*\x{030C}$chartypes{"notcaron"}*\264$/
Truth table40%2/5
A and B or C
A= $string =~ /^`\p{Letter}$chartypes{"notgrave"}*\x{0300}/B= $string =~ /\p{Letter}$chartypes{"notacute"}*\x{0301}$chartypes{"notacute"}*\264$/C= $string =~ /^`\p{Letter}$chartypes{"notcaron"}*\x{030C}$chartypes{"notcaron"}*\264$/
ABCresult
11X1
0X11
1011
0X00
1000
76 ($string =~ /\p{Letter}${chartypes{notacute}}*\x{0301}${chartypes{notacute}}*´$/)) ||
77 ($string =~ /^`\p{Letter}${chartypes{notcaron}}*\x{030C}${chartypes{notcaron}}*´$/)) {
78 1 die "String '$string' is *already* awesome!\n";
79 }
80 elsif ($string !~ /^\p{Letter}/) {
81 2 die "String '$string' begins with a non-letter character.\n";
82 }
83 elsif ($string !~ /\p{Letter}\p{NonspacingMark}*$/) {
84 1 die "String '$string' terminates with a non-letter character.\n";
85 }
86 else {
87 15 1;
88 }
89 }
90  
91  
92 1 1; # This is a module, so it must return true.
93  
94 __END__
↑ Summary