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