Geo.pm

filter: Statementstmt 46.0% 23 / 50 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 38 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 58.3% 7 / 12 Podpod 100% 4 / 4 totaltotal 24.6% 34 / 138 CC 23 SCAR 53.7
CC
23
Cov
23%
_build_params
380.0
new
12.0
get
12.0
CRAP 214.8
↑ Summary Geo/Company.pm »
1 # ABSTRACT: Performs queries using Yandex Maps Company Search API
2  
3 package Yandex::Geo;
4 1 $Yandex::Geo::VERSION = '0.01';
5  
6  
7 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Geo::JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Yandex::Geo::Company;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 sub cities_bbox {
18 0 ▶ return { 'ROV' => '39.535873,47.146130~39.842460,47.356752' };
Subroutine cities_bbox: not called CC=1 SCAR=6.9
Pod documented
19 }
20  
21  
22 sub new {
23 0 ▶ my ( $class, %params ) = @_;
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
24  
25 confess 'Empty apikey'
26 0 ▶ unless defined $params{apikey} && length $params{apikey};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params{"apikey"} and length $params{"apikey"} 0 0 0
Condition0%0/3
defined $params{"apikey"} and length $params{"apikey"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $params{"apikey"} and length $params{"apikey"}
defined $params{"apikey"} length $params{"apikey"}
Truth table0%0/3
A and B
A= defined $params{"apikey"}B= length $params{"apikey"}
ABresult
0X0
100
111
27  
28 0 my $self = {
29 ua => LWP::UserAgent->new( timeout => 10 ),
30 base_url => 'https://search-maps.yandex.ru/v1/',
31 %params,
32 };
33  
34 0 bless $self, $class;
35 }
36  
37  
38 sub get {
39 0 ▶ my ( $self, %params ) = @_;
Subroutine get: not called CC=3 SCAR=24.8
Pod documented
40  
41 0 my $url_params = $self->_build_params(%params);
42 0 my $url = URI->new( $self->{base_url} );
43 0 $url->query_form($url_params);
44  
45 0 my $response = $self->{ua}->get($url);
46  
47 0 ▶ unless ( $response->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
48 0 ▶ if ( int( $response->code / 100 ) == 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (int $response->code / 100 == 4) 0 0 0
49 0 die $response->status_line . ': ' . $response->decoded_content;
50 }
51  
52 0 die $response->status_line;
53 }
54  
55 0 Geo::JSON->from_json( $response->decoded_content );
56  
57 }
58  
59  
60 sub y_companies {
61 0 ▶ my ( $self, $text, %params ) = @_;
Subroutine y_companies: not called CC=1 SCAR=6.9
Pod documented
62  
63 0 my $geo_json = $self->get( text => $text, %params );
64 0 Yandex::Geo::Company::from_geo_json($geo_json);
65 }
66  
67 sub _build_params {
68 0 ▶ my ( $self, %params ) = @_;
Subroutine _build_params: not called CC=19 SCAR=59.4
69  
70 # Set default parameters
71  
72 confess 'No search text provided'
73 0 ▶ unless defined $params{text} && length $params{text};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params{"text"} and length $params{"text"} 0 0 0
Condition0%0/3
defined $params{"text"} and length $params{"text"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $params{"text"} and length $params{"text"}
defined $params{"text"} length $params{"text"}
Truth table0%0/3
A and B
A= defined $params{"text"}B= length $params{"text"}
ABresult
0X0
100
111
74  
75 my $mess = {
76 apikey => $self->{apikey},
77 text => $params{text},
78 type => $self->{type} || $params{type} || 'biz',
79 lang => $self->{lang} || $params{lang} || 'ru_RU',
80 ll => $self->{ll} || $params{ll},
81 spn => $self->{spn} || $params{spn},
82 bbox => $self->{bbox} || $params{bbox},
83 rspn => $self->{rspn} || $params{rspn} || 1,
84 results => $self->{results} || $params{results} || 25,
85 skip => $self->{skip} || $params{skip}
86 0 ▶ };
Condition0%0/32
$self->{'type'} || $params{'type'} || 'biz'
l!l
00
$self->{"type"} or $params{"type"}
l!l&&r!l&&!r
000
$self->{'lang'} || $params{'lang'} || 'ru_RU'
l!l
00
$self->{"lang"} or $params{"lang"}
l!l&&r!l&&!r
000
$self->{'ll'} || $params{'ll'}
l!l&&r!l&&!r
000
$self->{'spn'} || $params{'spn'}
l!l&&r!l&&!r
000
$self->{'bbox'} || $params{'bbox'}
l!l&&r!l&&!r
000
$self->{'rspn'} || $params{'rspn'} || 1
l!l
00
$self->{"rspn"} or $params{"rspn"}
l!l&&r!l&&!r
000
$self->{'results'} || $params{'results'} || 25
l!l
00
$self->{"results"} or $params{"results"}
l!l&&r!l&&!r
000
$self->{'skip'} || $params{'skip'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'type'} || $params{'type'} || 'biz'
$self->{"type"} $params{"type"}
MC/DC0%0/2
$self->{'lang'} || $params{'lang'} || 'ru_RU'
$self->{"lang"} $params{"lang"}
MC/DC0%0/2
$self->{'ll'} || $params{'ll'}
$self->{'ll'} $params{'ll'}
MC/DC0%0/2
$self->{'spn'} || $params{'spn'}
$self->{'spn'} $params{'spn'}
MC/DC0%0/2
$self->{'bbox'} || $params{'bbox'}
$self->{'bbox'} $params{'bbox'}
MC/DC0%0/2
$self->{'rspn'} || $params{'rspn'} || 1
$self->{"rspn"} $params{"rspn"}
MC/DC0%0/2
$self->{'results'} || $params{'results'} || 25
$self->{"results"} $params{"results"}
MC/DC0%0/2
$self->{'skip'} || $params{'skip'}
$self->{'skip'} $params{'skip'}
Truth table0%0/3
A or B
A= $self->{"type"}B= $params{"type"}
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $self->{"lang"}B= $params{"lang"}
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $self->{'ll'}B= $params{'ll'}
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $self->{'spn'}B= $params{'spn'}
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $self->{'bbox'}B= $params{'bbox'}
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $self->{"rspn"}B= $params{"rspn"}
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $self->{"results"}B= $params{"results"}
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $self->{'skip'}B= $params{'skip'}
ABresult
1X1
011
000
87  
88 $mess->{bbox} = $self->cities_bbox->{ $self->{only_city} }
89 0 ▶ if defined $self->{only_city};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"only_city"} 0 0 0
90 $mess->{bbox} = $self->cities_bbox->{ $params{only_city} }
91 0 ▶ if defined $params{only_city};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params{"only_city"} 0 0 0
92  
93 # Remove empty params to not overload query
94  
95 0 for my $k ( keys %$mess ) {
96 0 ▶ delete $mess->{$k} unless $mess->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless $mess->{$k} 0 0 0
97 }
98  
99 0 delete $mess->{only_city};
100  
101 0 return $mess;
102  
103 }
104  
105 1 1;
106  
107 __END__
↑ Summary Geo/Company.pm »