| 1 | package Power::Outlet::Virtual; | ||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use File::Spec qw{}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use Path::Class qw{}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use base qw{Power::Outlet::Common}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | our $VERSION = '0.54'; | |||||||||
| 9 | |||||||||||
| 10 | =head1 NAME | ||||||||||
| 11 | |||||||||||
| 12 | Power::Outlet::Virtual - Control and query a Virtual Outlet | ||||||||||
| 13 | |||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||
| 15 | |||||||||||
| 16 | my $outlet = Power::Outlet::iBootBar->new(id => 1); | ||||||||||
| 17 | print $outlet->query, "\n"; | ||||||||||
| 18 | print $outlet->on, "\n"; | ||||||||||
| 19 | print $outlet->off, "\n"; | ||||||||||
| 20 | |||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||
| 22 | |||||||||||
| 23 | Power::Outlet::Virtual is a package for controlling and querying a virtual outlet where the state is stored in a temp file. | ||||||||||
| 24 | |||||||||||
| 25 | =head1 USAGE | ||||||||||
| 26 | |||||||||||
| 27 | =head1 CONSTRUCTOR | ||||||||||
| 28 | |||||||||||
| 29 | =head2 new | ||||||||||
| 30 | |||||||||||
| 31 | my $outlet = Power::Outlet->new(type=>"Virtual", id=>1); | ||||||||||
| 32 | my $outlet = Power::Outlet::Virtual->new; | ||||||||||
| 33 | |||||||||||
| 34 | =head1 PROPERTIES | ||||||||||
| 35 | |||||||||||
| 36 | =head2 id | ||||||||||
| 37 | |||||||||||
| 38 | Sets and returns the outlet unique id. | ||||||||||
| 39 | |||||||||||
| 40 | Default: 1 | ||||||||||
| 41 | |||||||||||
| 42 | =cut | ||||||||||
| 43 | |||||||||||
| 44 | 115 | ▶ | sub id { | ||||||||
|
Subroutine
id: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||
| 45 | 115 | my $self = shift; | |||||||||
| 46 | 115 | ▶ | $self->{"id"} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 115 | ▶ | $self->{"id"} = $self->_id_default unless defined $self->{"id"}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 115 | return $self->{"id"}; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | sub _id_default {1}; | ||||||||
|
Subroutine
_id_default: not called CC=1 SCAR=6.9
| |||||||||||
| 52 | |||||||||||
| 53 | =head1 METHODS | ||||||||||
| 54 | |||||||||||
| 55 | =cut | ||||||||||
| 56 | |||||||||||
| 57 | 115 | ▶ | sub _folder { | ||||||||
|
Subroutine
_folder: called CC=4 SCAR=13.9
| |||||||||||
| 58 | 115 | my $self = shift; | |||||||||
| 59 | 115 | ▶ | $self->{'_folder'} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 115 | ▶ | $self->{'_folder'} = File::Spec->tmpdir() unless defined $self->{'_folder'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 115 | ▶ | die(sprintf('Error: Directory "%s" is not writable', $self->{'_folder'})) unless -w $self->{'_folder'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 114 | return $self->{'_folder'}; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 110 | ▶ | sub _file { | ||||||||
|
Subroutine
_file: called CC=1 SCAR=0.0
| |||||||||||
| 66 | 110 | my $self = shift; | |||||||||
| 67 | 110 | return Path::Class::file($self->_folder, sprintf("power-outlet.%s.outlet", $self->id)); | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | =head2 query | ||||||||||
| 71 | |||||||||||
| 72 | Returns current state of the virtual outlet | ||||||||||
| 73 | |||||||||||
| 74 | =cut | ||||||||||
| 75 | |||||||||||
| 76 | 85 | ▶ | sub query { | ||||||||
|
Subroutine
query: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 77 | 85 | my $self = shift; | |||||||||
| 78 | 85 | ▶ | if (defined wantarray) { #scalar and list context | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 80 | my $file = $self->_file; | |||||||||
| 80 | 80 | ▶ | return -f $file ? $file->slurp(chomp=>1) : 'OFF'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | } else { #void context | ||||||||||
| 82 | 5 | return; | |||||||||
| 83 | } | ||||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | =head2 on | ||||||||||
| 87 | |||||||||||
| 88 | Sends a TCP/IP message to the iBoot device to Turn Power ON | ||||||||||
| 89 | |||||||||||
| 90 | =cut | ||||||||||
| 91 | |||||||||||
| 92 | 15 | ▶ | sub on { | ||||||||
|
Subroutine
on: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 93 | 15 | my $self = shift; | |||||||||
| 94 | 15 | $self->_file->spew("ON$/"); | |||||||||
| 95 | 15 | return $self->query; | |||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | =head2 off | ||||||||||
| 99 | |||||||||||
| 100 | Sends a TCP/IP message to the iBoot device to Turn Power OFF | ||||||||||
| 101 | |||||||||||
| 102 | =cut | ||||||||||
| 103 | |||||||||||
| 104 | 15 | ▶ | sub off { | ||||||||
|
Subroutine
off: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 105 | 15 | my $self = shift; | |||||||||
| 106 | 15 | $self->_file->spew("OFF$/"); | |||||||||
| 107 | 15 | return $self->query; | |||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | =head2 switch | ||||||||||
| 111 | |||||||||||
| 112 | Queries the device for the current status and then requests the opposite. | ||||||||||
| 113 | |||||||||||
| 114 | =cut | ||||||||||
| 115 | |||||||||||
| 116 | #see Power::Outlet::Common->switch | ||||||||||
| 117 | |||||||||||
| 118 | =head2 cycle | ||||||||||
| 119 | |||||||||||
| 120 | Cycle Power (ON-OFF-ON or OFF-ON-OFF). | ||||||||||
| 121 | |||||||||||
| 122 | =cut | ||||||||||
| 123 | |||||||||||
| 124 | #see Power::Outlet::Common->cycle | ||||||||||
| 125 | |||||||||||
| 126 | =head1 BUGS | ||||||||||
| 127 | |||||||||||
| 128 | Please log on RT and send an email to the author. | ||||||||||
| 129 | |||||||||||
| 130 | =head1 SUPPORT | ||||||||||
| 131 | |||||||||||
| 132 | DavisNetworks.com supports all Perl applications including this package. | ||||||||||
| 133 | |||||||||||
| 134 | =head1 AUTHOR | ||||||||||
| 135 | |||||||||||
| 136 | Michael R. Davis | ||||||||||
| 137 | CPAN ID: MRDVT | ||||||||||
| 138 | DavisNetworks.com | ||||||||||
| 139 | |||||||||||
| 140 | =head1 COPYRIGHT | ||||||||||
| 141 | |||||||||||
| 142 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||
| 143 | |||||||||||
| 144 | The full text of the license can be found in the LICENSE file included with this module. | ||||||||||
| 145 | |||||||||||
| 146 | =head1 SEE ALSO | ||||||||||
| 147 | |||||||||||
| 148 | =cut | ||||||||||
| 149 | |||||||||||
| 150 | 2 | 1; | |||||||||