blib/lib/Net/Wigle.pm

filter: Statementstmt 53.2% 33 / 62 Branchbran 0.0% 0 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 70.0% 7 / 10 Podpod 25.0% 1 / 4 totaltotal 46.1% 42 / 91 CC 7 SCAR 20.8
CC
7
Cov
45%
query
20.0
log_in
12.0
new
2.0
CRAP 8.0
↑ Summary
1 # see POD at the bottom for documentation
2 package Net::Wigle;
3  
4 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Params::Validate qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use 5.010000;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 require Exporter;
12  
13 1 our @ISA = qw(
14 Exporter
15 LWP::UserAgent
16 );
17  
18 # Items to export into callers namespace by default. Note: do not export
19 # names by default without a very good reason. Use EXPORT_OK instead.
20 # Do not simply export all your public functions/methods/constants.
21  
22 # This allows declaration use Net::Wigle ':all';
23 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
24 # will save memory.
25 1 our %EXPORT_TAGS = ( 'all' => [ qw(
26 ) ] );
27  
28 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
29  
30 1 our @EXPORT = qw(
31 );
32  
33 1 our $VERSION = '0.05';
34 1 our $url_query_base = 'https://wigle.net/gps/gps/main/confirmquery/';
35 1 our $url_login = 'https://wigle.net/gps/gps/main/login/';
36  
37 sub new {
38 1 ▶ my $proto = shift;
Subroutine new: called CC=2 SCAR=7.1
Pod documented
39 1 ▶ my $class = ref $proto || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
40 1 my $self = {};
41 1 bless $self, $class;
42 1 $self->requests_redirectable(['GET', 'HEAD', 'POST']);
43 1 return $self;
44 }
45  
46 # purpose : login to wigle.net
47  
48 sub log_in {
49 0 ▶ my $self = shift;
Subroutine log_in: not called CC=3 SCAR=24.8
Pod undocumented
50 0 my %args = validate @_, {
51 user => { type => SCALAR, },
52 pass => { type => SCALAR, },
53 };
54 0 ▶ unless ($self->cookie_jar) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->cookie_jar) 0 0 0
55 0 $self->cookie_jar({});
56 }
57 my $form = {
58 credential_0 => $args{user},
59 credential_1 => $args{pass},
60 0 noexpire => 'checked',
61 };
62 0 my $response = $self->post($url_login, $form);
63 0 ▶ unless ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
64 0 return undef;
65 }
66 0 return $self->cookie_jar;
67 }
68  
69 # purpose : returns a parsed/scraped version of query_raw
70  
71 sub query {
72 0 ▶ my $self = shift;
Subroutine query: not called CC=4 SCAR=30.0
Pod undocumented
73 0 my %args = validate @_, {
74 user => {
75 type => SCALAR,
76 },
77 pass => {
78 type => SCALAR,
79 },
80 variance => {
81 default => '0.010',
82 },
83 latrange1 => {
84 optional => 1,
85 },
86 latrange2 => {
87 optional => 1,
88 },
89 longrange1 => {
90 optional => 1,
91 },
92 longrange2 => {
93 optional => 1,
94 },
95 addresscode => {
96 optional => 1,
97 },
98 statecode => {
99 optional => 1,
100 },
101 zipcode => {
102 optional => 1,
103 },
104 pagestart => {
105 optional => 1,
106 },
107 lastupdt => {
108 optional => 1,
109 },
110 netid => {
111 optional => 1,
112 },
113 ssid => {
114 optional => 1,
115 },
116 freenet => {
117 optional => 1,
118 },
119 paynet => {
120 optional => 1,
121 },
122 dhcp => {
123 optional => 1,
124 },
125 onlymine => {
126 optional => 1,
127 },
128 Query => {
129 default => 'Query',
130 },
131 };
132 my $cookie_jar = $self->log_in(
133 user => $args{user},
134 pass => $args{pass},
135 0 );
136 0 ▶ unless ($cookie_jar) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cookie_jar) 0 0 0
137 0 return undef;
138 }
139 0 delete $args{user};
140 0 delete $args{pass};
141 0 my $response = $self->query_raw(%args);
142 0 ▶ unless ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
143 0 return undef;
144 }
145 0 my $string_search_response = $response->as_string;
146 0 my @records;
147 #$string_search_response =~ qr/.*\<tr\s+class="search"\s*\>(.*?)\<\/tr.*/xmsi;
148 0 ▶ while ($string_search_response =~ m{
Branch: 1 branch
BranchTrueFalseTotal
if ($string_search_response =~ m[ \<tr\s+class="search"\s*\> (.*?) \</tr ]gimsx) 0 0 0
149 \<tr\s+class="search"\s*\>
150 (.*?)
151 \</tr
152 }xmsgi) {
153 0 my $row_raw = $1;
154 0 $row_raw =~ m{
155 <td>(.*?)</td>\s* # map link
156 <td>(.*?)</td>\s* # netid
157 <td>(.*?)</td>\s* # ssid
158 <td>(.*?)</td>\s* # comment
159 <td>(.*?)</td>\s* # name
160 <td>(.*?)</td>\s* # type
161 <td>(.*?)</td>\s* # freenet
162 <td>(.*?)</td>\s* # paynet
163 <td>(.*?)</td>\s* # firsttime
164 <td>(.*?)</td>\s* # lasttime
165 <td>(.*?)</td>\s* # flags
166 <td>(.*?)</td>\s* # wep
167 <td>(.*?)</td>\s* # trilat
168 <td>(.*?)</td>\s* # trilong
169 <td>(.*?)</td>\s* # dhcp
170 <td>(.*?)</td>\s* # lastupdt
171 <td>(.*?)</td>\s* # channel
172 <td>(.*?)</td>\s* # active
173 <td>(.*?)</td>\s* # bcninterval
174 <td>(.*?)</td>\s* # qos
175 }xmsgi;
176 0 push @records, {
177 netid => $2,
178 ssid => $3,
179 comment => $4,
180 name => $5,
181 type => $6,
182 freenet => $7,
183 paynet => $8,
184 firsttime => $9,
185 lasttime => $10,
186 flags => $11,
187 wep => $12,
188 trilat => $13,
189 trilong => $14,
190 dhcp => $15,
191 lastupdt => $16,
192 channel => $17,
193 active => $18,
194 bcninterval => $19,
195 qos => $20,
196 userfound => $21,
197 };
198 }
199 0 return \@records;
200 }
201  
202 # purpose : query wigle, trying to keep this simple
203 # usage : args are optional, just provided for informational purposes
204 # comments : returns an HTTP::Response object
205  
206 sub query_raw {
207 0 ▶ my $self = shift;
Subroutine query_raw: not called CC=1 SCAR=6.9
Pod undocumented
208 0 my %args = @_;
209 0 return $self->post($url_query_base, \%args);
210 }
211  
212 1 1;
213 __END__
↑ Summary