line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hardware::UPS::Perl::Utils; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#============================================================================== |
4
|
|
|
|
|
|
|
# package description: |
5
|
|
|
|
|
|
|
#============================================================================== |
6
|
|
|
|
|
|
|
# This package supplies a set of usefull functions used in packages dealing |
7
|
|
|
|
|
|
|
# with an UPS. For a detailed description see the pod documentation |
8
|
|
|
|
|
|
|
# included at the end of this file. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# List of functions: |
11
|
|
|
|
|
|
|
# ------------------ |
12
|
|
|
|
|
|
|
# configure - configures options |
13
|
|
|
|
|
|
|
# error - dealing with errors |
14
|
|
|
|
|
|
|
# warning - dealing with warnings |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
#============================================================================== |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#============================================================================== |
19
|
|
|
|
|
|
|
# Copyright: |
20
|
|
|
|
|
|
|
#============================================================================== |
21
|
|
|
|
|
|
|
# Copyright (c) 2007 Christian Reile, . All |
22
|
|
|
|
|
|
|
# rights reserved. This program is free software; you can redistribute it |
23
|
|
|
|
|
|
|
# and/or modify it under the same terms as Perl itself. |
24
|
|
|
|
|
|
|
#============================================================================== |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
#============================================================================== |
27
|
|
|
|
|
|
|
# Entries for Revision Control: |
28
|
|
|
|
|
|
|
#============================================================================== |
29
|
|
|
|
|
|
|
# Revision : $Revision: 1.8 $ |
30
|
|
|
|
|
|
|
# Author : $Author: creile $ |
31
|
|
|
|
|
|
|
# Last Modified On: $Date: 2007/04/14 09:37:26 $ |
32
|
|
|
|
|
|
|
# Status : $State: Exp $ |
33
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
34
|
|
|
|
|
|
|
# Modifications : |
35
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
# $Log: Utils.pm,v $ |
38
|
|
|
|
|
|
|
# Revision 1.8 2007/04/14 09:37:26 creile |
39
|
|
|
|
|
|
|
# documentation update. |
40
|
|
|
|
|
|
|
# |
41
|
|
|
|
|
|
|
# Revision 1.7 2007/04/07 15:14:45 creile |
42
|
|
|
|
|
|
|
# adaptations to "best practices" style; |
43
|
|
|
|
|
|
|
# update of documentation. |
44
|
|
|
|
|
|
|
# |
45
|
|
|
|
|
|
|
# Revision 1.6 2007/03/03 21:15:53 creile |
46
|
|
|
|
|
|
|
# typing error removed. |
47
|
|
|
|
|
|
|
# |
48
|
|
|
|
|
|
|
# Revision 1.5 2007/02/05 20:37:31 creile |
49
|
|
|
|
|
|
|
# pod documentation revised. |
50
|
|
|
|
|
|
|
# |
51
|
|
|
|
|
|
|
# Revision 1.4 2007/02/04 14:01:32 creile |
52
|
|
|
|
|
|
|
# bug fix in pod documentation. |
53
|
|
|
|
|
|
|
# |
54
|
|
|
|
|
|
|
# Revision 1.3 2007/02/03 15:36:03 creile |
55
|
|
|
|
|
|
|
# package Hardware::UPS::Perl::General removed, as we |
56
|
|
|
|
|
|
|
# use OO PID files now; |
57
|
|
|
|
|
|
|
# update of pod documentation. |
58
|
|
|
|
|
|
|
# |
59
|
|
|
|
|
|
|
# Revision 1.2 2007/01/28 05:24:05 creile |
60
|
|
|
|
|
|
|
# bug fix concerning pod documentation. |
61
|
|
|
|
|
|
|
# |
62
|
|
|
|
|
|
|
# Revision 1.1 2007/01/28 04:17:41 creile |
63
|
|
|
|
|
|
|
# initial version. |
64
|
|
|
|
|
|
|
# |
65
|
|
|
|
|
|
|
# |
66
|
|
|
|
|
|
|
#============================================================================== |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#============================================================================== |
69
|
|
|
|
|
|
|
# module preamble: |
70
|
|
|
|
|
|
|
#============================================================================== |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
56
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
BEGIN { |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
1
|
|
6
|
use Exporter (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
77
|
1
|
|
|
1
|
|
9
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
191
|
|
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
1
|
|
15
|
$VERSION = sprintf( "%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/ ); |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
19
|
@ISA = qw(Exporter); |
82
|
1
|
|
|
|
|
2
|
@EXPORT = qw(); |
83
|
1
|
|
|
|
|
3
|
@EXPORT_OK = qw( |
84
|
|
|
|
|
|
|
&configure |
85
|
|
|
|
|
|
|
&error |
86
|
|
|
|
|
|
|
&warning |
87
|
|
|
|
|
|
|
); |
88
|
1
|
|
|
|
|
34
|
%EXPORT_TAGS = qw(); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
#============================================================================== |
93
|
|
|
|
|
|
|
# end of module preamble |
94
|
|
|
|
|
|
|
#============================================================================== |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
#============================================================================== |
97
|
|
|
|
|
|
|
# packages required: |
98
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
99
|
|
|
|
|
|
|
# |
100
|
|
|
|
|
|
|
# Carp - warn of errors (from perspective of |
101
|
|
|
|
|
|
|
# caller) |
102
|
|
|
|
|
|
|
# |
103
|
|
|
|
|
|
|
#============================================================================== |
104
|
|
|
|
|
|
|
|
105
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
509
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
#============================================================================== |
108
|
|
|
|
|
|
|
# public functions: |
109
|
|
|
|
|
|
|
#============================================================================== |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub configure { |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# subroutine to configure the connection |
114
|
|
|
|
|
|
|
# |
115
|
|
|
|
|
|
|
# parameters: $actions (input) - anonymous hash; the action table |
116
|
|
|
|
|
|
|
# $arguments (input) - anonymous array; arguments supplied |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# input as hidden local variables |
119
|
0
|
|
|
0
|
1
|
|
my ($actions, $arguments) = @_ ; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# hidden local variables |
122
|
0
|
|
|
|
|
|
my $opt; # current option |
123
|
|
|
|
|
|
|
my $arg; # current argument |
124
|
0
|
|
|
|
|
|
my @return; # return list of of builtin Perl function `grep' |
125
|
0
|
|
|
|
|
|
my @options; # the option list |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# processing options |
128
|
0
|
|
|
|
|
|
@options = keys %{$actions}; |
|
0
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
PROCESS_OPTIONS: |
131
|
0
|
|
|
|
|
|
while (@{$arguments}) { |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
$opt = shift(@{$arguments}); |
|
0
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
@return = grep(/^$opt/, @options); |
135
|
|
|
|
|
|
|
|
136
|
0
|
0
|
|
|
|
|
if (1 != @return) { |
137
|
0
|
|
|
|
|
|
error("unknown or ambiguous option -- $opt"); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
$arg = shift(@{$arguments}); |
|
0
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
$actions->{$return[0]}->($arg); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
} # end of subroutine "configure" |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub error { |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# subroutine to display internal error messages |
149
|
|
|
|
|
|
|
# |
150
|
|
|
|
|
|
|
# parameters: $errorMessage (input) - error message to be displayed |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# input as hidden local variable |
153
|
0
|
|
|
0
|
1
|
|
my $errorMessage = shift; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# hidden local variables |
156
|
0
|
|
|
|
|
|
my $i = 1; # calling level |
157
|
0
|
|
|
|
|
|
my $method = (caller($i))[3]; # calling public method |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# determine calling subroutine |
160
|
|
|
|
|
|
|
METHOD: |
161
|
0
|
|
|
|
|
|
while ($method =~ /::_/) { |
162
|
0
|
|
|
|
|
|
$method = (caller(++$i))[3]; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# displaying error message and die |
166
|
0
|
|
|
|
|
|
croak("$method: $errorMessage"); |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
} # end of subroutine "error" |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub warning { |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
# subroutine to display internal warning messages |
173
|
|
|
|
|
|
|
# |
174
|
|
|
|
|
|
|
# parameters: $warningMessage (input) - warning message to be displayed |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
# input as hidden local variable |
177
|
0
|
|
|
0
|
1
|
|
my $warningMessage = shift; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# hidden local variables |
180
|
0
|
|
|
|
|
|
my $i = 1; # calling level |
181
|
0
|
|
|
|
|
|
my $method = (caller($i))[3]; # calling public method |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# determine calling subroutine |
184
|
|
|
|
|
|
|
METHOD: |
185
|
0
|
|
|
|
|
|
while ($method =~ /::_/) { |
186
|
0
|
|
|
|
|
|
$method = (caller(++$i))[3]; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
# displaying error message and continue |
190
|
0
|
|
|
|
|
|
carp("$method: $warningMessage"); |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
} # end of subroutine "warning" |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
#============================================================================== |
195
|
|
|
|
|
|
|
# package return: |
196
|
|
|
|
|
|
|
#============================================================================== |
197
|
|
|
|
|
|
|
1; |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
__END__ |