blib/lib/Lingua/PT/Capitalizer.pm

filter: Statementstmt 97.8% 46 / 47 Branchbran 75.0% 6 / 8 Conditioncond 66.6% 6 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 8 / 8 Podpod 50.0% 1 / 2 totaltotal 87.5% 70 / 80 CC 9 SCAR 15.5
CC
9
Cov
91%
capitalize
8.2
_pt_word_tokenizer
2.0
BEGIN
1.0
CRAP 4.7
↑ Summary
1 package Lingua::PT::Capitalizer;
2  
3 2 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use English qw[-no_match_vars];
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use base qw[ Exporter ];
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 our @EXPORT = q(capitalize);
8  
9 2 our $VERSION = '0.001'; # VERSION
10  
11 2 our %lc_always = (
12 q(a) => 1,
13 q(á) => 1,
14 q(à) => 1,
15 q(aos) => 1,
16 q(às) => 1,
17 q(d') => 1, # elisão
18 q(da) => 1,
19 q(das) => 1,
20 q(de) => 1,
21 q(di) => 1,
22 q(do) => 1,
23 q(dos) => 1,
24 q(e) => 1,
25 q(na) => 1,
26 q(nas) => 1,
27 q(no) => 1,
28 q(nos) => 1,
29 q(o) => 1,
30 q(os) => 1,
31 );
32  
33 22 ▶sub capitalize {
Subroutine capitalize: called CC=8 SCAR=21.0
Pod documented
34 22 ▶ my ( $self, $text, $preserve_caps )
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq __PACKAGE__ ? : 22 0 22
35 = ref $_[0] eq __PACKAGE__
36 ? @_
37 : ( undef, @_ );
38  
39 22 ▶ $text //= $_;
Condition33%1/3
$text //= $_
l!l&&r!l&&!r
2200
MC/DC0%0/2
$text //= $_
$text $_
Truth table33%1/3
A //= B
A= $textB= $_
ABresult
1X1
011
000
40  
41 22 ▶ return unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 22 22
42  
43 22 my @token = _pt_word_tokenizer($text);
44  
45 22 ▶ foreach ( my $i = 0; $i <= $#token; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#token) 507 22 529
46 507 foreach ( $token[$i] ) {
47 507 ▶ if ( $preserve_caps ~~ q(1)
Branch: 1 branch
BranchTrueFalseTotal
if ($preserve_caps ~~ 1 and /^\p{Lu}+(?:\N{U+27})?$/msux) 2 505 507
Condition100%3/3
$preserve_caps ~~ 1 and /^\p{Lu}+(?:\N{U+27})?$/msux
!ll&&!rl&&r
49872
MC/DC100%2/2
$preserve_caps ~~ 1 and /^\p{Lu}+(?:\N{U+27})?$/msux
$preserve_caps ~~ 1 /^\p{Lu}+(?:\N{U+27})?$/msux
Truth table100%3/3
A and B
A= $preserve_caps ~~ 1B= /^\p{Lu}+(?:\N{U+27})?$/msux
ABresult
0X0
100
111
48 2 ▶ && m{^\p{Lu}+(?:\N{APOSTROPHE})?$}msx )
Subroutine BEGIN: called CC=1 SCAR=0.0
49 {
50 2 next;
51 }
52  
53 505 my $lc = lc;
54 505 when ( $i == 0 ) { $_ = ucfirst $lc; }
55 0 when ( substr( $_, -1 ) eq q(.) ) { $_ = ucfirst $lc; }
56 483 when ( exists $lc_always{$lc} ) { $_ = $lc; }
57 446 default {
58 446 $_ = ucfirst $lc;
59 }
60 } ## end foreach ( $token[$i] )
61 } ## end foreach ( my $i = 0; $i <= ...)
62  
63 22 $text = join q(), @token;
64  
65 22 return $text;
66 } ## end sub capitalize
67  
68 22 ▶sub _pt_word_tokenizer {
Subroutine _pt_word_tokenizer: called CC=2 SCAR=6.9
69 22 my $text = shift;
70  
71 2 ▶ my $re = qr{(\p{L}+(?:\N{APOSTROPHE}|\p{L}{0,2}))}msx;
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 22 my @token = split $re, $text;
74 22 ▶ @token = grep { defined && $_ ne q() } @token;
Condition66%2/3
defined $_ && $_ ne ''
!ll&&!rl&&r
031507
MC/DC50%1/2
defined $_ && $_ ne ''
defined $_ $_ ne ''
Truth table66%2/3
A && B
A= defined $_B= $_ ne ''
ABresult
0X0
100
111
75  
76 22 return @token;
77 }
78  
79 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
80 1 my $class = shift;
81 1 my $self = {
82 capitalize => \&capitalize,
83 lc_always => \%lc_always,
84 };
85 1 return bless $self, $class;
86 }
87  
88 2 1;
89  
90 __END__
↑ Summary