File Coverage

blib/lib/String/ProperCase/Surname.pm
Criterion Covered Total %
statement 16 16 100.0
branch 4 4 100.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 25 25 100.0


line stmt bran cond sub pod time code
1             package String::ProperCase::Surname;
2 3     3   507892 use strict;
  3         16  
  3         111  
3 3     3   13 use warnings;
  3         4  
  3         194  
4 3     3   15 use base qw{Exporter};
  3         18  
  3         2362  
5              
6             our $VERSION = '0.04';
7             our @EXPORT = qw(ProperCase);
8             our @EXPORT_OK = qw(ProperCase);
9              
10             =head1 NAME
11              
12             String::ProperCase::Surname - Converts Surnames to Proper Case
13              
14             =head1 SYNOPSIS
15              
16             use String::ProperCase::Surname;
17             print ProperCase($surname);
18              
19             =head1 DESCRIPTION
20              
21             The package String::ProperCase::Surname is an L that exports exactly one function called ProperCase. The ProperCase function is for use on Surnames which handles cases like O'Neal, O'Brien, McLean, etc.
22              
23             After researching the proper case issues there are three different use cases with a wide variety of loose rules. This algorithm is customized for surnames. Other uses such as "TitleCase" and "MenuCase" have different algorithms. The main difference is that in surnames the letter following an apostrophe is always uppercase (e.g. "O'Brien") in title case and menu case the letter is always lowercase (e.g. "They're").
24              
25             =head1 USAGE
26              
27             use String::ProperCase::Surname;
28             print ProperCase($surname);
29              
30             OR
31              
32             require String::ProperCase::Surname;
33             print String::ProperCase::Surname::ProperCase($surname);
34              
35             OR
36              
37             use String::ProperCase::Surname qw{};
38             *pc=\&String::ProperCase::Surname::ProperCase;
39             print pc($surname);
40              
41             =head1 VARIABLES
42              
43             =cut
44              
45             #List of default mixed case surnames (excluding Mc surnames).
46              
47             our @surname=qw{
48              
49             AbuArab
50              
51             DaSilva DeAnda DeAngelo DeBardelaben DeBary DeBaugh DeBeck DeBergh DeBerry
52             DeBlanc DeBoe DeBoer DeBonis DeBord DeBose DeBostock DeBourge DeBroux DeBruhl
53             DeBruler DeButts DeCaires DeCamp DeCarolis DeCastro DeCay DeConinck DeCook
54             DeCoppens DeCorte DeCost DeCosta DeCoste DeCoster DeCouto DeFamio DeFazio DeFee
55             DeFluri DeFord DeForest DeFraia DeFrange DeFree DeFrees DeGarmo DeGear DeGeare
56             DeGnath DeGraff DeGraffenreid DeGrange DeGraw DeGrenier DeGroft DeGuaincour
57             DeHaan DeHaas DeHart DeHass DeHate DeHaven DeHeer DeHerrera DeJarnette DeJean
58             DeLaet DelAmarre DeLancey DeLara DeLarm DelAshmutt DeLaughter DeLay DeLespine
59             DelGado DelGaudio DeLong DeLony DeLorenzo DeLozier DelPrincipe DelRosso DeLuca
60             DeLude DeLuke DeMaio DeMarchi DeMarco DeMarcus DeMarmein DeMars DeMartinis DeMay
61             DeMello DeMonge DeMont DeMontigny DeMoss DeNunzio DeNure DePalma DePaola
62             DePasquale DePauli DePerno DePhillips DePoty DePriest DeRatt DeRemer DeRosa
63             DeRosier DeRossett DeSaegher DeSalme DeShane DeShano DeSilva DeSimencourt
64             DeSimone DesJardins DeSoto DeSpain DesPlanques DeSplinter DeStefano DesVoigne
65             DeTurck DeVall DeVane DeVaughan DeVaughn DeVaul DeVault DeVenney DeVilbiss
66             DeVille DeVillier DeVinney DeVito DeVore DeVorss DeVoto DeVries DeWald DeWall
67             DeWalt DeWilfond DeWinne DeWitt DeWolf DeYarmett DeYoung DiBenedetto DiCicco
68             DiClaudio DiClemento DiFrisco DiGiacomo DiGiglio DiGraziano DiGregorio
69             DiLiberto DiMarco DiMarzo DiPaolo DiPietrantonio DiStefano DoBoto DonSang
70             DuBois DuBose DuBourg DuCoin DuPre DuPuy
71              
72             DeVaux DeVoir
73              
74             EnEarl
75              
76             FitzJames FitzRandolf
77              
78             LaBarge LaBarr LaBelle LaBonte LaBounty LaBrue LaCaille LaCasse LaChapelle
79             LaClair LaCombe LaCount LaCour LaCourse LaCroix LaFarge LaFeuillande LaFlamme
80             LaFollette LaFontaine LaForge LaForme LaForte LaFosse LaFountain LaFoy LaFrance
81             LaFuze LaGaisse LaGreca LaGuardia LaHaise LaLande LaLanne LaLiberte LaLonde
82             LaLone LaMaitre LaMatry LaMay LaMere LaMont LaMotte LaMunyon LaPierre LaPlante
83             LaPointe LaPorte LaPrade LaPrairie LaQue LaRoche LaRochelle LaRose LaRue
84             LaSalle LaSance LaSart LaTray LaVallee LaVeau LaVenia LaVigna LeBerth LeBlond
85             LeBoeuf LeBreton LeCaire LeCapitain LeCesne LeClair LeClaire LeClerc LeCompte
86             LeConte LeCour LeCrone LeDow LeDuc LeFevre LeFlore LeFors LeFridge LeGrand
87             LeGras LeGrove LeJeune LeMaster LeMesurier LeMieux LeMoine LePage LeQuire LeRoy
88             LeStage LeSuer LeVally LeVert LiConti LoManto LoMastro LoRusso
89              
90             MacAlister MacAlpine MacArthur MacAulay MacAulay MacAuliffe MacBain MacBean
91             MacBeth MacCallum MacClaine MacCauley MacClelland MacCleery MacCloud MacCord
92             MacCray MacDonald MacDonnell MacDougall MacDuff MacDuffie MacFadyen MacFarland
93             MacFarlane MacFie MacGillivray MacGregor MacInnes MacIntyre MacKay MacKenzie
94             MacKinley MacKinnon Mackintosh MacKinney MacLaine MacLachlan MacLaren
95             MacLaughlin MacLea MacLean MacLellan MacLeod MacMahon MacMillan MacNab
96             MacNaught MacNeal MacNeil MacNeill MacNicol MacPhee MacPherson MacQuarrie
97             MacRae MacShane MacSporran MacTavish MacThomas MacWhirter MacAtee MacCarthy
98             MacCarty MacCleverty MacCredie MacCue MacCurrach MacEachern MacGilvray MacIvor
99             MacKechnie MacLennan MacLucas MacManus MacMartin MacNeary MacNevin MacQueen
100             MacWilliams MaDej MaGaw
101              
102             SanFillipo SanGalli SantaLucia
103              
104             TePas
105              
106             VanArsdale VanBuren VanCamp VanCleave VanDalsem VanderLey VanderNeut VanderTol
107             VanderWegen VanDerWeyer VanderWilligen VanDevelde VandeWege VanDolah VanDusen
108             VanDyke VanHee VanHoak VanHook VanHoose VanHouten VanHouwe VanHoven VanKampen
109             VanKleck VanKleeck VanKuiken VanLanduyt VanLeer VanLiere VanLuven VanMeter
110             VanOlinda VanOrmer VanPelt VanSchaick VanSciver VanScoy VanScoyk VanSickle
111             VanTassel VanTuyl VanValkenburg VanVolkenburgh VanWinkle VanWysenberghe
112             VanZandt VenDerWeyer VonCannon
113              
114             };
115              
116             =head2 %surname
117              
118             You can add or delete custom mixed case surnames to/from this hash.
119              
120             Delete
121              
122             delete($String::ProperCase::Surname::surname{lc($_)}) foreach qw{MacDonald MacLeod};
123              
124             Add
125              
126             $String::ProperCase::Surname::surname{lc($_)}=$_ foreach qw{DaVis};
127              
128             Note: All keys are lower case and values are mixed case.
129              
130             =cut
131              
132             our %surname=map {lc($_) => $_} @surname;
133              
134             =head1 FUNCTIONS
135              
136             =head2 ProperCase
137              
138             Function returns the correct case given a surname.
139              
140             print ProperCase($surname);
141              
142             Note: All "Mc" last names are assumed to be mixed case.
143              
144             =cut
145              
146             sub ProperCase {
147 29     29 1 469794 my $string="";
148 29         166 foreach my $part (split /\b/, shift()) {
149 59 100       183 if ($part=~m/^(Mc)([a-z].*)/i) { #Mc
    100          
150 5         16 $string.=ucfirst(lc($1)) . ucfirst(lc($2));
151             } elsif ($surname{lc($part)}) { #MacCleery, DeVaux, etc.
152 12         27 $string.=$surname{lc($part)};
153             } else {
154 42         74 $string.=ucfirst(lc($part));
155             }
156             }
157 29         112 return $string;
158             }
159              
160             =head1 LIMITATIONS
161              
162             Surname default mixed case hash will never be perfect for every implementation.
163              
164             =head1 AUTHOR
165              
166             Michael R. Davis
167              
168             =head1 COPYRIGHT
169              
170             This program is free software licensed under the...
171              
172             The BSD License
173              
174             The full text of the license can be found in the LICENSE file included with this module.
175              
176             =head1 SEE ALSO
177              
178             L, L
179              
180             =cut
181              
182             1;