PITA/Guest/Storage.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 80 CC 5 SCAR 15.8
CC
5
Cov
0%
platform
12.0
new
6.0
_GUID
6.0
CRAP 4.9
1 package PITA::Guest::Storage;
2  
3 =pod
4  
5 =head1 NAME
6  
7 PITA::Guest::Storage - Guest Storage Engine base class
8  
9 =head1 DESCRIPTION
10  
11 Looking after Guest images is a full time job.
12  
13 And so L<PITA::Guest::Storage> provides a dedicated API for locating,
14 verifying, storing, managing and serving the many gigabytes worth of
15 image data that is typically stored in a Guest image library.
16  
17 =head1 METHODS
18  
19 =cut
20  
21 use 5.008;
22 use strict;
23 use Carp ();
24 use Data::GUID ();
25 use Params::Util ();
26  
27 our $VERSION = '0.60';
28  
29  
30  
31  
32  
33 #####################################################################
34 # Constructor and Accessors
35  
36 =pod
37  
38 =head2 new
39  
40 my $store = My::Storage->new(
41 param1 => 'value1',
42 param2 => 'value2',
43 paramN => 'valueN',
44 );
45  
46 The C<new> constructor (regardless of the subclass) takes a set of
47 key/value params and returns a new B<PITA::Guest::Storage> object.
48  
49 Note the B<PITA::Guest::Storage> class itself cannot be instantiated
50 directly. You can only create objects of subclasses.
51  
52 Returns a new B<PITA::Guest::Storage> object, or throws an exception
53 on error.
54  
55 =cut
56  
57 sub new {
58 my $class = shift;
59 if ( $class eq __PACKAGE__ ) {
60 Carp::croak('Cannot instantiate PITA::Guest::Storage directly');
61 }
62 return bless { @_ }, $class;
63 }
64  
65  
66  
67  
68  
69 #####################################################################
70 # Guest Management
71  
72 =pod
73  
74 =head2 add_guest
75  
76 $store->add_guest( $pita_xml_guest );
77  
78 The C<add_guest> method takes a single L<PITA::XML::Guest> object, does
79 significant testing to validate that the guest object is actually a valid
80 testing guest image, probes it to determine the testing platforms within
81 the guest image, and then adds it to the Guest Storage.
82  
83 As you can imagine, the C<add_guest> method may take some time to run.
84  
85 Returns the modified, fully resolved, version of the L<PITA::XML::Guest>
86 object if the guest is ok and was added, or throws an exception on error.
87  
88 =cut
89  
90 sub add_guest {
91 my $self = shift;
92 my $guest = Params::Util::_INSTANCE(shift, 'PITA::XML::Guest')
93 or Carp::croak('Did not provide a PITA::XML::Guest to add_guest');
94 Carp::croak( ref($self) . ' has not implemented the add_guest method' );
95 }
96  
97 =pod
98  
99 =head2 guest
100  
101 my $guest = $store->guest( $guid );
102  
103 The C<guest> method takes a GUID param, locates and returns the Guest
104 image metadata for the GUID.
105  
106 Returns a L<PITA::XML::Guest> if found, false if the GUID does not exist
107 in the Guest storage, or throws an exception on error.
108  
109 =cut
110  
111 sub guest {
112 my $self = shift;
113 my $guid = _GUID(shift)
114 or Carp::croak('Did not provide a GUID to guest');
115 Carp::croak( ref($self) . ' has not implemented the guest method' );
116 }
117  
118 =pod
119  
120 =head2 guests
121  
122 The C<guests> method returns the Guest image metadata for all of the
123 Guest images in the Guest Storage object.
124  
125 Returns a list of L<PITA::XML::Guest> objects, or throws an exception
126 on error.
127  
128 =cut
129  
130 sub guests {
131 my $self = shift;
132 Carp::croak( ref($self) . ' has not implemented the guests method' );
133 }
134  
135 =pod
136  
137 =head2 platform
138  
139 my $platform = $self->platform( $guid );
140  
141 The C<platform> method locates a single testing L<PITA::XML::Platform>
142 within some guest, within the Guest Storage.
143  
144 Returns a L<PITA::XML::Platform> object, false if the GUID does not exist
145 in the storage, or throws an exception on error.
146  
147 =cut
148  
149 sub platform {
150 my $self = shift;
151 my $id = shift;
152 my @plat = grep { $_->id eq $id } $self->platforms;
153 if ( @plat == 1 ) {
154 return $plat[0];
155 }
156 if ( @plat ) {
157 Carp::croak("Fond more than 1 platform with id $id");
158 }
159 return '';
160 }
161  
162 =pod
163  
164 =head2 platforms
165  
166 The C<platforms> method returns the Testing Platform metadata for all
167 of the platforms in the Guest Storage.
168  
169 Returns a list of L<PITA::XML::Platform> objects, or throws an exception
170 on error.
171  
172 =cut
173  
174 sub platforms {
175 map { $_->platforms } $_[0]->guests;
176 }
177  
178  
179  
180  
181  
182 #####################################################################
183 # Support Methods
184  
185 sub _GUID {
186 my $guid = eval {
187 Data::GUID->from_any_string(shift);
188 };
189 $@ ? undef : $guid;
190 }
191  
192 1;
193  
194 =pod
195  
196 =head1 SUPPORT
197  
198 Bugs should be reported via the CPAN bug tracker at
199  
200 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=PITA>
201  
202 For other issues, contact the author.
203  
204 =head1 AUTHOR
205  
206 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
207  
208 =head1 SEE ALSO
209  
210 L<PITA>, L<http://ali.as/pita/>
211  
212 =head1 COPYRIGHT
213  
214 Copyright 2005 - 2011 Adam Kennedy.
215  
216 This program is free software; you can redistribute
217 it and/or modify it under the same terms as Perl itself.
218  
219 The full text of the license can be found in the
220 LICENSE file included with this module.
221  
222 =cut