File Coverage

blib/lib/Locale/AU.pm
Criterion Covered Total %
statement 26 26 100.0
branch 2 2 100.0
condition 2 3 66.6
subroutine 6 6 100.0
pod 3 3 100.0
total 39 40 97.5


line stmt bran cond sub pod time code
1             package Locale::AU;
2              
3 6     6   1332720 use warnings;
  6         30  
  6         539  
4 6     6   33 use strict;
  6         11  
  6         162  
5 6     6   2981 use Data::Section::Simple;
  6         4699  
  6         1933  
6              
7             =head1 NAME
8              
9             Locale::AU - abbreviations for territory and state identification in Australia and vice versa
10              
11             =head1 VERSION
12              
13             Version 0.02
14              
15             =cut
16              
17             our $VERSION = '0.02';
18              
19             =head1 SYNOPSIS
20              
21             use Locale::AU;
22              
23             my $u = Locale::AU->new();
24              
25             my $state = $u->{code2state}{$code};
26             my $code = $u->{state2code}{$state};
27              
28             my @state = $u->all_state_names;
29             my @code = $u->all_state_codes;
30              
31              
32             =head1 SUBROUTINES/METHODS
33              
34             =head2 new
35              
36             Creates a Locale::AU object.
37              
38             Can be called both as a class method (Locale::AU->new()) and as an object method ($object->new()).
39              
40             =cut
41              
42             sub new {
43 5     5 1 816581 my $proto = shift;
44 5   66     34 my $class = ref($proto) || $proto;
45              
46             # If the class is undefined, fallback to the current package name
47 5 100       17 if(!defined($class)) {
48             # Use Locale::AU->new(), not Locale::AU::new()
49             # Carp::carp(__PACKAGE__, ' use ->new() not ::new() to instantiate');
50             # return;
51              
52             # FIXME: this only works when no arguments are given
53 1         3 $class = __PACKAGE__;
54             }
55              
56             # Parse the data into bidirectional mappings
57 5         10 my $self = {};
58              
59 5         43 my @line = split /\n/, Data::Section::Simple::get_data_section('states');
60              
61 5         1462 for (@line) {
62 40         96 my($code, $state) = split /:/;
63             # Map codes to states
64 40         92 $self->{code2state}{$code} = $state;
65             # Map states to codes
66 40         117 $self->{state2code}{$state} = $code;
67             }
68              
69 5         47 return bless $self, $class;
70             }
71              
72             =head2 all_state_codes
73              
74             Returns an array (not arrayref) of all state codes in alphabetical form.
75              
76             =cut
77              
78             sub all_state_codes {
79 2     2 1 1009 my $self = shift;
80              
81 2         3 return(sort keys %{$self->{code2state}});
  2         19  
82             }
83              
84             =head2 all_state_names
85              
86             Returns an array (not arrayref) of all state names in alphabetical form
87              
88             =cut
89              
90             sub all_state_names {
91 2     2 1 2488 my $self = shift;
92              
93 2         5 return(sort keys %{$self->{state2code}});
  2         16  
94             }
95              
96             =head2 $self->{code2state}
97              
98             This is a hashref which has state abbreviations as the key and the long
99             name as the value.
100              
101             =head2 $self->{state2code}
102              
103             This is a hashref which has the long name as the key and the abbreviated
104             state name as the value.
105              
106             =head1 SEE ALSO
107              
108             L
109              
110             =head1 AUTHOR
111              
112             Nigel Horne, C<< >>
113              
114             =head1 BUGS
115              
116             =over 4
117              
118             =item * The state name is returned in C format.
119              
120             =item * neither hash is strict, though they should be.
121              
122             =item * Jarvis Bay Territory is not handled
123              
124             =back
125              
126             =head1 SUPPORT
127              
128             You can find documentation for this module with the perldoc command.
129              
130             perldoc Locale::AU
131              
132             You can also look for information at:
133              
134             =over 4
135              
136             =item * MetaCPAN
137              
138             L
139              
140             =item * RT: CPAN's request tracker
141              
142             L
143              
144             =item * CPAN Testers' Matrix
145              
146             L
147              
148             =item * CPAN Testers Dependencies
149              
150             L
151              
152             =back
153              
154             =head1 ACKNOWLEDGEMENTS
155              
156             Based on L - Copyright (c) 2002 - C<< $present >> Terrence Brannon.
157              
158             =head1 LICENSE AND COPYRIGHT
159              
160             Copyright 2020-2025 Nigel Horne.
161              
162             This program is released under the following licence: GPL2
163              
164             =cut
165              
166             1; # End of Locale::AU
167             __DATA__