| 1 | package Power::Outlet::Common::IP::HTTP; | ||||||||||
| 2 | 8 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 8 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 8 | ▶ | use URI qw{}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 8 | ▶ | use HTTP::Tiny qw{}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 8 | ▶ | use base qw{Power::Outlet::Common::IP}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 8 | our $VERSION = '0.54'; | |||||||||
| 9 | |||||||||||
| 10 | =head1 NAME | ||||||||||
| 11 | |||||||||||
| 12 | Power::Outlet::Common::IP::HTTP - Power::Outlet base class for HTTP power outlet | ||||||||||
| 13 | |||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||
| 15 | |||||||||||
| 16 | use base qw{Power::Outlet::Common::IP::HTTP}; | ||||||||||
| 17 | |||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||
| 19 | |||||||||||
| 20 | Power::Outlet::Common::IP::HTTP is a package for controlling and querying an HTTP-based network attached power outlet. | ||||||||||
| 21 | |||||||||||
| 22 | =head1 USAGE | ||||||||||
| 23 | |||||||||||
| 24 | use base qw{Power::Outlet::Common::IP::HTTP}; | ||||||||||
| 25 | |||||||||||
| 26 | =head1 METHODS | ||||||||||
| 27 | |||||||||||
| 28 | =head2 url | ||||||||||
| 29 | |||||||||||
| 30 | Returns a configured L<URI::http> object | ||||||||||
| 31 | |||||||||||
| 32 | =cut | ||||||||||
| 33 | |||||||||||
| 34 | 1 | ▶ | sub url { | ||||||||
|
Subroutine
url: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||
| 35 | 1 | my $self = shift; | |||||||||
| 36 | 1 | ▶ | $self->{'url'} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 1 | ▶ | unless (defined $self->{'url'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 1 | my $url = URI->new; | |||||||||
| 39 | 1 | $url->scheme($self->http_scheme); | |||||||||
| 40 | 1 | $url->host($self->host); #from Power::Outlet::Common::IP | |||||||||
| 41 | 1 | $url->port($self->port); #from Power::Outlet::Common::IP | |||||||||
| 42 | 1 | $url->path($self->http_path); #from Power::Outlet::Common::IP::HTTP | |||||||||
| 43 | 1 | $self->{'url'} = $url; | |||||||||
| 44 | } | ||||||||||
| 45 | 1 | ▶ | die unless $self->{'url'}->isa('URI'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 1 | return $self->{'url'}->clone; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | =head1 PROPERTIES | ||||||||||
| 50 | |||||||||||
| 51 | =head2 http_scheme | ||||||||||
| 52 | |||||||||||
| 53 | Set and returns the http_scheme property | ||||||||||
| 54 | |||||||||||
| 55 | Default: http | ||||||||||
| 56 | |||||||||||
| 57 | =cut | ||||||||||
| 58 | |||||||||||
| 59 | 1 | ▶ | sub http_scheme { | ||||||||
|
Subroutine
http_scheme: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||
| 60 | 1 | my $self = shift; | |||||||||
| 61 | 1 | ▶ | $self->{'http_scheme'} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 1 | ▶ | $self->{'http_scheme'} = $self->_http_scheme_default unless defined $self->{'http_scheme'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 1 | return $self->{'http_scheme'}; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 1 | ▶ | sub _http_scheme_default {'http'}; | ||||||||
|
Subroutine
_http_scheme_default: called CC=1 SCAR=0.0
| |||||||||||
| 67 | |||||||||||
| 68 | 0 | ▶ | sub _port_default {'80'}; #HTTP | ||||||||
|
Subroutine
_port_default: not called CC=1 SCAR=6.9
| |||||||||||
| 69 | |||||||||||
| 70 | =head2 http_path | ||||||||||
| 71 | |||||||||||
| 72 | Set and returns the http_path property | ||||||||||
| 73 | |||||||||||
| 74 | Default: / | ||||||||||
| 75 | |||||||||||
| 76 | =cut | ||||||||||
| 77 | |||||||||||
| 78 | 2 | ▶ | sub http_path { | ||||||||
|
Subroutine
http_path: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 79 | 2 | my $self = shift; | |||||||||
| 80 | 2 | ▶ | $self->{'http_path'} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 2 | ▶ | $self->{'http_path'} = $self->_http_path_default unless defined $self->{'http_path'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 2 | return $self->{'http_path'}; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 0 | ▶ | sub _http_path_default {'/upnp/control/basicevent1'}; #WeMo | ||||||||
|
Subroutine
_http_path_default: not called CC=1 SCAR=6.9
| |||||||||||
| 86 | |||||||||||
| 87 | =head1 OBJECT ACCESSORS | ||||||||||
| 88 | |||||||||||
| 89 | =head2 http_client | ||||||||||
| 90 | |||||||||||
| 91 | Returns a cached L<HTTP::Tiny> web client | ||||||||||
| 92 | |||||||||||
| 93 | =cut | ||||||||||
| 94 | |||||||||||
| 95 | 0 | ▶ | sub http_client { | ||||||||
|
Subroutine
http_client: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 96 | 0 | my $self = shift; | |||||||||
| 97 | 0 | ▶ | $self->{'http_client'} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | $self->{'http_client'} = HTTP::Tiny->new | ||||||||||
| 99 | 0 | ▶ | unless ref($self->{'http_client'}) eq 'HTTP::Tiny'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | 0 | return $self->{'http_client'}; | |||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | =head1 BUGS | ||||||||||
| 104 | |||||||||||
| 105 | Please log on RT and send an email to the author. | ||||||||||
| 106 | |||||||||||
| 107 | =head1 SUPPORT | ||||||||||
| 108 | |||||||||||
| 109 | DavisNetworks.com supports all Perl applications including this package. | ||||||||||
| 110 | |||||||||||
| 111 | =head1 AUTHOR | ||||||||||
| 112 | |||||||||||
| 113 | Michael R. Davis | ||||||||||
| 114 | CPAN ID: MRDVT | ||||||||||
| 115 | DavisNetworks.com | ||||||||||
| 116 | |||||||||||
| 117 | =head1 COPYRIGHT | ||||||||||
| 118 | |||||||||||
| 119 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||
| 120 | |||||||||||
| 121 | The full text of the license can be found in the LICENSE file included with this module. | ||||||||||
| 122 | |||||||||||
| 123 | =head1 SEE ALSO | ||||||||||
| 124 | |||||||||||
| 125 | L<URI>, L<HTTP::Tiny> | ||||||||||
| 126 | |||||||||||
| 127 | =cut | ||||||||||
| 128 | |||||||||||
| 129 | 8 | 1; | |||||||||