Formatter.pm

filter: Statementstmt 96.9% 64 / 66 Branchbran 59.0% 13 / 22 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 15 / 15 Podpod 100% 4 / 4 totaltotal 86.6% 97 / 112 CC 15 SCAR 14.0
CC
15
Cov
86%
alias_format
8.3
__formatter
4.6
add_format
4.3
CRAP 4.0
« Formatter/FormatBase/Double.pm ↑ Summary Formatter/Format/Degree.pm »
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
BranchTrueFalseTotal
unless ("Class::Inspector"->loaded($class)) 12 0 12
33 12 ▶ if ($class->require) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->require) { } 12 0 12
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
BranchTrueFalseTotal
if ($Geo::Formatter::logic{$format} and $Geo::Formatter::logic{$format}{$dir}) 27 0 27
Condition33%1/3
$Geo::Formatter::logic{$format} and $Geo::Formatter::logic{$format}{$dir}
!ll&&!rl&&r
0027
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}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($code) { } 27 0 27
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
BranchTrueFalseTotal
my $base_setting = $Geo::Formatter::logic{$base} or croak("Cannot find base format: $base") 4 0 4
76 4 ▶ $logic{$format} = {} unless ($logic{$format});
Branch: 1 branch
BranchTrueFalseTotal
unless $Geo::Formatter::logic{$format} 4 0 4
77  
78 4 foreach my $dir ("encode","decode") {
79 my %dir_opt = $opt ?
80 (
81 8 ▶ %{$opt},
Branch: 1 branch
BranchTrueFalseTotal
$opt->{$dir} ? : 4 4 8
82 8 ▶ ($opt->{$dir} ? %{$opt->{$dir}} : ()),
Branch: 1 branch
BranchTrueFalseTotal
$opt ? : 8 0 8
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
BranchTrueFalseTotal
ref $_[$#_] eq 'HASH' ? : 7 0 7
91 7 %opt = (
92 %dir_opt,
93 %opt,
94 );
95 7 $base_setting->{$dir}->(@_,\%opt);
96 } :
97 8 ▶ $base_setting->{$dir} :
Branch: 2 branches
BranchTrueFalseTotal
$base_setting->{$dir} ? : 8 0 8
%dir_opt ? : 6 2 8
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__
« Formatter/FormatBase/Double.pm ↑ Summary Formatter/Format/Degree.pm »