blib/lib/Text/Soundex.pm

filter: Statementstmt 45.2% 24 / 53 Branchbran 7.1% 1 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 44.4% 4 / 9 Podpod 0.0% 0 / 4 totaltotal 36.2% 29 / 80 CC 7 SCAR 19.2
CC
7
Cov
37%
soundex_noxs
12.0
soundex_nara
12.0
soundex_unicode
6.0
CRAP 6.8
↑ Summary Soundex.xs »
1 # -*- perl -*-
2  
3 # (c) Copyright 1998-2007 by Mark Mielke
4 #
5 # Freedom to use these sources for whatever you want, as long as credit
6 # is given where credit is due, is hereby granted. You may make modifications
7 # where you see fit but leave this copyright somewhere visible. As well, try
8 # to initial any changes you make so that if I like the changes I can
9 # incorporate them into later versions.
10 #
11 # - Mark Mielke <mark@mielke.cc>
12 #
13  
14 package Text::Soundex;
15 1 require 5.006;
16  
17 1 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use XSLoader ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use if $] > 5.016, 'deprecate';
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 our $VERSION = '3.05';
25 1 our @EXPORT_OK = qw(soundex soundex_unicode soundex_nara soundex_nara_unicode
26 $soundex_nocode);
27 1 our @EXPORT = qw(soundex soundex_nara $soundex_nocode);
28 1 our @ISA = qw(Exporter);
29  
30 1 our $nocode;
31  
32 # Previous releases of Text::Soundex made $nocode available as $soundex_nocode.
33 # For now, this part of the interface is exported and maintained.
34 # In the feature, $soundex_nocode will be deprecated.
35 1 *Text::Soundex::soundex_nocode = \$nocode;
36  
37 sub soundex_noxs
38 0 ▶{
Subroutine soundex_noxs: not called CC=3 SCAR=24.8
Pod undocumented
39 # Original Soundex algorithm
40  
41 my @results = map {
42 0 my $code = uc($_);
43 0 $code =~ tr/AaEeHhIiOoUuWwYyBbFfPpVvCcGgJjKkQqSsXxZzDdTtLlMmNnRr//cd;
44  
45 0 ▶ if (length($code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $code) { } 0 0 0
46 0 my $firstchar = substr($code, 0, 1);
47 0 $code =~ tr[AaEeHhIiOoUuWwYyBbFfPpVvCcGgJjKkQqSsXxZzDdTtLlMmNnRr]
48 [0000000000000000111111112222222222222222333344555566]s;
49 0 ($code = substr($code, 1)) =~ tr/0//d;
50 0 substr($firstchar . $code . '000', 0, 4);
51 } else {
52 0 $nocode;
53 }
54 } @_;
55  
56 0 ▶ wantarray ? @results : $results[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
57 }
58  
59 sub soundex_nara
60 0 ▶{
Subroutine soundex_nara: not called CC=3 SCAR=24.8
Pod undocumented
61 # US census (NARA) algorithm.
62  
63 my @results = map {
64 0 my $code = uc($_);
65 0 $code =~ tr/AaEeHhIiOoUuWwYyBbFfPpVvCcGgJjKkQqSsXxZzDdTtLlMmNnRr//cd;
66  
67 0 ▶ if (length($code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $code) { } 0 0 0
68 0 my $firstchar = substr($code, 0, 1);
69 0 $code =~ tr[AaEeHhIiOoUuWwYyBbFfPpVvCcGgJjKkQqSsXxZzDdTtLlMmNnRr]
70 [0000990000009900111111112222222222222222333344555566]s;
71 0 $code =~ s/(.)9\1/$1/gs;
72 0 ($code = substr($code, 1)) =~ tr/09//d;
73 0 substr($firstchar . $code . '000', 0, 4);
74 } else {
75 0 $nocode
76 }
77 } @_;
78  
79 0 ▶ wantarray ? @results : $results[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
80 }
81  
82 sub soundex_unicode
83 0 ▶{
Subroutine soundex_unicode: not called CC=2 SCAR=17.9
Pod undocumented
84 0 ▶ require Text::Unidecode unless defined &Text::Unidecode::unidecode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined &Text::Unidecode::unidecode 0 0 0
85 0 soundex(Text::Unidecode::unidecode(@_));
86 }
87  
88 sub soundex_nara_unicode
89 0 ▶{
Subroutine soundex_nara_unicode: not called CC=2 SCAR=17.9
Pod undocumented
90 0 ▶ require Text::Unidecode unless defined &Text::Unidecode::unidecode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined &Text::Unidecode::unidecode 0 0 0
91 0 soundex_nara(Text::Unidecode::unidecode(@_));
92 }
93  
94 1 eval { XSLoader::load(__PACKAGE__, $VERSION) };
95  
96 1 ▶if (defined(&soundex_xs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &Text::Soundex::soundex_xs) { } 1 0 1
97 1 *soundex = \&soundex_xs;
98 } else {
99 0 *soundex = \&soundex_noxs;
100 0 ▶ *soundex_xs = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
101 0 require Carp;
102 0 Carp::croak("XS implementation of Text::Soundex::soundex_xs() ".
103 "could not be loaded");
104 0 };
105 }
106  
107 1 1;
108  
109 __END__
↑ Summary Soundex.xs »