| 1 | package PITA::XML::Request; | ||
| 2 | |||
| 3 | =pod | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | PITA::XML::Request - A request for the testing of a software package | ||
| 8 | |||
| 9 | =head1 SYNOPSIS | ||
| 10 | |||
| 11 | # Create a request specification | ||
| 12 | my $dist = PITA::XML::Request->new( | ||
| 13 | scheme => 'perl5', | ||
| 14 | distname => 'PITA-XML', | ||
| 15 | |||
| 16 | # The package to test | ||
| 17 | file => PITA::XML::File->new( | ||
| 18 | filename => 'Foo-Bar-0.01.tar.gz', | ||
| 19 | digest => 'MD5.0123456789ABCDEF0123456789ABCDEF', | ||
| 20 | ), | ||
| 21 | |||
| 22 | # Optional fields for repository-based requests | ||
| 23 | authority => 'cpan', | ||
| 24 | authpath => '/id/A/AD/ADAMK/Foo-Bar-0.01.tar.gz', | ||
| 25 | ); | ||
| 26 | |||
| 27 | =head1 DESCRIPTION | ||
| 28 | |||
| 29 | C<PITA::XML::Request> is an object for holding information about | ||
| 30 | a request for a distribution to be tested. It is created most often | ||
| 31 | as part of the parsing of a L<PITA::XML> XML file. | ||
| 32 | |||
| 33 | It holds the testing scheme, name of the distribition, file information, | ||
| 34 | and authority information (if the distribution was sourced from a | ||
| 35 | repository such as CPAN) | ||
| 36 | |||
| 37 | =head1 METHODS | ||
| 38 | |||
| 39 | =cut | ||
| 40 | |||
| 41 | use 5.006; | ||
| 42 | use strict; | ||
| 43 | use Carp (); | ||
| 44 | use File::Spec (); | ||
| 45 | use File::Basename (); | ||
| 46 | use Config::Tiny (); | ||
| 47 | use Params::Util qw{ _INSTANCE _STRING }; | ||
| 48 | use PITA::XML::Storable (); | ||
| 49 | |||
| 50 | use vars qw{$VERSION @ISA}; | ||
| 51 | BEGIN { | ||
| 52 | $VERSION = '0.52'; | ||
| 53 | @ISA = 'PITA::XML::Storable'; | ||
| 54 | } | ||
| 55 | |||
| 56 | sub xml_entity { 'request' } | ||
| 57 | |||
| 58 | |||
| 59 | |||
| 60 | |||
| 61 | |||
| 62 | ##################################################################### | ||
| 63 | # Constructor and Accessors | ||
| 64 | |||
| 65 | sub new { | ||
| 66 | my $class = shift; | ||
| 67 | my $self = bless { @_ }, $class; | ||
| 68 | |||
| 69 | # Check the object | ||
| 70 | $self->_init; | ||
| 71 | |||
| 72 | $self; | ||
| 73 | } | ||
| 74 | |||
| 75 | # Format-check the parameters | ||
| 76 | sub _init { | ||
| 77 | my $self = shift; | ||
| 78 | |||
| 79 | # Check the id, if it has one | ||
| 80 | if ( defined $self->id ) { | ||
| 81 | unless ( PITA::XML->_GUID($self->id) ) { | ||
| 82 | Carp::croak('Invalid id value format'); | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | # Check the scheme | ||
| 87 | unless ( PITA::XML->_SCHEME($self->scheme) ) { | ||
| 88 | Carp::croak('Missing, invalid or unsupported scheme'); | ||
| 89 | } | ||
| 90 | |||
| 91 | # Arbitrarily apply the normal standard for distributions | ||
| 92 | ### Might need to change this down the line | ||
| 93 | unless ( PITA::XML->_DISTNAME($self->distname) ) { | ||
| 94 | Carp::croak('Missing or invalid distname'); | ||
| 95 | } | ||
| 96 | |||
| 97 | # Check the (required) file | ||
| 98 | unless ( _INSTANCE($self->file, 'PITA::XML::File') ) { | ||
| 99 | Carp::croak('Missing or invalid file'); | ||
| 100 | } | ||
| 101 | |||
| 102 | # Is there an authority | ||
| 103 | if ( $self->authority ) { | ||
| 104 | # Check the authority | ||
| 105 | unless ( _STRING($self->authority) ) { | ||
| 106 | Carp::croak('Invalid authority'); | ||
| 107 | } | ||
| 108 | } else { | ||
| 109 | $self->{authority} = ''; | ||
| 110 | } | ||
| 111 | |||
| 112 | # Check the cpanpath | ||
| 113 | if ( $self->authpath ) { | ||
| 114 | # Check the authpath | ||
| 115 | unless ( _STRING($self->authpath) ) { | ||
| 116 | Carp::croak('Invalid authpath'); | ||
| 117 | } | ||
| 118 | } else { | ||
| 119 | $self->{authpath} = ''; | ||
| 120 | } | ||
| 121 | |||
| 122 | # Authpath and authority are needed together | ||
| 123 | if ( $self->authpath and ! $self->authority ) { | ||
| 124 | Carp::croak('No authority provided with authpath'); | ||
| 125 | } | ||
| 126 | # Authpath and authority are needed together | ||
| 127 | if ( $self->authority and ! $self->authpath ) { | ||
| 128 | Carp::croak('No authpath provided with authority'); | ||
| 129 | } | ||
| 130 | |||
| 131 | $self; | ||
| 132 | } | ||
| 133 | |||
| 134 | =pod | ||
| 135 | |||
| 136 | =head2 id | ||
| 137 | |||
| 138 | The C<id> accessor returns the unique identifier of the request, if | ||
| 139 | it has one. This should be some form of L<Data::UUID> string. | ||
| 140 | |||
| 141 | Returns the identifier as a string, or C<undef> if the request has not | ||
| 142 | been assigned an id. | ||
| 143 | |||
| 144 | =cut | ||
| 145 | |||
| 146 | sub id { $_[0]->{id} } | ||
| 147 | |||
| 148 | =pod | ||
| 149 | |||
| 150 | =head2 scheme | ||
| 151 | |||
| 152 | The C<scheme> accessor returns the name of the testing scheme that the | ||
| 153 | distribution is to be tested under. | ||
| 154 | |||
| 155 | In this initial implementation, the following schemes are supported. | ||
| 156 | |||
| 157 | =over 4 | ||
| 158 | |||
| 159 | =item perl5 | ||
| 160 | |||
| 161 | Perl 5 general testing scheme. | ||
| 162 | |||
| 163 | Auto-detect the specific sub-scheme (currently either C<perl5.makefile> | ||
| 164 | or C<perl5.build>) | ||
| 165 | |||
| 166 | =item perl5.make | ||
| 167 | |||
| 168 | Traditional Perl 5 testing scheme. | ||
| 169 | |||
| 170 | Executes C<perl Makefile.PL>, C<make>, C<make test>, | ||
| 171 | C<make install>. | ||
| 172 | |||
| 173 | =item perl5.build | ||
| 174 | |||
| 175 | L<Module::Build> Perl 5 testing scheme. | ||
| 176 | |||
| 177 | Executes C<perl Build.PL>, C<Build>, C<Build test>, | ||
| 178 | C<Build install>. | ||
| 179 | |||
| 180 | =item perl6 | ||
| 181 | |||
| 182 | Perl 6 general testing scheme. | ||
| 183 | |||
| 184 | Specifics are yet to be determined. | ||
| 185 | |||
| 186 | =back | ||
| 187 | |||
| 188 | =cut | ||
| 189 | |||
| 190 | sub scheme { | ||
| 191 | $_[0]->{scheme}; | ||
| 192 | } | ||
| 193 | |||
| 194 | =pod | ||
| 195 | |||
| 196 | =head2 distname | ||
| 197 | |||
| 198 | The C<distname> accessor returns the name of the request as a string. | ||
| 199 | |||
| 200 | Most often, this would be something like 'Foo-Bar' with a primary focus on | ||
| 201 | the class Foo::Bar. | ||
| 202 | |||
| 203 | =cut | ||
| 204 | |||
| 205 | sub distname { | ||
| 206 | $_[0]->{distname}; | ||
| 207 | } | ||
| 208 | |||
| 209 | =pod | ||
| 210 | |||
| 211 | =head2 file | ||
| 212 | |||
| 213 | The C<file> accessor returns the L<PITA::XML::File> that contains the | ||
| 214 | package to test. | ||
| 215 | |||
| 216 | =cut | ||
| 217 | |||
| 218 | sub file { | ||
| 219 | $_[0]->{file}; | ||
| 220 | } | ||
| 221 | |||
| 222 | =pod | ||
| 223 | |||
| 224 | =head2 authority | ||
| 225 | |||
| 226 | If present, the C<authority> accessor returns the name of the package | ||
| 227 | authority. For example, CPAN distributions use the authority C<'cpan'>. | ||
| 228 | |||
| 229 | =cut | ||
| 230 | |||
| 231 | sub authority { | ||
| 232 | $_[0]->{authority}; | ||
| 233 | } | ||
| 234 | |||
| 235 | =pod | ||
| 236 | |||
| 237 | =head2 authpath | ||
| 238 | |||
| 239 | When testing distributions , the C<authpath> returns the path for | ||
| 240 | the Request file within the CPAN. | ||
| 241 | |||
| 242 | For non-CPAN distributions, returns false (the null string). | ||
| 243 | |||
| 244 | =cut | ||
| 245 | |||
| 246 | sub authpath { | ||
| 247 | $_[0]->{authpath}; | ||
| 248 | } | ||
| 249 | |||
| 250 | =pod | ||
| 251 | |||
| 252 | =head2 find_file $base | ||
| 253 | |||
| 254 | The C<find_file> method takes a file or directory as a param (which | ||
| 255 | must exist) and tries to locate the actual file on disk at a location | ||
| 256 | within or relative to the passed path. | ||
| 257 | |||
| 258 | Returns the merge path to the file (if it exists) or C<undef> if not. | ||
| 259 | |||
| 260 | =cut | ||
| 261 | |||
| 262 | sub find_file { | ||
| 263 | my $self = shift; | ||
| 264 | my $path = shift; | ||
| 265 | if ( -f $path ) { | ||
| 266 | $path = File::Basename::dirname($path); | ||
| 267 | } | ||
| 268 | unless ( -d $path ) { | ||
| 269 | Carp::croak("Invalid or non-existant base path"); | ||
| 270 | } | ||
| 271 | |||
| 272 | # Add the filename to the base dir | ||
| 273 | my $file = File::Spec->catfile( $path, $self->file->filename ); | ||
| 274 | return -f $file ? $file : undef; | ||
| 275 | } | ||
| 276 | |||
| 277 | 1; | ||
| 278 | |||
| 279 | =pod | ||
| 280 | |||
| 281 | =head1 SUPPORT | ||
| 282 | |||
| 283 | Bugs should be reported via the CPAN bug tracker at | ||
| 284 | |||
| 285 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=PITA-XML> | ||
| 286 | |||
| 287 | For other issues, contact the author. | ||
| 288 | |||
| 289 | =head1 AUTHOR | ||
| 290 | |||
| 291 | Adam Kennedy E<lt>adamk@cpan.orgE<gt>, L<http://ali.as/> | ||
| 292 | |||
| 293 | =head1 SEE ALSO | ||
| 294 | |||
| 295 | L<PITA::XML> | ||
| 296 | |||
| 297 | The Perl Image-based Testing Architecture (L<http://ali.as/pita/>) | ||
| 298 | |||
| 299 | =head1 COPYRIGHT | ||
| 300 | |||
| 301 | Copyright 2005 - 2013 Adam Kennedy. | ||
| 302 | |||
| 303 | This program is free software; you can redistribute | ||
| 304 | it and/or modify it under the same terms as Perl itself. | ||
| 305 | |||
| 306 | The full text of the license can be found in the | ||
| 307 | LICENSE file included with this module. | ||
| 308 | |||
| 309 | =cut |