line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::TigerLine::Abbreviations; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
24928
|
$Geo::TigerLine::Abbreviations::VERSION = '0.04'; |
4
|
|
|
|
|
|
|
} |
5
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
7
|
1
|
|
|
1
|
|
328
|
use Cache::FileCache; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use LWP::Simple; |
9
|
|
|
|
|
|
|
use vars qw(%Dict); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
init(); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub init { |
14
|
|
|
|
|
|
|
for my $abbr ( @{_get_dictionary()} ) { |
15
|
|
|
|
|
|
|
push @{$Dict{$abbr->{$_}}}, $abbr for keys %$abbr; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
for ( keys %Dict ) { |
18
|
|
|
|
|
|
|
@{$Dict{$_}} = unique( @{$Dict{$_}} ); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub unique { |
23
|
|
|
|
|
|
|
my %seen; |
24
|
|
|
|
|
|
|
$seen{$_} = $_ for @_; |
25
|
|
|
|
|
|
|
return values %seen; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _get_dictionary { |
29
|
|
|
|
|
|
|
my $cache = Cache::FileCache->new |
30
|
|
|
|
|
|
|
( { namespace => 'TigerLINE', |
31
|
|
|
|
|
|
|
default_expires_in => $Cache::Cache::EXPIRES_NEVER } ); |
32
|
|
|
|
|
|
|
my $dict = $cache->get( 'Dictionary' ); |
33
|
|
|
|
|
|
|
if ( not $dict ) { |
34
|
|
|
|
|
|
|
$dict = _fetch_dictionary(); |
35
|
|
|
|
|
|
|
$cache->set( 'Dictionary', $dict ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
return $dict; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _fetch_dictionary { |
41
|
|
|
|
|
|
|
no warnings 'uninitialized'; |
42
|
|
|
|
|
|
|
return |
43
|
|
|
|
|
|
|
[ ( map { local $_ = $_; |
44
|
|
|
|
|
|
|
s/\t/ /g; |
45
|
|
|
|
|
|
|
s/^\s+//; |
46
|
|
|
|
|
|
|
s/\s+$//; |
47
|
|
|
|
|
|
|
my %h; |
48
|
|
|
|
|
|
|
@h{qw(feature_type |
49
|
|
|
|
|
|
|
standard_abbreviation |
50
|
|
|
|
|
|
|
short_abbreviation |
51
|
|
|
|
|
|
|
translation)} = split /\s{2,}/; |
52
|
|
|
|
|
|
|
delete @h{ grep $h{$_} !~ /\w/, keys %h }; |
53
|
|
|
|
|
|
|
\ %h } |
54
|
|
|
|
|
|
|
split /^(?=\S)/m, |
55
|
|
|
|
|
|
|
( get( 'http://www2.census.gov/geo/tiger/tiger2k/a2kapd.txt' ) |
56
|
|
|
|
|
|
|
=~ /(^Acad.+)/ms )[0] ) ]; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |