Zoom5341J/Fetch.pm

filter: Statementstmt 53.4% 23 / 43 Branchbran 7.1% 1 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 2 totaltotal 45.4% 30 / 66 CC 8 SCAR 29.6
CC
8
Cov
42%
fetch_page_rows
42.0
fetch_data
4.8
BEGIN
1.0
CRAP 19.4
↑ Summary Zoom5341J/Parse.pm »
1 # Fetch page from the cablemodem
2 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 =head1 NAME
9  
10 Device::CableModem::Zoom5341J::Fetch
11  
12 =head1 NOTA BENE
13  
14 This is part of the guts of Device::CableModem::Zoom5341J. If you're
15 reading this, you're either developing the module, writing tests, or
16 coloring outside the lines; consider yourself warned.
17  
18 =cut
19  
20  
21 =head2 ->fetch_page_rows
22  
23 Grabs the connection status page from the modem, returns the given HTML.
24 =cut
25  
26 # The URL's we grab
27 7 my $login_url = '/login.asp';
28 7 my $login_post = '/goform/login';
29 7 my $conn_url = '/RgConnect.asp';
30  
31 7 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 7 ▶use HTTP::Request::Common qw/POST/;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 sub fetch_page_rows
34 0 ▶{
Subroutine fetch_page_rows: not called CC=6 SCAR=37.4
Pod undocumented
35 0 my $self = shift;
36  
37 0 my $ua = LWP::UserAgent->new;
38  
39 0 my @uerrs;
40 0 my $ubase = "http://$self->{modem_addr}";
41  
42 # It seems like we have to have hit the base page first, or it fails
43 # us logging in...
44 0 $ua->get("$ubase/");
45  
46 # POST to the login page
47 my $res = $ua->post("${ubase}${login_post}", Content => {
48 loginUsername => $self->{username},
49 loginPassword => $self->{password},
50 0 });
51 0 ▶ croak "Expected redirect, not $res->code"
Branch: 1 branch
BranchTrueFalseTotal
unless $res->code == 302 0 0 0
52 unless $res->code == 302;
53  
54 0 my $rloc = $res->header('Location');
55 0 ▶ croak "No redirect header location" unless $rloc;
Branch: 1 branch
BranchTrueFalseTotal
unless $rloc 0 0 0
56 0 ▶ croak "Login failed" unless $rloc =~ m#$conn_url#;
Branch: 1 branch
BranchTrueFalseTotal
unless $rloc =~ /$conn_url/ 0 0 0
57  
58  
59 # Login succeeded. Go ahead and grab the connection stats.
60 0 my $url = "${ubase}${conn_url}";
61 0 $res = $ua->get($url);
62 0 ▶ croak "Stat page request to $url failed" unless $res->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->is_success 0 0 0
63 0 my $html = $res->content;
64 0 ▶ croak "Got no data from $url" unless $html;
Branch: 1 branch
BranchTrueFalseTotal
unless $html 0 0 0
65  
66 0 return $html;
67 }
68  
69  
70 =head2 ->fetch_data
71  
72 Grabs and stashes the data.
73 =cut
74 sub fetch_data
75 1 ▶{
Subroutine fetch_data: called CC=3 SCAR=15.7
Pod undocumented
76 1 my $self = shift;
77  
78 # Ensure everything's clear
79 1 $self->{conn_html} = undef;
80 1 $self->{conn_stats} = undef;
81  
82 # Backdoor for testing
83 1 ▶ return if $self->{__TESTING_NO_FETCH};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"__TESTING_NO_FETCH"} 1 0 1
84  
85 0 my $html = $self->fetch_page_rows;
86 0 ▶ carp "Failed fetching page from modem" unless $html;
Branch: 1 branch
BranchTrueFalseTotal
unless $html 0 0 0
87 0 $self->{conn_html} = $html;
88  
89 0 return;
90 }
91  
92  
93 7 1;
94 __END__
↑ Summary Zoom5341J/Parse.pm »