| 1 | package Geo::Formatter; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use version; our $VERSION = qv('0.0.1'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use vars qw(@ISA @EXPORT); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 6 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 11 | 6 | @EXPORT = qw(latlng2format format2latlng alias_format); | |||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Class::Inspector; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use UNIVERSAL::require; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 6 | our %logic = (); | |||||||||||||||||||||||||||
| 16 | # our @search = (); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 6 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 6 | my $pkg = shift; | |||||||||||||||||||||||||||
| 20 | 6 | my @formats = @_; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 6 | $pkg->add_format("Degree","DMS",@_); | |||||||||||||||||||||||||||
| 23 | 6 | $pkg->export_to_level(1, $pkg); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 6 | ▶ | sub add_format { | ||||||||||||||||||||||||||
|
Subroutine
add_format: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 6 | my $pkg = shift; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 6 | foreach my $format (@_) { | |||||||||||||||||||||||||||
| 30 | 12 | my $class = "Geo::Formatter::Format::$format"; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 12 | ▶ | unless( Class::Inspector->loaded($class) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 12 | ▶ | if ($class->require) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 12 | $class->import; | |||||||||||||||||||||||||||
| 35 | } else { | ||||||||||||||||||||||||||||
| 36 | 0 | croak "Cannot load format : $format"; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 27 | ▶ | sub __formatter { | ||||||||||||||||||||||||||
|
Subroutine
__formatter: called CC=4 SCAR=15.2
| |||||||||||||||||||||||||||||
| 43 | 27 | my $dir = shift; | |||||||||||||||||||||||||||
| 44 | 27 | my $format = shift; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 27 | my $code; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 27 | ▶ | if ($logic{$format} && $logic{$format}->{$dir}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Geo::Formatter::logic{$format} and $Geo::Formatter::logic{$format}{$dir}
MC/DC0%0/2
$Geo::Formatter::logic{$format} and $Geo::Formatter::logic{$format}{$dir}
$Geo::Formatter::logic{$format}
$Geo::Formatter::logic{$format}{$dir}
Truth table33%1/3
A and B
A= $Geo::Formatter::logic{$format}B= $Geo::Formatter::logic{$format}{$dir}
| |||||||||||||||||||||||||||||
| 49 | 27 | $code = $logic{$format}->{$dir}; | |||||||||||||||||||||||||||
| 50 | }# else { | ||||||||||||||||||||||||||||
| 51 | # foreach my $search (@search) { | ||||||||||||||||||||||||||||
| 52 | # last if ($code = $search->match($format,$dir)); | ||||||||||||||||||||||||||||
| 53 | # } | ||||||||||||||||||||||||||||
| 54 | # } | ||||||||||||||||||||||||||||
| 55 | 27 | ▶ | if ($code) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 27 | return $code->(@_); | |||||||||||||||||||||||||||
| 57 | } else { | ||||||||||||||||||||||||||||
| 58 | 0 | croak "Cannot $dir $format format"; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 13 | ▶ | sub latlng2format { | ||||||||||||||||||||||||||
|
Subroutine
latlng2format: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 13 | __formatter("encode",@_); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 14 | ▶ | sub format2latlng { | ||||||||||||||||||||||||||
|
Subroutine
format2latlng: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 14 | __formatter("decode",@_); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 4 | ▶ | sub alias_format { | ||||||||||||||||||||||||||
|
Subroutine
alias_format: called CC=8 SCAR=21.2
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | 4 | my $format = shift; | |||||||||||||||||||||||||||
| 72 | 4 | my $base = shift; | |||||||||||||||||||||||||||
| 73 | 4 | my $opt = shift; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 4 | ▶ | my $base_setting = $logic{$base} or croak("Cannot find base format: $base"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 4 | ▶ | $logic{$format} = {} unless ($logic{$format}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 4 | foreach my $dir ("encode","decode") { | |||||||||||||||||||||||||||
| 79 | my %dir_opt = $opt ? | ||||||||||||||||||||||||||||
| 80 | ( | ||||||||||||||||||||||||||||
| 81 | 8 | ▶ | %{$opt}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 8 | ▶ | ($opt->{$dir} ? %{$opt->{$dir}} : ()), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | ) : | ||||||||||||||||||||||||||||
| 84 | (); | ||||||||||||||||||||||||||||
| 85 | 8 | delete @dir_opt{qw(decode encode)}; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | my $code = $base_setting->{$dir} ? | ||||||||||||||||||||||||||||
| 88 | %dir_opt ? | ||||||||||||||||||||||||||||
| 89 | 7 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 90 | 7 | ▶ | my %opt = ref($_[$#_]) eq 'HASH' ? %{ pop() } : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 7 | %opt = ( | |||||||||||||||||||||||||||
| 92 | %dir_opt, | ||||||||||||||||||||||||||||
| 93 | %opt, | ||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||
| 95 | 7 | $base_setting->{$dir}->(@_,\%opt); | |||||||||||||||||||||||||||
| 96 | } : | ||||||||||||||||||||||||||||
| 97 | 8 | ▶ | $base_setting->{$dir} : | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 98 | undef; | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 8 | $logic{$format}->{$dir} = $code; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 6 | 1; # Magic true value required at end of module | |||||||||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||||||||||