File Coverage

blib/lib/Device/CableModem/Zoom5341/Parse.pm
Criterion Covered Total %
statement 36 36 100.0
branch 11 12 91.6
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 52 55 94.5


line stmt bran cond sub pod time code
1 7     7   40 use strict;
  7         14  
  7         376  
2 7     7   36 use warnings;
  7         13  
  7         234  
3              
4 7     7   36 use Carp;
  7         12  
  7         3740  
5              
6              
7             =head1 NAME
8              
9             Device::CableModem::Zoom5341::Parse
10              
11             =head1 NOTA BENE
12              
13             This is part of the guts of Device::CableModem::Zoom5341. If you're
14             reading this, you're either developing the module, writing tests, or
15             coloring outside the lines; consider yourself warned.
16              
17             =cut
18              
19              
20             =head2 ->parse_connrow_vals
21              
22             Parses out stuff from connection status rows related to up/downstream
23             stats.
24             =cut
25             sub parse_connrow_vals
26             {
27 17     17 0 27 my $self = shift;
28 17         28 my $str = shift;
29              
30 17 50       42 croak "No HTML stashed" unless $self->{conn_html};
31              
32             # Find the JS row
33 17         22 my @row = grep /^var $str = /, @{$self->{conn_html}};
  17         6472  
34 17 100       158 croak "Bad row results for '$str'" unless @row == 1;
35              
36             # Pull out just the string
37 16         86 my ($sval) = ($row[0] =~ /"([^"]+)";/);
38              
39             # And return it split on pipes
40 16         67 my @flds = split /\|/, $sval;
41 16         103 return \@flds;
42             }
43              
44              
45             =head2 ->parse_conn_stats
46              
47             Parse out all the connection status bits.
48             =cut
49             sub parse_conn_stats
50             {
51 4     4 0 1215 my $self = shift;
52              
53 4 100       26 $self->fetch_connection unless $self->{conn_html};
54 4 100       204 croak "No HTML stashed" unless $self->{conn_html};
55              
56             # First grab all the data out of the JS bits
57 3         18 my %dbits = (
58             freq => 'CmDownstreamFrequencyBase',
59             mod => 'CmDownstreamQamBase',
60             power => 'CmDownstreamChannelPowerdBmVBase',
61             snr => 'CmDownstreamSnrBase',
62             );
63 3         16 my %ubits = (
64             chanid => 'CmUpstreamChannelIdBase',
65             freq => 'CmUpstreamFrequencyBase',
66             bw => 'CmUpstreamBwBase',
67             power => 'CmUpstreamChannelPowerBase',
68             );
69              
70             $self->{conn_stats}{down}{$_} = $self->parse_connrow_vals($dbits{$_})
71 3         23 for keys %dbits;
72             $self->{conn_stats}{up}{$_} = $self->parse_connrow_vals($ubits{$_})
73 2         16 for keys %ubits;
74              
75              
76             # Now empty out up/down channels as necessary
77 2         7 my $ds = $self->{conn_stats}{down};
78 2         6 for my $i (0..$#{$ds->{freq}})
  2         10  
79             {
80 16 100       50 unless($ds->{freq}[$i] > 0)
81             {
82 10         49 undef($ds->{$_}[$i]) for keys %dbits
83             }
84             }
85              
86 2         7 my $us = $self->{conn_stats}{up};
87 2         5 for my $i (0..$#{$us->{chanid}})
  2         6  
88             {
89 8 100       24 unless($us->{chanid}[$i] > 0)
90             {
91 4         21 undef($us->{$_}[$i]) for keys %ubits
92             }
93             }
94              
95 2         12 return;
96             }
97              
98              
99             1;
100             __END__