| 1 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 3 | ▶ | 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 | 3 | $Net::Fritz::Box::VERSION = 'v0.0.7'; | |||||||||
| 9 | |||||||||||
| 10 | # We need LWP::UserAgent 6.00 because of ssl_opts. We could work with | ||||||||||
| 11 | # an older version as seen in https://github.com/rhuss/jmx4perl/issues/28 | ||||||||||
| 12 | # but SOAP::Lite might then have the same problem... For now just | ||||||||||
| 13 | # stick with the versioned dependency. | ||||||||||
| 14 | 3 | ▶ | use LWP::UserAgent 6.00; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 3 | ▶ | use XML::Simple qw(:strict); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 3 | $XML::Simple::PREFERRED_PARSER = 'XML::Parser'; | |||||||||
| 17 | |||||||||||
| 18 | 3 | ▶ | use Net::Fritz::Error; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 3 | ▶ | use Net::Fritz::Device; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | 3 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | 3 | with 'Net::Fritz::IsNoError'; | |||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | 3 | has upnp_url => ( is => 'ro', default => 'http://fritz.box:49000' ); | |||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | 3 | has trdesc_path => ( is => 'ro', default => '/tr64desc.xml' ); | |||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | 3 | has username => ( is => 'ro' ); | |||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | 3 | has password => ( is => 'ro' ); | |||||||||
| 36 | |||||||||||
| 37 | # internal XML::Simple instance (lazy) | ||||||||||
| 38 | 3 | has _xs => ( is => 'lazy', init_arg => undef ); | |||||||||
| 39 | |||||||||||
| 40 | sub _build__xs { | ||||||||||
| 41 | 2 | ▶ | return XML::Simple->new(ForceArray => 1, KeyAttr => []); | ||||||||
|
Subroutine
_build__xs: called CC=1 SCAR=0.0
| |||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | # internal LWP::UserAgent instance (lazy) | ||||||||||
| 45 | # overwriting the default might be handy for setting proxy variables or the like | ||||||||||
| 46 | 3 | has _ua => ( is => 'lazy' ); | |||||||||
| 47 | |||||||||||
| 48 | sub _build__ua { | ||||||||||
| 49 | # Depending on your SSL setup (propably which SSL modules LWP::UserAgent uses | ||||||||||
| 50 | # for transport), this is also needed to disable certificate checks. | ||||||||||
| 51 | # I have one machine that needs it and another that doesn't. | ||||||||||
| 52 | 5 | ▶ | $ENV{HTTPS_DEBUG} = 1; | ||||||||
|
Subroutine
_build__ua: called CC=1 SCAR=0.0
| |||||||||||
| 53 | |||||||||||
| 54 | 5 | my $ua = LWP::UserAgent->new(keep_alive => 1); | |||||||||
| 55 | 5 | $ua->conn_cache({total_capacity => 4}); | |||||||||
| 56 | # disable SSL certificate checks, Fritz!Box has no verifiable SSL certificate | ||||||||||
| 57 | 5 | $ua->ssl_opts(verify_hostname => 0 ,SSL_verify_mode => 0x00); | |||||||||
| 58 | |||||||||||
| 59 | 5 | return $ua; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | # internal SSL attributes for SOAP::Lite instances (lazy) | ||||||||||
| 63 | 3 | has _sslopts => ( is => 'lazy' ); | |||||||||
| 64 | |||||||||||
| 65 | sub _build__sslopts { | ||||||||||
| 66 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_build__sslopts: not called CC=1 SCAR=6.9
| |||||||||||
| 67 | |||||||||||
| 68 | # use the SSL options from the LWP::UserAgent instance | ||||||||||
| 69 | # copy ALL keys including undefined values | ||||||||||
| 70 | 0 | return [ map { $_ => $self->_ua->ssl_opts($_) } $self->_ua->ssl_opts ]; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | |||||||||||
| 74 | sub discover { | ||||||||||
| 75 | 2 | ▶ | my $self = shift; | ||||||||
|
Subroutine
discover: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 76 | |||||||||||
| 77 | 2 | my $url = $self->upnp_url . $self->trdesc_path; | |||||||||
| 78 | |||||||||||
| 79 | 2 | my $response = $self->_ua->get($url); | |||||||||
| 80 | |||||||||||
| 81 | 2 | ▶ | if ($response->is_success) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | return Net::Fritz::Device->new( | ||||||||||
| 83 | 1 | xmltree => $self->_xs->parse_string($response->decoded_content)->{device}->[0], | |||||||||
| 84 | fritz => $self | ||||||||||
| 85 | ); | ||||||||||
| 86 | } | ||||||||||
| 87 | else { | ||||||||||
| 88 | 1 | return Net::Fritz::Error->new($response->status_line) | |||||||||
| 89 | } | ||||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | |||||||||||
| 93 | sub dump { | ||||||||||
| 94 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
dump: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 95 | 0 | my $indent = shift; | |||||||||
| 96 | 0 | ▶ | $indent = '' unless defined $indent; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | |||||||||||
| 98 | 0 | my $text = "${indent}Net::Fritz::Box:\n"; | |||||||||
| 99 | 0 | $indent .= ' '; | |||||||||
| 100 | 0 | $text .= "${indent}upnp_url = " . $self->upnp_url . "\n"; | |||||||||
| 101 | 0 | $text .= "${indent}trdesc_path = " . $self->trdesc_path . "\n"; | |||||||||
| 102 | |||||||||||
| 103 | 0 | return $text; | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | |||||||||||
| 107 | 3 | 1; | |||||||||
| 108 | |||||||||||
| 109 | __END__ | ||||||||||