OpenCellID.pm

filter: Statementstmt 81.8% 45 / 55 Branchbran 50.0% 9 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 92.8% 13 / 14 Podpod 100% 6 / 6 totaltotal 78.4% 73 / 93 CC 10 SCAR 16.1
CC
10
Cov
74%
call
20.0
key
3.0
url
3.0
CRAP 5.0
↑ 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.06';
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 =head1 METHODS
45  
46 =head2 key
47  
48 Sets and returns the API key.
49  
50 =cut
51  
52 2 ▶sub key {
Subroutine key: called CC=3 SCAR=11.0
Pod documented
53 2 my $self=shift;
54 2 ▶ $self->{"key"}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 1 2
55 2 ▶ $self->{"key"}="myapikey" unless $self->{"key"};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"key"} 0 2 2
56 2 return $self->{"key"};
57 }
58  
59 =head2 url
60  
61 Sets and returns the URL. Defaults to http://www.opencellid.org/
62  
63 =cut
64  
65 2 ▶sub url {
Subroutine url: called CC=3 SCAR=11.0
Pod documented
66 2 my $self=shift;
67 2 ▶ $self->{"url"}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 1 2
68 2 ▶ $self->{"url"}="http://www.opencellid.org/" unless $self->{"url"};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"url"} 1 1 2
69 2 return $self->{"url"};
70 }
71  
72 =head2 cell
73  
74 Returns a L<Geo::WebService::OpenCellID::cell> object.
75  
76 =cut
77  
78 1 ▶sub cell {
Subroutine cell: called CC=2 SCAR=7.0
Pod documented
79 1 my $self=shift;
80 1 ▶ unless (defined($self->{"cell"})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"cell"}) 1 0 1
81 1 $self->{"cell"}=Geo::WebService::OpenCellID::cell->new(parent=>$self);
82 }
83 1 return $self->{"cell"};
84 }
85  
86 =head2 measure
87  
88 Returns a L<Geo::WebService::OpenCellID::measure> object.
89  
90 =cut
91  
92 1 ▶sub measure {
Subroutine measure: called CC=2 SCAR=7.0
Pod documented
93 1 my $self=shift;
94 1 ▶ unless (defined($self->{"measure"})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"measure"}) 1 0 1
95 1 $self->{"measure"}=Geo::WebService::OpenCellID::measure->new(parent=>$self);
96 }
97 1 return $self->{"measure"};
98 }
99  
100 =head1 METHODS (INTERNAL)
101  
102 =head2 call
103  
104 Calls the web service.
105  
106 my $data=$gwo->call($method_path, $response_class, %parameters);
107  
108 =cut
109  
110 0 ▶sub call {
Subroutine call: not called CC=4 SCAR=30.0
Pod documented
111 0 my $self=shift;
112 0 ▶ my $path=shift or die;
Branch: 1 branch
BranchTrueFalseTotal
my $path = shift() or die 0 0 0
113 0 ▶ my $class=shift or die;
Branch: 1 branch
BranchTrueFalseTotal
my $class = shift() or die 0 0 0
114 0 my $uri=URI->new($self->url);
115 0 $uri->path($path);
116 0 $uri->query_form(key=>$self->key, @_);
117 0 my $content=LWP::Simple::get($uri->as_string);
118 0 ▶ if ($content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content) { } 0 0 0
119 0 return $class->new(
120 content => $content,
121 url => $uri,
122 data => $self->data_xml($content),
123 );
124 } else {
125 0 return undef;
126 }
127 }
128  
129 =head2 data_xml
130  
131 Returns a data structure given xml
132  
133 my $ref =$gwo->data_xml();
134  
135 =cut
136  
137 3 ▶sub data_xml {
Subroutine data_xml: called CC=1 SCAR=0.0
Pod documented
138 3 my $self=shift;
139 3 my $xml=shift;
140 3 return XML::Simple->new(ForceArray=>1)->XMLin($xml);
141 }
142  
143 =head1 COPYRIGHT
144  
145 Copyright (c) 2025 Michael R. Davis
146  
147 This program is free software; you can redistribute
148 it and/or modify it under the same terms as Perl itself.
149  
150 The full text of the license can be found in the
151 LICENSE file included with this module.
152  
153 =head1 SEE ALSO
154  
155 L<URI>, L<LWP::Simple>, L<XML::Simple>
156  
157 =cut
158  
159 4 1;
↑ Summary OpenCellID/Response/cell.pm »