804b35a9ac8ca1db6f6fccb86bc8a0d2d4250e2e
[clearscm.git] / lib / Machines.pm
1 =pod
2
3 =head1 NAME $RCSfile: Machines.pm,v $
4
5 Abstraction of machines.
6
7 =head1 VERSION
8
9 =over
10
11 =item Author
12
13 Andrew DeFaria <Andrew@ClearSCM.com>
14
15 =item Revision
16
17 $Revision: 1.4 $
18
19 =item Created
20
21 Tue Jan  8 17:24:16 MST 2008
22
23 =item Modified
24
25 $Date: 2011/11/16 19:46:13 $
26
27 =back
28
29 =head1 SYNOPSIS
30
31 This module handles the details of providing information about
32 machines while obscuring the mechanism for storing such information.
33
34  my $machines = Machines->new;
35
36  foreach ($machine->all) {
37    my %machine = %{$_};
38    display "Machine: $machine{name}";
39    disp.ay "Owner: $machine{owner}"
40  } # if
41
42 =head1 DESCRIPTION
43
44 This module provides information about machines
45
46 =head1 ROUTINES
47
48 The following routines are exported:
49
50 =cut
51
52 package Machines;
53
54 use strict;
55 use warnings;
56
57 use Display;
58 use Utils;
59
60 use base 'Exporter';
61
62 our @EXPORT = qw (
63   all
64   new
65 );
66
67 sub new {
68   my ($class, %parms) = @_;
69
70 =pod
71
72 =head2 new (<parms>)
73
74 Construct a new Machines object. The following OO style arguments are
75 supported:
76
77 Parameters:
78
79 =for html <blockquote>
80
81 =over
82
83 =item file:
84
85 Name of an alternate file from which to read machine information. This
86 is intended as a quick alternative.
87
88 =back
89
90 =for html </blockquote>
91
92 Returns:
93
94 =for html <blockquote>
95
96 =over
97
98 =item Machines object
99
100 =back
101
102 =for html </blockquote>
103
104 =cut
105
106   my $file = $parms{file} ? $parms{file} : "$FindBin::Bin/../etc/machines";
107
108   error "Unable to find $file", 1 if ! -f $file;
109
110   my %machines;
111
112   foreach (ReadFile $file) {
113     my @parts = split;
114
115     # Skip commented out or blank lines
116     next if $parts[0] =~ /^#/ or $parts[0] =~ /^$/;
117
118     $machines{$parts[0]} = $parts[1];
119   } # foreach
120
121   bless {
122     file     => $parms {file},
123     machines => \%machines,
124   }, $class; # bless
125
126   return $class;
127 } # new
128
129 sub all () {
130   my ($self) = @_;
131
132 =pod
133
134 =head3 all ()
135
136 Returns all known machines as an array of hashes
137
138 Parameters:
139
140 =for html <blockquote>
141
142 =over
143
144 =item none
145
146 =back
147
148 =for html </blockquote>
149
150 Returns:
151
152 =begin html
153
154 <blockquote>
155
156 =end html
157
158 =over
159
160 =item Array of machine hash records
161
162 =back
163
164 =for html </blockquote>
165
166 =cut
167
168   return %{$self->{machines}};
169 } # display
170
171 1;
172
173 =pod
174
175 =head1 CONFIGURATION AND ENVIRONMENT
176
177 MACHINES: If set then points to a flat file containing machine
178 names. Note this is providied as a way to quickly use an alternate
179 "machine database". As such only minimal information is support.
180
181 =head1 DEPENDENCIES
182
183  Display
184  Rexec
185
186 =head1 INCOMPATABILITIES
187
188 None yet...
189
190 =head1 BUGS AND LIMITATIONS
191
192 There are no known bugs in this module.
193
194 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
195
196 =head1 LICENSE AND COPYRIGHT
197
198 This Perl Module is freely available; you can redistribute it and/or
199 modify it under the terms of the GNU General Public License as
200 published by the Free Software Foundation; either version 2 of the
201 License, or (at your option) any later version.
202
203 This Perl Module is distributed in the hope that it will be useful,
204 but WITHOUT ANY WARRANTY; without even the implied warranty of
205 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
206 General Public License (L<http://www.gnu.org/copyleft/gpl.html>) for more
207 details.
208
209 You should have received a copy of the GNU General Public License
210 along with this Perl Module; if not, write to the Free Software Foundation,
211 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
212 reserved.
213
214 =cut