OpenCellID.pm

filter: Statementstmt 82.4% 47 / 57 Branchbran 50.0% 9 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.3% 14 / 15 Podpod 85.7% 6 / 7 totaltotal 78.3% 76 / 97 SCAR 24.5
CC
10
Cov
75%
call
20.0
initialize
3.0
cell
2.0
CRAP 11.6
↑ Summary OpenCellID/Response/cell.pm »
1 package Geo::WebService::OpenCellID;
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use base qw{Geo::WebService::OpenCellID::Base};
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Geo::WebService::OpenCellID::cell;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Geo::WebService::OpenCellID::measure;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use LWP::Simple qw{};
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use XML::Simple qw{};
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use URI qw{};
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 our $VERSION = '0.05';
12  
13 =head1 NAME
14  
15 Geo::WebService::OpenCellID - Perl API for the opencellid.org database
16  
17 =head1 SYNOPSIS
18  
19 use Geo::WebService::OpenCellID;
20 my $gwo=Geo::WebService::OpenCellID->new(key=>$apikey);
21 my $point=$gwo->cell->get(mcc=>$country,
22 mnc=>$network,
23 lac=>$locale,
24 cellid=>$cellid);
25 printf "Lat:%s, Lon:%s\n", $point->latlon;
26  
27 =head1 DESCRIPTION
28  
29 Perl Interface to the database at http://www.opencellid.org/
30  
31 =head1 USAGE
32  
33 =head1 CONSTRUCTOR
34  
35 =head2 new
36  
37 my $obj = Geo::WebService::OpenCellID->new(
38 key=>"myapikey", #default
39 url=>"http://www.opencellid.org/", #default
40 );
41  
42 =cut
43  
44 sub initialize {
45 4 ▶ my $self=shift;
Subroutine initialize: called CC=3 SCAR=11.0
Pod undocumented
46 4 %$self=@_;
47 4 ▶ $self->url("http://www.opencellid.org/") unless $self->url;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->url 4 0 4
48 4 ▶ $self->key("myapikey") unless $self->key;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->key 3 1 4
49 }
50  
51 =head1 METHODS
52  
53 =head2 key
54  
55 Sets and returns the API key.
56  
57 =cut
58  
59 sub key {
60 9 ▶ my $self=shift;
Subroutine key: called CC=2 SCAR=6.9
Pod documented
61 9 ▶ $self->{"key"}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 4 5 9
62 9 return $self->{"key"};
63 }
64  
65 =head2 url
66  
67 Sets and returns the URL. Defaults to http://www.opencellid.org/
68  
69 =cut
70  
71 sub url {
72 10 ▶ my $self=shift;
Subroutine url: called CC=2 SCAR=6.9
Pod documented
73 10 ▶ $self->{"url"}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 5 5 10
74 10 return $self->{"url"};
75 }
76  
77 =head2 cell
78  
79 Returns a L<Geo::WebService::OpenCellID::cell> object.
80  
81 =cut
82  
83 sub cell {
84 1 ▶ my $self=shift;
Subroutine cell: called CC=2 SCAR=7.0
Pod documented
85 1 ▶ unless (defined($self->{"cell"})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"cell"}) 1 0 1
86 1 $self->{"cell"}=Geo::WebService::OpenCellID::cell->new(parent=>$self);
87 }
88 1 return $self->{"cell"};
89 }
90  
91 =head2 measure
92  
93 Returns a L<Geo::WebService::OpenCellID::measure> object.
94  
95 =cut
96  
97 sub measure {
98 1 ▶ my $self=shift;
Subroutine measure: called CC=2 SCAR=7.0
Pod documented
99 1 ▶ unless (defined($self->{"measure"})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"measure"}) 1 0 1
100 1 $self->{"measure"}=Geo::WebService::OpenCellID::measure->new(parent=>$self);
101 }
102 1 return $self->{"measure"};
103 }
104  
105 =head1 METHODS (INTERNAL)
106  
107 =head2 call
108  
109 Calls the web service.
110  
111 my $data=$gwo->call($method_path, $response_class, %parameters);
112  
113 =cut
114  
115 sub call {
116 0 ▶ my $self=shift;
Subroutine call: not called CC=4 SCAR=30.0
Pod documented
117 0 ▶ my $path=shift or die;
Branch: 1 branch
BranchTrueFalseTotal
my $path = shift() or die 0 0 0
118 0 ▶ my $class=shift or die;
Branch: 1 branch
BranchTrueFalseTotal
my $class = shift() or die 0 0 0
119 0 my $uri=URI->new($self->url);
120 0 $uri->path($path);
121 0 $uri->query_form(key=>$self->key, @_);
122 0 my $content=LWP::Simple::get($uri->as_string);
123 0 ▶ if ($content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content) { } 0 0 0
124 0 return $class->new(
125 content => $content,
126 url => $uri,
127 data => $self->data_xml($content),
128 );
129 } else {
130 0 return undef;
131 }
132 }
133  
134 =head2 data_xml
135  
136 Returns a data structure given xml
137  
138 my $ref =$gwo->data_xml();
139  
140 =cut
141  
142 sub data_xml {
143 3 ▶ my $self=shift;
Subroutine data_xml: called CC=1 SCAR=0.0
Pod documented
144 3 my $xml=shift;
145 3 return XML::Simple->new(ForceArray=>1)->XMLin($xml);
146 }
147  
148 =head1 BUGS
149  
150 Submit to RT and email the Author
151  
152 =head1 SUPPORT
153  
154 Try the Author or Try 8motions.com
155  
156 =head1 AUTHOR
157  
158 Michael R. Davis
159 CPAN ID: MRDVT
160 STOP, LLC
161 domain=>michaelrdavis,tld=>com,account=>perl
162 http://www.stopllc.com/
163  
164 =head1 COPYRIGHT
165  
166 This program is free software; you can redistribute
167 it and/or modify it under the same terms as Perl itself.
168  
169 The full text of the license can be found in the
170 LICENSE file included with this module.
171  
172 =head1 SEE ALSO
173  
174 L<URI>, L<LWP::Simple>, L<XML::Simple>
175  
176 =cut
177  
178 4 1;
↑ Summary OpenCellID/Response/cell.pm »