RWDE/Utility.pm untested

filter: Statementstmt 0.0% 0 / 25 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 39 CC 1 SCAR 6.9
CC
1
Cov
0%
commify
2.0
get_countries_hash
2.0
get_states_hash
2.0
CRAP 2.0
1 # Macros to handle generic page functions
2  
3 package RWDE::Utility;
4  
5 use strict;
6 use warnings;
7  
8 use RWDE::Logging;
9 use vars qw($VERSION);
10 $VERSION = sprintf "%d", q$Revision: 568 $ =~ /(\d+)/;
11  
12 =pod
13  
14 =head2 commify()
15  
16 # Return a number with commas in it for easy reading.
17 # From Perl Cookbook.
18  
19 =cut
20  
21 sub commify {
22 my $text = reverse $_[0];
23 $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
24 return scalar reverse $text;
25 }
26  
27 =head2 get_countries_hash
28  
29 Create and populate a hash with input from a comma delim string
30  
31 =cut
32  
33 sub get_countries_hash {
34 my %countries_hash = (
35 us => 'United States',
36 ca => 'Canada',
37 af => 'Afghanistan',
38 al => 'Albania',
39 dz => 'Algeria',
40 as => 'American Samoa',
41 ad => 'Andorra',
42 ao => 'Angola',
43 ai => 'Anguilla',
44 aq => 'Antarctica',
45 ag => 'Antigua and Barbuda',
46 ar => 'Argentina',
47 am => 'Armenia',
48 aw => 'Aruba',
49 au => 'Australia',
50 at => 'Austria',
51 az => 'Azerbaidjan',
52 bs => 'Bahamas',
53 bh => 'Bahrain',
54 bd => 'Bangladesh',
55 bb => 'Barbados',
56 by => 'Belarus',
57 be => 'Belgium',
58 bz => 'Belize',
59 bj => 'Benin',
60 bm => 'Bermuda',
61 bt => 'Bhutan',
62 bo => 'Bolivia',
63 ba => 'Bosnia-Herzegovina',
64 bw => 'Botswana',
65 bv => 'Bouvet Island',
66 br => 'Brazil',
67 io => 'British Indian Ocean Territory',
68 bn => 'Brunei Darussalam',
69 bg => 'Bulgaria',
70 bf => 'Burkina Faso',
71 bi => 'Burundi',
72 kh => 'Cambodia',
73 cm => 'Cameroon',
74 cv => 'Cape Verde',
75 ky => 'Cayman Islands',
76 cf => 'Central African Republic',
77 td => 'Chad',
78 cl => 'Chile',
79 cn => 'China',
80 cx => 'Christmas Island',
81 cc => 'Cocos (Keeling) Islands',
82 co => 'Colombia',
83 km => 'Comoros',
84 cg => 'Congo',
85 ck => 'Cook Islands',
86 cr => 'Costa Rica',
87 hr => 'Croatia',
88 cu => 'Cuba',
89 cy => 'Cyprus',
90 cz => 'Czech Republic',
91 dk => 'Denmark',
92 dj => 'Djibouti',
93 dm => 'Dominica',
94 do => 'Dominican Republic',
95 tp => 'East Timor',
96 ec => 'Ecuador',
97 eg => 'Egypt',
98 sv => 'El Salvador',
99 gq => 'Equatorial Guinea',
100 er => 'Eritrea',
101 ee => 'Estonia',
102 et => 'Ethiopia',
103 fk => 'Falkland Islands',
104 fo => 'Faroe Islands',
105 fj => 'Fiji',
106 fi => 'Finland',
107 cs => 'Former Czechoslovakia',
108 su => 'Former USSR',
109 fr => 'France',
110 fx => 'France (European Territory)',
111 gf => 'French Guyana',
112 tf => 'French Southern Territories',
113 ga => 'Gabon',
114 gm => 'Gambia',
115 ge => 'Georgia',
116 de => 'Germany',
117 gh => 'Ghana',
118 gi => 'Gibraltar',
119 gb => 'Great Britain',
120 gr => 'Greece',
121 gl => 'Greenland',
122 gd => 'Grenada',
123 gp => 'Guadeloupe (French)',
124 gu => 'Guam (USA)',
125 gt => 'Guatemala',
126 gn => 'Guinea',
127 gw => 'Guinea Bissau',
128 gy => 'Guyana',
129 ht => 'Haiti',
130 hm => 'Heard and McDonald Islands',
131 hn => 'Honduras',
132 hk => 'Hong Kong',
133 hu => 'Hungary',
134 is => 'Iceland',
135 in => 'India',
136 id => 'Indonesia',
137 ir => 'Iran',
138 iq => 'Iraq',
139 ie => 'Ireland',
140 il => 'Israel',
141 it => 'Italy',
142 ci => 'Ivory Coast (Cote D\'Ivoire)',
143 jm => 'Jamaica',
144 jp => 'Japan',
145 jo => 'Jordan',
146 kz => 'Kazakhstan',
147 ke => 'Kenya',
148 ki => 'Kiribati',
149 kw => 'Kuwait',
150 kg => 'Kyrgyzstan',
151 la => 'Laos',
152 lv => 'Latvia',
153 lb => 'Lebanon',
154 ls => 'Lesotho',
155 lr => 'Liberia',
156 ly => 'Libya',
157 li => 'Liechtenstein',
158 lt => 'Lithuania',
159 lu => 'Luxembourg',
160 mo => 'Macau',
161 mk => 'Macedonia',
162 mg => 'Madagascar',
163 mw => 'Malawi',
164 my => 'Malaysia',
165 mv => 'Maldives',
166 ml => 'Mali',
167 mt => 'Malta',
168 mh => 'Marshall Islands',
169 mq => 'Martinique (French)',
170 mr => 'Mauritania',
171 mu => 'Mauritius',
172 yt => 'Mayotte',
173 mx => 'Mexico',
174 fm => 'Micronesia',
175 md => 'Moldavia',
176 mc => 'Monaco',
177 mn => 'Mongolia',
178 ms => 'Montserrat',
179 ma => 'Morocco',
180 mz => 'Mozambique',
181 mm => 'Myanmar',
182 na => 'Namibia',
183 nr => 'Nauru',
184 np => 'Nepal',
185 nl => 'Netherlands',
186 an => 'Netherlands Antilles',
187 nt => 'Neutral Zone',
188 nc => 'New Caledonia (French)',
189 nz => 'New Zealand',
190 ni => 'Nicaragua',
191 ne => 'Niger',
192 ng => 'Nigeria',
193 nu => 'Niue',
194 nf => 'Norfolk Island',
195 kp => 'North Korea',
196 mp => 'Northern Mariana Islands',
197 no => 'Norway',
198 om => 'Oman',
199 pk => 'Pakistan',
200 pw => 'Palau',
201 pa => 'Panama',
202 pg => 'Papua New Guinea',
203 py => 'Paraguay',
204 pe => 'Peru',
205 ph => 'Philippines',
206 pn => 'Pitcairn Island',
207 pl => 'Poland',
208 pf => 'Polynesia (French)',
209 pt => 'Portugal',
210 pr => 'Puerto Rico',
211 qa => 'Qatar',
212 re => 'Reunion (French)',
213 ro => 'Romania',
214 ru => 'Russian Federation',
215 rw => 'Rwanda',
216 gs => 'S. Georgia & S. Sandwich Isls.',
217 sh => 'Saint Helena',
218 kn => 'Saint Kitts & Nevis Anguilla',
219 lc => 'Saint Lucia',
220 pm => 'Saint Pierre and Miquelon',
221 st => 'Saint Tome and Principe',
222 vc => 'Saint Vincent & Grenadines',
223 ws => 'Samoa',
224 sm => 'San Marino',
225 sa => 'Saudi Arabia',
226 sn => 'Senegal',
227 sc => 'Seychelles',
228 sl => 'Sierra Leone',
229 sg => 'Singapore',
230 sk => 'Slovak Republic',
231 si => 'Slovenia',
232 sb => 'Solomon Islands',
233 so => 'Somalia',
234 za => 'South Africa',
235 kr => 'South Korea',
236 es => 'Spain',
237 lk => 'Sri Lanka',
238 sd => 'Sudan',
239 sr => 'Suriname',
240 sj => 'Svalbard and Jan Mayen Islands',
241 sz => 'Swaziland',
242 se => 'Sweden',
243 ch => 'Switzerland',
244 sy => 'Syria',
245 tj => 'Tadjikistan',
246 tw => 'Taiwan',
247 tz => 'Tanzania',
248 th => 'Thailand',
249 tg => 'Togo',
250 tk => 'Tokelau',
251 to => 'Tonga',
252 tt => 'Trinidad and Tobago',
253 tn => 'Tunisia',
254 tr => 'Turkey',
255 tm => 'Turkmenistan',
256 tc => 'Turks and Caicos Islands',
257 tv => 'Tuvalu',
258 ug => 'Uganda',
259 ua => 'Ukraine',
260 ae => 'United Arab Emirates',
261 uk => 'United Kingdom',
262 uy => 'Uruguay',
263 ut => 'US Territories',
264 um => 'USA Minor Outlying Islands',
265 uz => 'Uzbekistan',
266 vu => 'Vanuatu',
267 va => 'Vatican City State',
268 ve => 'Venezuela',
269 vn => 'Vietnam',
270 vg => 'Virgin Islands (British)',
271 vi => 'Virgin Islands (USA)',
272 wf => 'Wallis and Futuna Islands',
273 eh => 'Western Sahara',
274 ye => 'Yemen',
275 yu => 'Yugoslavia',
276 zr => 'Zaire',
277 zm => 'Zambia',
278 zw => 'Zimbabwe',
279 );
280 return \%countries_hash;
281 }
282  
283 =head2 get_countries_hash
284  
285 Create and populate a hash with input from a comma delim string
286  
287 =cut
288  
289 sub get_states_hash {
290  
291 my %states_hash = (
292 al => 'Alabama',
293 ak => 'Alaska',
294 az => 'Arizona',
295 ar => 'Arkansas',
296 ca => 'California',
297 co => 'Colorado',
298 ct => 'Connecticut',
299 de => 'Delaware',
300 dc => 'District of Columbia',
301 fl => 'Florida',
302 ga => 'Georgia',
303 hi => 'Hawaii',
304 id => 'Idaho',
305 il => 'Illinois',
306 in => 'Indiana',
307 ia => 'Iowa',
308 ks => 'Kansas',
309 ky => 'Kentucky',
310 la => 'Louisiana',
311 me => 'Maine',
312 md => 'Maryland',
313 ma => 'Massachusetts',
314 mi => 'Michigan',
315 mn => 'Minnesota',
316 ms => 'Mississippi',
317 mo => 'Missouri',
318 mt => 'Montana',
319 ne => 'Nebraska',
320 nv => 'Nevada',
321 nh => 'New Hampshire',
322 nj => 'New Jersey',
323 nm => 'New Mexico',
324 ny => 'New York',
325 nc => 'North Carolina',
326 nd => 'North Dakota',
327 oh => 'Ohio',
328 ok => 'Oklahoma',
329 or => 'Oregon',
330 pa => 'Pennsylvania',
331 ri => 'Rhode Island',
332 sc => 'South Carolina',
333 sd => 'South Dakota',
334 tn => 'Tennessee',
335 tx => 'Texas',
336 ut => 'Utah',
337 vt => 'Vermont',
338 va => 'Virginia',
339 wa => 'Washington',
340 wv => 'West Virginia',
341 wi => 'Wisconsin',
342 wy => 'Wyoming',
343 ab => 'Alberta',
344 bc => 'British Columbia',
345 mb => 'Manitoba',
346 nt => 'N.W. Territories',
347 nb => 'New Brunswick',
348 nl => 'Newfoundland and Labrador',
349 ns => 'Nova Scotia',
350 nu => 'Nunavut',
351 on => 'Ontario',
352 pe => 'Prince Edward Island',
353 qc => 'Quebec',
354 sk => 'Saskatchewan',
355 yt => 'Yukon',
356 );
357  
358 return \%states_hash;
359 }
360  
361 sub get_provinces_hash {
362  
363 my %provinces_hash = (
364 ab => 'Alberta',
365 bc => 'British Columbia',
366 mb => 'Manitoba',
367 nt => 'N.W. Territories',
368 nb => 'New Brunswick',
369 nl => 'Newfoundland and Labrador',
370 ns => 'Nova Scotia',
371 nu => 'Nunavut',
372 on => 'Ontario',
373 pe => 'Prince Edward Island',
374 qc => 'Quebec',
375 sk => 'Saskatchewan',
376 yt => 'Yukon',
377 );
378  
379 return \%provinces_hash;
380 }
381  
382 sub terminate ($$) {
383 my ($self, $msg, $status) = @_;
384  
385 RWDE::Logging->syslog_msg('devel', $msg);
386  
387 exit($status);
388 }
389  
390 1;