File Coverage

blib/lib/Locale/CA.pm
Criterion Covered Total %
statement 29 29 100.0
branch 4 4 100.0
condition 4 6 66.6
subroutine 6 6 100.0
pod 3 3 100.0
total 46 48 95.8


line stmt bran cond sub pod time code
1             package Locale::CA;
2              
3 4     4   524738 use warnings;
  4         108  
  4         173  
4 4     4   24 use strict;
  4         9  
  4         81  
5 4     4   2053 use Data::Section::Simple;
  4         2652  
  4         1327  
6              
7             =head1 NAME
8              
9             Locale::CA - two letter codes for province identification in Canada and vice versa
10              
11             =head1 VERSION
12              
13             Version 0.03
14              
15             =cut
16              
17             our $VERSION = '0.03';
18              
19             =head1 SYNOPSIS
20              
21             use Locale::CA;
22              
23             my $u = Locale::CA->new();
24              
25             # Returns the French names of the provinces if $LANG starts with 'fr'
26             my $province = $u->{code2province}{$code};
27             my $code = $u->{province2code}{$province};
28              
29             my @province = $u->all_province_names;
30             my @code = $u->all_province_codes;
31              
32             =head1 SUBROUTINES/METHODS
33              
34             =head2 new
35              
36             Creates a Locale::CA object.
37              
38             =cut
39              
40             sub new {
41 5     5 1 2317 my $proto = shift;
42 5   66     29 my $class = ref($proto) || $proto;
43              
44 5 100       17 return unless(defined($class));
45              
46 4         10 my $self = {};
47              
48 4         15 my $data;
49 4 100 66     26 if(defined($ENV{'LANG'}) && ($ENV{'LANG'} =~ /^fr/)) {
50 1         5 $data = Data::Section::Simple::get_data_section('provinces_fr');
51             } else {
52 3         14 $data = Data::Section::Simple::get_data_section('provinces_en');
53             }
54              
55 4         1122 my @line = split /\n/, $data;
56              
57 4         13 for (@line) {
58 48         118 my($code, $province) = split /:/;
59 48         104 $self->{code2province}{$code} = $province;
60 48         110 $self->{province2code}{$province} = $code;
61             }
62              
63 4         24 return bless $self, $class;
64             }
65              
66             =head2 all_province_codes
67              
68             Returns an array (not arrayref) of all province codes in alphabetical form.
69              
70             =cut
71              
72             sub all_province_codes {
73 1     1 1 587 my $self = shift;
74              
75 1         3 return(sort keys %{$self->{code2province}});
  1         14  
76             }
77              
78             =head2 all_province_names
79              
80             Returns an array (not arrayref) of all province names in alphabetical form
81              
82             =cut
83              
84             sub all_province_names {
85 1     1 1 3535 my $self = shift;
86              
87 1         2 return(sort keys %{$self->{province2code}});
  1         11  
88             }
89              
90             =head2 $self->{code2province}
91              
92             This is a hashref which has two-letter province names as the key and the long
93             name as the value.
94              
95             =head2 $self->{province2code}
96              
97             This is a hashref which has the long name as the key and the two-letter
98             province name as the value.
99              
100             =head1 SEE ALSO
101              
102             L
103              
104             =head1 AUTHOR
105              
106             Nigel Horne, C<< >>
107              
108             =head1 BUGS
109              
110             =over 4
111              
112             =item * The province name is returned in C format.
113              
114             =item * neither hash is strict, though they should be.
115              
116             =back
117              
118             =head1 SUPPORT
119              
120             You can find documentation for this module with the perldoc command.
121              
122             perldoc Locale::CA
123              
124             You can also look for information at:
125              
126             =over 4
127              
128             =item * RT: CPAN's request tracker
129              
130             L
131              
132             =item * CPAN Ratings
133              
134             L
135              
136             =item * Search CPAN
137              
138             L
139              
140             =back
141              
142             =head1 ACKNOWLEDGEMENTS
143              
144             Based on L - Copyright (c) 2002 - C<< $present >> Terrence Brannon.
145              
146             =head1 LICENSE AND COPYRIGHT
147              
148             Copyright 2012-2020 Nigel Horne.
149              
150             This program is released under the following licence: GPL2
151              
152             =cut
153              
154             1; # End of Locale::CA
155             __DATA__