| 1 | package PITA::XML::Install; | ||
| 2 | |||
| 3 | =pod | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | PITA::XML::Install - A PITA report on a single distribution install | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | C<PITA::XML::Install> is a data object that contains the complete | ||
| 12 | set of information on a single test/install run for a distribution on a | ||
| 13 | single host of an arbitrary platform. | ||
| 14 | |||
| 15 | =cut | ||
| 16 | |||
| 17 | use 5.006; | ||
| 18 | use strict; | ||
| 19 | use Carp (); | ||
| 20 | use Params::Util qw{ _INSTANCE _SET0 }; | ||
| 21 | |||
| 22 | use vars qw{$VERSION}; | ||
| 23 | BEGIN { | ||
| 24 | $VERSION = '0.52'; | ||
| 25 | } | ||
| 26 | |||
| 27 | |||
| 28 | |||
| 29 | |||
| 30 | |||
| 31 | ##################################################################### | ||
| 32 | # Constructor and Accessors | ||
| 33 | |||
| 34 | =pod | ||
| 35 | |||
| 36 | =head2 new | ||
| 37 | |||
| 38 | # Create a new Install object | ||
| 39 | my $install = PITA::XML::Install->new( | ||
| 40 | request => $request | ||
| 41 | platform => $platform, | ||
| 42 | analysis => $analysis, | ||
| 43 | ); | ||
| 44 | |||
| 45 | The C<new> constructor is used to create a new installation report, a | ||
| 46 | collection of which are serialized to the L<PITA::XML> XML file. | ||
| 47 | |||
| 48 | Returns a new C<PITA::XML::Install> object, or dies on error. | ||
| 49 | |||
| 50 | =cut | ||
| 51 | |||
| 52 | sub new { | ||
| 53 | my $class = shift; | ||
| 54 | my $self = bless { @_ }, $class; | ||
| 55 | |||
| 56 | # Check the object | ||
| 57 | $self->_init; | ||
| 58 | |||
| 59 | $self; | ||
| 60 | } | ||
| 61 | |||
| 62 | sub _init { | ||
| 63 | my $self = shift; | ||
| 64 | |||
| 65 | # We must have a platform spec | ||
| 66 | unless ( _INSTANCE($self->platform, 'PITA::XML::Platform') ) { | ||
| 67 | Carp::croak('Invalid or missing platform'); | ||
| 68 | } | ||
| 69 | |||
| 70 | # We must have a testing request | ||
| 71 | unless ( _INSTANCE($self->request, 'PITA::XML::Request') ) { | ||
| 72 | Carp::croak('Invalid or missing request'); | ||
| 73 | } | ||
| 74 | |||
| 75 | # The platform scheme should match the platform scheme | ||
| 76 | # (ignoring any part after the dot in the request) | ||
| 77 | my $scheme_regexp = '^' . quotemeta($self->platform->scheme) . '\\b'; | ||
| 78 | unless ( $self->request->scheme =~ /$scheme_regexp/ ) { | ||
| 79 | Carp::croak('Platform scheme does not match request scheme'); | ||
| 80 | } | ||
| 81 | |||
| 82 | # Zero or more commands | ||
| 83 | $self->{commands} ||= []; | ||
| 84 | unless ( _SET0( $self->{commands}, 'PITA::XML::Command') ) { | ||
| 85 | Carp::croak('Invalid commands'); | ||
| 86 | } | ||
| 87 | |||
| 88 | # Zero or more tests | ||
| 89 | $self->{tests} ||= []; | ||
| 90 | unless ( _SET0( $self->{tests}, 'PITA::XML::Test') ) { | ||
| 91 | Carp::croak('Invalid tests'); | ||
| 92 | } | ||
| 93 | |||
| 94 | # Analysis is optional | ||
| 95 | if ( defined $self->analysis or exists $self->{analysis} ) { | ||
| 96 | unless ( _INSTANCE($self->analysis, 'PITA::XML::Analysis') ) { | ||
| 97 | Carp::croak('Invalid analysis object'); | ||
| 98 | } | ||
| 99 | } else { | ||
| 100 | $self->{analysis} = undef; | ||
| 101 | } | ||
| 102 | |||
| 103 | $self; | ||
| 104 | } | ||
| 105 | |||
| 106 | |||
| 107 | |||
| 108 | |||
| 109 | |||
| 110 | ##################################################################### | ||
| 111 | # Main Methods | ||
| 112 | |||
| 113 | =pod | ||
| 114 | |||
| 115 | =head2 request | ||
| 116 | |||
| 117 | The C<request> accessor returns testing request information. | ||
| 118 | |||
| 119 | Returns a L<PITA::XML::Distribution> object. | ||
| 120 | |||
| 121 | =cut | ||
| 122 | |||
| 123 | sub request { | ||
| 124 | $_[0]->{request}; | ||
| 125 | } | ||
| 126 | |||
| 127 | =pod | ||
| 128 | |||
| 129 | =head2 platform | ||
| 130 | |||
| 131 | The C<platform> accessor returns the platform specification for the install. | ||
| 132 | |||
| 133 | Returns a L<PITA::XML::Platform> object. | ||
| 134 | |||
| 135 | =cut | ||
| 136 | |||
| 137 | sub platform { | ||
| 138 | $_[0]->{platform}; | ||
| 139 | } | ||
| 140 | |||
| 141 | =pod | ||
| 142 | |||
| 143 | =head2 add_command | ||
| 144 | |||
| 145 | $install->add_command( $command ); | ||
| 146 | |||
| 147 | The C<add_command> method adds a L<PITA::XML::Command> object to the | ||
| 148 | list of commands in the install object. | ||
| 149 | |||
| 150 | Returns true, or dies is you do not pass a L<PITA::XML::Command> object. | ||
| 151 | |||
| 152 | =cut | ||
| 153 | |||
| 154 | sub add_command { | ||
| 155 | my $self = shift; | ||
| 156 | my $command = _INSTANCE(shift, 'PITA::XML::Command') | ||
| 157 | or Carp::croak("Did not provide a PITA::XML::Command to add_command"); | ||
| 158 | push @{ $self->{commands} }, $command; | ||
| 159 | 1; | ||
| 160 | } | ||
| 161 | |||
| 162 | =pod | ||
| 163 | |||
| 164 | =head2 commands | ||
| 165 | |||
| 166 | The C<commands> accessor returns the commands executed during the testing. | ||
| 167 | |||
| 168 | Returns a list of zero or more L<PITA::XML::Command> objects. | ||
| 169 | |||
| 170 | =cut | ||
| 171 | |||
| 172 | sub commands { | ||
| 173 | @{ $_[0]->{commands} }; | ||
| 174 | } | ||
| 175 | |||
| 176 | =pod | ||
| 177 | |||
| 178 | =head2 add_test | ||
| 179 | |||
| 180 | $install->add_test( $test ); | ||
| 181 | |||
| 182 | The C<add_test> method adds a L<PITA::XML::Test> object to the | ||
| 183 | list of test results in the install object. | ||
| 184 | |||
| 185 | Returns true, or dies is you do not pass a L<PITA::XML::Test> object. | ||
| 186 | |||
| 187 | =cut | ||
| 188 | |||
| 189 | sub add_test { | ||
| 190 | my $self = shift; | ||
| 191 | my $test = _INSTANCE(shift, 'PITA::XML::Test') | ||
| 192 | or Carp::croak("Did not provide a PITA::XML::Test to add_test"); | ||
| 193 | push @{ $self->{tests} }, $test; | ||
| 194 | 1; | ||
| 195 | } | ||
| 196 | |||
| 197 | =pod | ||
| 198 | |||
| 199 | =head2 tests | ||
| 200 | |||
| 201 | The C<tests> accessor returns the results of the individual tests run during the testing. | ||
| 202 | |||
| 203 | Returns a list of zero or more L<PITA::XML::Test> objects. | ||
| 204 | |||
| 205 | =cut | ||
| 206 | |||
| 207 | sub tests { | ||
| 208 | @{ $_[0]->{tests} }; | ||
| 209 | } | ||
| 210 | |||
| 211 | =pod | ||
| 212 | |||
| 213 | =head2 analysis | ||
| 214 | |||
| 215 | The C<analysis> accessor returns the analysis object for the test run. | ||
| 216 | |||
| 217 | Returns a L<PITA::XML::Analysis> object, or C<undef> if no analysis | ||
| 218 | performed during the testing. | ||
| 219 | |||
| 220 | =cut | ||
| 221 | |||
| 222 | sub analysis { | ||
| 223 | $_[0]->{analysis}; | ||
| 224 | } | ||
| 225 | |||
| 226 | 1; | ||
| 227 | |||
| 228 | =pod | ||
| 229 | |||
| 230 | =head1 SUPPORT | ||
| 231 | |||
| 232 | Bugs should be reported via the CPAN bug tracker at | ||
| 233 | |||
| 234 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=PITA-XML> | ||
| 235 | |||
| 236 | For other issues, contact the author. | ||
| 237 | |||
| 238 | =head1 AUTHOR | ||
| 239 | |||
| 240 | Adam Kennedy E<lt>adamk@cpan.orgE<gt>, L<http://ali.as/> | ||
| 241 | |||
| 242 | =head1 SEE ALSO | ||
| 243 | |||
| 244 | L<PITA::XML> | ||
| 245 | |||
| 246 | The Perl Image-based Testing Architecture (L<http://ali.as/pita/>) | ||
| 247 | |||
| 248 | =head1 COPYRIGHT | ||
| 249 | |||
| 250 | Copyright 2005 - 2013 Adam Kennedy. | ||
| 251 | |||
| 252 | This program is free software; you can redistribute | ||
| 253 | it and/or modify it under the same terms as Perl itself. | ||
| 254 | |||
| 255 | The full text of the license can be found in the | ||
| 256 | LICENSE file included with this module. | ||
| 257 | |||
| 258 | =cut |