Fritz/Box.pm

filter: Statementstmt 100% 53 / 53 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 100% 2 / 2 totaltotal 100% 71 / 71 CC 3 SCAR 2.5
CC
3
Cov
100%
discover
2.0
dump
2.0
BEGIN
1.0
CRAP 1.3
« Fritz/Error.pm ↑ Summary Fritz.pm »
1 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 # Copyright (C) 2015 Christian Garbs <mitch@cgarbs.de>
4 # Licensed under GNU GPL v2 or later.
5  
6 package Net::Fritz::Box;
7 # ABSTRACT: main configuration and entry point for L<Net::Fritz> distribution
8 5 $Net::Fritz::Box::VERSION = 'v0.0.2';
9  
10 5 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use XML::Simple qw(:strict);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 ▶use Net::Fritz::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Net::Fritz::Device;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 5 with 'Net::Fritz::IsNoError';
19  
20  
21 5 has upnp_url => ( is => 'ro', default => 'http://fritz.box:49000' );
22  
23  
24 5 has trdesc_path => ( is => 'ro', default => '/tr64desc.xml' );
25  
26  
27 5 has username => ( is => 'ro' );
28  
29  
30 5 has password => ( is => 'ro' );
31  
32 # internal XML::Simple instance (lazy)
33 5 has _xs => ( is => 'lazy', init_arg => undef );
34  
35 sub _build__xs {
36 16 ▶ return XML::Simple->new(ForceArray => 1, KeyAttr => []);
Subroutine _build__xs: called CC=1 SCAR=0.0
37 }
38  
39 # internal LWP::UserAgent instance (lazy)
40 # overwriting the default might be handy for setting proxy variables or the like
41 5 has _ua => ( is => 'lazy' );
42  
43 sub _build__ua {
44 # Depending on your SSL setup (propably which SSL modules LWP::UserAgent uses
45 # for transport), this is also needed to disable certificate checks.
46 # I have one machine that needs it and another that doesn't.
47 20 ▶ $ENV{HTTPS_DEBUG} = 1;
Subroutine _build__ua: called CC=1 SCAR=0.0
48
49 20 my $ua = LWP::UserAgent->new();
50 # disable SSL certificate checks, Fritz!Box has no verifiable SSL certificate
51 20 $ua->ssl_opts(verify_hostname => 0 ,SSL_verify_mode => 0x00);
52
53 20 return $ua;
54 }
55  
56 # internal SSL attributes for SOAP::Lite instances (lazy)
57 5 has _sslopts => ( is => 'lazy' );
58  
59 sub _build__sslopts {
60 9 ▶ my $self = shift;
Subroutine _build__sslopts: called CC=1 SCAR=0.0
61  
62 # use the SSL options from the LWP::UserAgent instance
63 # copy ALL keys including undefined values
64 9 return [ map { $_ => $self->_ua->ssl_opts($_) } $self->_ua->ssl_opts ];
65 }
66  
67  
68 sub discover {
69 3 ▶ my $self = shift;
Subroutine discover: called CC=2 SCAR=6.9
Pod documented
70  
71 3 my $url = $self->upnp_url . $self->trdesc_path;
72
73 3 my $response = $self->_ua->get($url);
74
75 3 ▶ if ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 2 1 3
76 return Net::Fritz::Device->new(
77 2 xmltree => $self->_xs->parse_string($response->decoded_content)->{device}->[0],
78 fritz => $self
79 );
80 }
81 else {
82 1 return Net::Fritz::Error->new($response->status_line)
83 }
84 }
85  
86  
87 sub dump {
88 2 ▶ my $self = shift;
Subroutine dump: called CC=2 SCAR=6.9
Pod documented
89 2 my $indent = shift;
90 2 ▶ $indent = '' unless defined $indent;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $indent 1 1 2
91  
92 2 my $text = "${indent}Net::Fritz::Box:\n";
93 2 $indent .= ' ';
94 2 $text .= "${indent}upnp_url = " . $self->upnp_url . "\n";
95 2 $text .= "${indent}trdesc_path = " . $self->trdesc_path . "\n";
96  
97 2 return $text;
98 }
99  
100  
101 5 1;
102  
103 __END__
« Fritz/Error.pm ↑ Summary Fritz.pm »