File Coverage

blib/lib/Geo/WebService/OpenCellID.pm
Criterion Covered Total %
statement 43 53 81.1
branch 9 18 50.0
condition n/a
subroutine 13 14 92.8
pod 6 6 100.0
total 71 91 78.0


line stmt bran cond sub pod time code
1             package Geo::WebService::OpenCellID;
2 4     4   442330 use warnings;
  4         21  
  4         244  
3 4     4   20 use strict;
  4         17  
  4         166  
4 4     4   21 use base qw{Geo::WebService::OpenCellID::Base};
  4         7  
  4         1913  
5 4     4   1808 use Geo::WebService::OpenCellID::cell;
  4         11  
  4         104  
6 4     4   1750 use Geo::WebService::OpenCellID::measure;
  4         11  
  4         95  
7 4     4   1592 use LWP::Simple qw{};
  4         405702  
  4         180  
8 4     4   3608 use XML::Simple qw{};
  4         47624  
  4         141  
9 4     4   44 use URI qw{};
  4         10  
  4         2130  
10              
11             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             sub key {
53 2     2 1 6 my $self=shift;
54 2 100       9 $self->{"key"}=shift if @_;
55 2 50       7 $self->{"key"}="myapikey" unless $self->{"key"};
56 2         12 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             sub url {
66 2     2 1 6 my $self=shift;
67 2 100       11 $self->{"url"}=shift if @_;
68 2 100       9 $self->{"url"}="http://www.opencellid.org/" unless $self->{"url"};
69 2         9 return $self->{"url"};
70             }
71              
72             =head2 cell
73              
74             Returns a L object.
75              
76             =cut
77              
78             sub cell {
79 1     1 1 688 my $self=shift;
80 1 50       5 unless (defined($self->{"cell"})) {
81 1         15 $self->{"cell"}=Geo::WebService::OpenCellID::cell->new(parent=>$self);
82             }
83 1         5 return $self->{"cell"};
84             }
85              
86             =head2 measure
87              
88             Returns a L object.
89              
90             =cut
91              
92             sub measure {
93 1     1 1 4 my $self=shift;
94 1 50       6 unless (defined($self->{"measure"})) {
95 1         14 $self->{"measure"}=Geo::WebService::OpenCellID::measure->new(parent=>$self);
96             }
97 1         5 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             sub call {
111 0     0 1 0 my $self=shift;
112 0 0       0 my $path=shift or die;
113 0 0       0 my $class=shift or die;
114 0         0 my $uri=URI->new($self->url);
115 0         0 $uri->path($path);
116 0         0 $uri->query_form(key=>$self->key, @_);
117 0         0 my $content=LWP::Simple::get($uri->as_string);
118 0 0       0 if ($content) {
119 0         0 return $class->new(
120             content => $content,
121             url => $uri,
122             data => $self->data_xml($content),
123             );
124             } else {
125 0         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             sub data_xml {
138 3     3 1 6 my $self=shift;
139 3         6 my $xml=shift;
140 3         39 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, L, L
156              
157             =cut
158              
159             1;