line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Power::Outlet::Virtual; |
2
|
2
|
|
|
2
|
|
103637
|
use strict; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
58
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
48
|
|
4
|
2
|
|
|
2
|
|
10
|
use File::Spec qw{}; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
50
|
|
5
|
2
|
|
|
2
|
|
429
|
use Path::Class qw{}; |
|
2
|
|
|
|
|
39834
|
|
|
2
|
|
|
|
|
44
|
|
6
|
2
|
|
|
2
|
|
13
|
use base qw{Power::Outlet::Common}; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
909
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.50'; |
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
|
|
|
|
|
|
|
sub id { |
45
|
115
|
|
|
115
|
1
|
9241
|
my $self = shift; |
46
|
115
|
50
|
|
|
|
324
|
$self->{"id"} = shift if @_; |
47
|
115
|
50
|
|
|
|
307
|
$self->{"id"} = $self->_id_default unless defined $self->{"id"}; |
48
|
115
|
|
|
|
|
1000
|
return $self->{"id"}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
0
|
|
0
|
sub _id_default {1}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 METHODS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _folder { |
58
|
115
|
|
|
115
|
|
405
|
my $self = shift; |
59
|
115
|
50
|
|
|
|
354
|
$self->{'_folder'} = shift if @_; |
60
|
115
|
100
|
|
|
|
599
|
$self->{'_folder'} = File::Spec->tmpdir() unless defined $self->{'_folder'}; |
61
|
115
|
100
|
|
|
|
2441
|
die(sprintf('Error: Directory "%s" is not writable', $self->{'_folder'})) unless -w $self->{'_folder'}; |
62
|
114
|
|
|
|
|
729
|
return $self->{'_folder'}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _file { |
66
|
110
|
|
|
110
|
|
187
|
my $self = shift; |
67
|
110
|
|
|
|
|
265
|
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
|
|
|
|
|
|
|
sub query { |
77
|
85
|
|
|
85
|
1
|
37648
|
my $self = shift; |
78
|
85
|
100
|
|
|
|
274
|
if (defined wantarray) { #scalar and list context |
79
|
80
|
|
|
|
|
189
|
my $file = $self->_file; |
80
|
80
|
100
|
|
|
|
9109
|
return -f $file ? $file->slurp(chomp=>1) : 'OFF'; |
81
|
|
|
|
|
|
|
} else { #void context |
82
|
5
|
|
|
|
|
20
|
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
|
|
|
|
|
|
|
sub on { |
93
|
15
|
|
|
15
|
1
|
4722
|
my $self = shift; |
94
|
15
|
|
|
|
|
43
|
$self->_file->spew("ON$/"); |
95
|
15
|
|
|
|
|
6105
|
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
|
|
|
|
|
|
|
sub off { |
105
|
15
|
|
|
15
|
1
|
7008
|
my $self = shift; |
106
|
15
|
|
|
|
|
51
|
$self->_file->spew("OFF$/"); |
107
|
15
|
|
|
|
|
7699
|
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
|
|
|
|
|
|
|
1; |