File Coverage

blib/lib/PITA/Guest/Storage.pm
Criterion Covered Total %
statement 15 41 36.5
branch 0 12 0.0
condition n/a
subroutine 5 12 41.6
pod 6 6 100.0
total 26 71 36.6


line stmt bran cond sub pod time code
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 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 1     1   2578 use 5.008;
  1         5  
  1         55  
22 1     1   7 use strict;
  1         2  
  1         44  
23 1     1   6 use Carp ();
  1         3  
  1         46  
24 1     1   6 use Data::GUID ();
  1         4  
  1         26  
25 1     1   6 use Params::Util ();
  1         3  
  1         620  
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 constructor (regardless of the subclass) takes a set of
47             key/value params and returns a new B object.
48              
49             Note the B class itself cannot be instantiated
50             directly. You can only create objects of subclasses.
51              
52             Returns a new B object, or throws an exception
53             on error.
54              
55             =cut
56              
57             sub new {
58 0     0 1   my $class = shift;
59 0 0         if ( $class eq __PACKAGE__ ) {
60 0           Carp::croak('Cannot instantiate PITA::Guest::Storage directly');
61             }
62 0           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 method takes a single L 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 method may take some time to run.
84              
85             Returns the modified, fully resolved, version of the L
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 0     0 1   my $self = shift;
92 0 0         my $guest = Params::Util::_INSTANCE(shift, 'PITA::XML::Guest')
93             or Carp::croak('Did not provide a PITA::XML::Guest to add_guest');
94 0           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 method takes a GUID param, locates and returns the Guest
104             image metadata for the GUID.
105              
106             Returns a L 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 0     0 1   my $self = shift;
113 0 0         my $guid = _GUID(shift)
114             or Carp::croak('Did not provide a GUID to guest');
115 0           Carp::croak( ref($self) . ' has not implemented the guest method' );
116             }
117              
118             =pod
119              
120             =head2 guests
121              
122             The C 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 objects, or throws an exception
126             on error.
127              
128             =cut
129              
130             sub guests {
131 0     0 1   my $self = shift;
132 0           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 method locates a single testing L
142             within some guest, within the Guest Storage.
143              
144             Returns a L 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 0     0 1   my $self = shift;
151 0           my $id = shift;
152 0           my @plat = grep { $_->id eq $id } $self->platforms;
  0            
153 0 0         if ( @plat == 1 ) {
154 0           return $plat[0];
155             }
156 0 0         if ( @plat ) {
157 0           Carp::croak("Fond more than 1 platform with id $id");
158             }
159 0           return '';
160             }
161              
162             =pod
163              
164             =head2 platforms
165              
166             The C method returns the Testing Platform metadata for all
167             of the platforms in the Guest Storage.
168              
169             Returns a list of L objects, or throws an exception
170             on error.
171              
172             =cut
173              
174             sub platforms {
175 0     0 1   map { $_->platforms } $_[0]->guests;
  0            
176             }
177              
178              
179              
180              
181              
182             #####################################################################
183             # Support Methods
184              
185             sub _GUID {
186 0     0     my $guid = eval {
187 0           Data::GUID->from_any_string(shift);
188             };
189 0 0         $@ ? 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
201              
202             For other issues, contact the author.
203              
204             =head1 AUTHOR
205              
206             Adam Kennedy Eadamk@cpan.orgE
207              
208             =head1 SEE ALSO
209              
210             L, L
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