blib/lib/Unicode/Precis.pm

filter: Statementstmt 39.3% 26 / 66 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 72.7% 8 / 11 Podpod 100% 3 / 3 totaltotal 28.2% 37 / 131 CC 23 SCAR 59.5
CC
23
Cov
24%
enforce
552.0
new
2.0
compare
2.0
CRAP 385.1
↑ Summary Utils/data/utils.pl »
1 #-*- perl -*-
2 #-*- coding: utf-8 -*-
3  
4 package Unicode::Precis;
5  
6 1 ▶use 5.008007; # Use Unicode 4.1.0 or later.
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Encode qw(is_utf8 _utf8_on _utf8_off);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Unicode::BiDiRule qw(check);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Unicode::Normalize qw(normalize);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Unicode::Precis::Preparation qw(prepare FreeFormClass IdentifierClass);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 use Unicode::Precis::Utils
15 1 ▶ qw(compareExactly decomposeWidth foldCase lowerCase mapSpace);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 our $VERSION = '1.199_01';
18 1 $VERSION = eval $VERSION; # see L<perlmodstyle>
19  
20 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
21 0 my $class = shift;
22 0 my %options = @_;
23  
24 0 bless {%options} => $class;
25 }
26  
27 0 ▶sub compare {
Subroutine compare: not called CC=1 SCAR=6.9
Pod documented
28 0 my $self = shift;
29 0 my $stringA = $self->enforce(shift);
30 0 my $stringB = $self->enforce(shift);
31  
32 0 return compareExactly($stringA, $stringB);
33 }
34  
35 0 ▶sub enforce {
Subroutine enforce: not called CC=23 SCAR=63.1
Pod documented
36 0 my ($self, $string) = @_;
37  
38 0 ▶ return undef unless defined $string;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 0 0
39  
40 0 ▶ if (lc($self->{WidthMappingRule} || '') eq 'decomposition') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc($self->{"WidthMappingRule"} || "") eq "decomposition") 0 0 0
Condition0%0/2
$self->{'WidthMappingRule'} || ''
l!l
00
MC/DC0%0/1
$self->{'WidthMappingRule'} || ''
$self->{'WidthMappingRule'}
Truth table0%0/2
A
A= $self->{'WidthMappingRule'}
Aresult
11
00
41 0 decomposeWidth($string);
42 }
43 0 ▶ my $mappingrule = lc($self->{AdditionalMappingRule} || '');
Condition0%0/2
$self->{'AdditionalMappingRule'} || ''
l!l
00
MC/DC0%0/1
$self->{'AdditionalMappingRule'} || ''
$self->{'AdditionalMappingRule'}
Truth table0%0/2
A
A= $self->{'AdditionalMappingRule'}
Aresult
11
00
44 0 ▶ if ($mappingrule =~ /\bmapspace/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mappingrule =~ /\bmapspace/) 0 0 0
45 0 mapSpace($string);
46 }
47 0 ▶ if ($mappingrule =~ /\bstripspace/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mappingrule =~ /\bstripspace/) 0 0 0
48 0 $string =~ s/\A\x20+//;
49 0 $string =~ s/\x20+\z//;
50 }
51 0 ▶ if ($mappingrule =~ /\bunifyspace/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mappingrule =~ /\bunifyspace/) 0 0 0
52 0 $string =~ s/\x20\x20+/\x20/g;
53 }
54 0 ▶ if (lc($self->{CaseMappingRule} || '') eq 'fold') {
Branch: 2 branches
BranchTrueFalseTotal
if (lc($self->{'CaseMappingRule'} || '') eq 'fold') { } 0 0 0
elsif (lc($self->{'CaseMappingRule'} || '') eq 'lower') { } 0 0 0
Condition0%0/2
$self->{'CaseMappingRule'} || ''
l!l
00
MC/DC0%0/1
$self->{'CaseMappingRule'} || ''
$self->{'CaseMappingRule'}
Truth table0%0/2
A
A= $self->{'CaseMappingRule'}
Aresult
11
00
55 0 foldCase($string);
56 ▶ } elsif (lc($self->{CaseMappingRule} || '') eq 'lower') {
Condition0%0/2
$self->{'CaseMappingRule'} || ''
l!l
00
MC/DC0%0/1
$self->{'CaseMappingRule'} || ''
$self->{'CaseMappingRule'}
Truth table0%0/2
A
A= $self->{'CaseMappingRule'}
Aresult
11
00
57 0 lowerCase($string);
58 }
59 0 ▶ if ($self->{NormalizationRule}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"NormalizationRule"}) 0 0 0
60 0 ▶ if (is_utf8($string)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&is_utf8($string)) { } 0 0 0
61 $string =
62 0 eval { normalize(uc $self->{NormalizationRule}, $string) };
63 } elsif ("\t" eq "\005") { # EBCDIC
64 $string = Encode::decode('UTF-8', $string);
65 $string =
66 eval { normalize(uc $self->{NormalizationRule}, $string) };
67 $string = Encode::encode('UTF-8', $string) if defined $string;
68 } else {
69 0 _utf8_on($string);
70 $string =
71 0 eval { normalize(uc $self->{NormalizationRule}, $string) };
72 0 _utf8_off($string);
73 }
74 0 ▶ return undef unless defined $string;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 0 0
75 }
76 0 ▶ if (lc($self->{DirectionalityRule} || '') eq 'bidi') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc($self->{"DirectionalityRule"} || "") eq "bidi") 0 0 0
Condition0%0/2
$self->{'DirectionalityRule'} || ''
l!l
00
MC/DC0%0/1
$self->{'DirectionalityRule'} || ''
$self->{'DirectionalityRule'}
Truth table0%0/2
A
A= $self->{'DirectionalityRule'}
Aresult
11
00
77 0 ▶ return undef unless defined check($string, 0);
Branch: 1 branch
BranchTrueFalseTotal
unless defined &check($string, 0) 0 0 0
78 }
79 my $stringclass = {
80 freeformclass => FreeFormClass,
81 identifierclass => IdentifierClass,
82 0 ▶ }->{lc($self->{StringClass} || '')}
Condition0%0/4
{'freeformclass', FreeFormClass(), 'identifierclass', IdentifierClass()}->{lc($self->{'StringClass'} || '')} || 0
l!l
00
$self->{'StringClass'} || ''
l!l
00
MC/DC0%0/1
{'freeformclass', FreeFormClass(), 'identifierclass', IdentifierClass()}->{lc($self->{'StringClass'} || '')} || 0
{'freeformclass', FreeFormClass(), 'identifierclass', IdentifierClass()}->{lc($self->{'StringClass'} || '')}
MC/DC0%0/1
$self->{'StringClass'} || ''
$self->{'StringClass'}
Truth table0%0/2
A
A= {'freeformclass', FreeFormClass(), 'identifierclass', IdentifierClass()}->{lc($self->{'StringClass'} || '')}
Aresult
11
00
Truth table0%0/2
A
A= $self->{'StringClass'}
Aresult
11
00
83 || 0;
84 return undef
85 0 ▶ unless defined prepare($string, $stringclass);
Branch: 1 branch
BranchTrueFalseTotal
unless defined prepare($string, $stringclass) 0 0 0
86 0 ▶ if (ref $self->{OtherRule} eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"OtherRule"} eq "CODE") 0 0 0
87 return undef
88 0 ▶ unless defined($string = $self->{OtherRule}->($string));
Branch: 1 branch
BranchTrueFalseTotal
unless defined($string = $self->{"OtherRule"}->($string)) 0 0 0
89 }
90  
91 0 eval { $_[1] = $string };
92 0 $string;
93 }
94  
95 1 1;
96 __END__
↑ Summary Utils/data/utils.pl »