| 1 | package WebService::StreetMapLink; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 5 | ▶ | use vars qw($VERSION); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 5 | $VERSION = 0.21; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 5 | ▶ | use Class::Factory::Util; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 5 | ▶ | use URI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 5 | ▶ | use Params::Validate qw( validate_with SCALAR UNDEF ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 5 | my %CountryToClass; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | sub RegisterSubclass | ||||||||||||||||||||
| 18 | 10 | ▶ | { | ||||||||||||||||||
|
Subroutine
RegisterSubclass: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 19 | 10 | my $class = shift; | |||||||||||||||||||
| 20 | 10 | ▶ | my $priority = shift || 100; | ||||||||||||||||||
|
Condition100%2/2
shift() || 100
MC/DC100%1/1
shift() || 100
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 10 | foreach my $country ( map { lc } $class->Countries ) | |||||||||||||||||||
| 23 | { | ||||||||||||||||||||
| 24 | 90 | push @{ $CountryToClass{$country} }, | |||||||||||||||||||
| 25 | { class => $class, | ||||||||||||||||||||
| 26 | priority => $priority, | ||||||||||||||||||||
| 27 | }; | ||||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | BEGIN | ||||||||||||||||||||
| 32 | 5 | ▶ | { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 33 | 5 | for my $class ( map { __PACKAGE__ . '::' . $_ } __PACKAGE__->subclasses ) | |||||||||||||||||||
| 34 | { | ||||||||||||||||||||
| 35 | 10 | ▶ | eval "use $class"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | 10 | ▶ | die $@ if $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 5 | ▶ | use constant NEW_SPEC => { country => { type => SCALAR }, | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 41 | address => { type => UNDEF | SCALAR, optional => 1 }, | ||||||||||||||||||||
| 42 | city => { type => UNDEF | SCALAR, optional => 1 }, | ||||||||||||||||||||
| 43 | state => { type => UNDEF | SCALAR, optional => 1 }, | ||||||||||||||||||||
| 44 | postal_code => { type => UNDEF | SCALAR, optional => 1 }, | ||||||||||||||||||||
| 45 | subclass => { type => UNDEF | SCALAR, optional => 1 }, | ||||||||||||||||||||
| 46 | 5 | }; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | sub new | ||||||||||||||||||||
| 49 | 9 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||
| 50 | 9 | my $class = shift; | |||||||||||||||||||
| 51 | 9 | my %p = validate_with( params => \@_, | |||||||||||||||||||
| 52 | spec => NEW_SPEC, | ||||||||||||||||||||
| 53 | allow_extra => 1, | ||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 9 | my $subclass; | |||||||||||||||||||
| 57 | 9 | ▶ | if ( $p{subclass} ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | { | ||||||||||||||||||||
| 59 | 4 | ▶ | if ( $p{subclass} =~ /::/ ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | { | ||||||||||||||||||||
| 61 | 0 | $subclass = $p{subclass}; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | else | ||||||||||||||||||||
| 64 | { | ||||||||||||||||||||
| 65 | 4 | $subclass = __PACKAGE__ . '::' . $p{subclass}; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 4 | delete $p{subclass}; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 9 | ▶ | unless ($subclass) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | { | ||||||||||||||||||||
| 73 | 5 | my $country = $class->_sanitize_country( $p{country} ); | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 5 | ▶ | return unless exists $CountryToClass{$country}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | my $entry = | ||||||||||||||||||||
| 78 | 0 | (sort { $a->{priority} <=> $b->{priority} } @{ $CountryToClass{$country} })[0]; | |||||||||||||||||||
| 79 | 5 | $subclass = $entry->{class}; | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 5 | $p{country} = $country; | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 9 | return $subclass->new(%p); | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | sub _sanitize_country | ||||||||||||||||||||
| 88 | 11 | ▶ | { | ||||||||||||||||||
|
Subroutine
_sanitize_country: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 89 | 11 | shift; | |||||||||||||||||||
| 90 | 11 | my $country = shift; | |||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 11 | ▶ | if ( $country =~ /united\s+states|u\.s\.(?:a\.)?/i ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | { | ||||||||||||||||||||
| 94 | 4 | $country = 'usa'; | |||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 11 | ▶ | if ( $country =~ /united\s+kingdom|u\.k\./i ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 98 | { | ||||||||||||||||||||
| 99 | 2 | $country = 'uk'; | |||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 11 | return lc $country; | |||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | sub uri_object | ||||||||||||||||||||
| 106 | 18 | ▶ | { | ||||||||||||||||||
|
Subroutine
uri_object: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||
| 107 | 18 | my $self = shift; | |||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 18 | my $uri = URI->new( '' ); | |||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 18 | foreach my $k ( qw( scheme host path ) ) | |||||||||||||||||||
| 112 | { | ||||||||||||||||||||
| 113 | 54 | my $m = "_$k"; | |||||||||||||||||||
| 114 | 54 | ▶ | $uri->$k( $self->$m() ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 115 | if $self->can($m); | ||||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 18 | ▶ | $uri->query_form( $self->_query ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 119 | if $self->can('_query'); | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 18 | return $uri->canonical; | |||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | sub uri | ||||||||||||||||||||
| 125 | 9 | ▶ | { | ||||||||||||||||||
|
Subroutine
uri: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 126 | 9 | $_[0]->uri_object->as_string; | |||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | 18 | ▶ | sub _scheme { $_[0]->{scheme} ? $_[0]->{scheme} : 'http' } | ||||||||||||||||||
|
Subroutine
_scheme: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | 18 | ▶ | sub _host { $_[0]->{host} } | ||||||||||||||||||
|
Subroutine
_host: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 132 | 18 | ▶ | sub _path { $_[0]->{path} } | ||||||||||||||||||
|
Subroutine
_path: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 133 | 18 | ▶ | sub _query { $_[0]->{query} } | ||||||||||||||||||
|
Subroutine
_query: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | sub service_name | ||||||||||||||||||||
| 136 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
service_name: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 137 | 1 | my $self = shift; | |||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | 1 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | 1 | return ( split /::/, $class )[-1]; | |||||||||||||||||||
| 142 | } | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | 5 | 1; | |||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | __END__ | ||||||||||||||||||||