| 1 | package PITA::XML::Platform; | ||
| 2 | |||
| 3 | =pod | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | PITA::XML::Platform - Data object representing a platform configuration | ||
| 8 | |||
| 9 | =head1 SYNOPSIS | ||
| 10 | |||
| 11 | # Create a platform configuration | ||
| 12 | my $platform = PITA::XML::Platform->new( | ||
| 13 | scheme => 'perl5', | ||
| 14 | path => '/usr/bin/perl', | ||
| 15 | env => \%ENV, | ||
| 16 | config => \%Config::Config, | ||
| 17 | ); | ||
| 18 | |||
| 19 | # Get the current perl5 platform configuration | ||
| 20 | my $current = PITA::XML::Platform->autodetect_perl5; | ||
| 21 | |||
| 22 | =head1 DESCRIPTION | ||
| 23 | |||
| 24 | C<PITA::XML::Platform> is an object for holding information about | ||
| 25 | the platform that a package is being tested on | ||
| 26 | |||
| 27 | It can be created either as part of the parsing of a L<PITA::XML> | ||
| 28 | file, or if you wish you can create one from the local system configuration. | ||
| 29 | |||
| 30 | Primarily it just holds information about the host's environment and the | ||
| 31 | Perl configuration. | ||
| 32 | |||
| 33 | =head1 METHODS | ||
| 34 | |||
| 35 | As the functionality for L<PITA::XML> is still in flux, the methods | ||
| 36 | will be documented once we stop changing them daily :) | ||
| 37 | |||
| 38 | =cut | ||
| 39 | |||
| 40 | use 5.005; | ||
| 41 | use strict; | ||
| 42 | use Carp (); | ||
| 43 | use Params::Util qw{ _STRING _HASH }; | ||
| 44 | |||
| 45 | use vars qw{$VERSION}; | ||
| 46 | BEGIN { | ||
| 47 | $VERSION = '0.52'; | ||
| 48 | } | ||
| 49 | |||
| 50 | |||
| 51 | |||
| 52 | |||
| 53 | |||
| 54 | ##################################################################### | ||
| 55 | # Constructor and Accessors | ||
| 56 | |||
| 57 | sub new { | ||
| 58 | my $class = shift; | ||
| 59 | my $self = bless { @_ }, $class; | ||
| 60 | |||
| 61 | # Check the object | ||
| 62 | $self->_init; | ||
| 63 | |||
| 64 | $self; | ||
| 65 | } | ||
| 66 | |||
| 67 | sub autodetect_perl5 { | ||
| 68 | my $class = shift; | ||
| 69 | |||
| 70 | # Source the information | ||
| 71 | my $path = $^X; | ||
| 72 | require Config; | ||
| 73 | |||
| 74 | # Hand it off to the constructor | ||
| 75 | $class->new( | ||
| 76 | scheme => 'perl5', | ||
| 77 | path => $path, | ||
| 78 | env => { %ENV }, # Only provide a copy | ||
| 79 | config => { %Config::Config }, # Only provide a copy | ||
| 80 | ); | ||
| 81 | } | ||
| 82 | |||
| 83 | # Format-check the parameters | ||
| 84 | sub _init { | ||
| 85 | my $self = shift; | ||
| 86 | |||
| 87 | # Check the platform scheme | ||
| 88 | unless ( PITA::XML->_SCHEME($self->scheme) ) { | ||
| 89 | Carp::croak('Invalid or missing platform testing scheme'); | ||
| 90 | } | ||
| 91 | |||
| 92 | # Check the path we used | ||
| 93 | unless ( _STRING($self->path) ) { | ||
| 94 | Carp::croak('Invalid or missing scheme path'); | ||
| 95 | } | ||
| 96 | |||
| 97 | # Check we have an environment | ||
| 98 | unless ( _HASH($self->env) ) { | ||
| 99 | Carp::croak('Invalid, missing, or empty environment'); | ||
| 100 | } | ||
| 101 | |||
| 102 | # Check we have a config | ||
| 103 | unless ( _HASH($self->config) ) { | ||
| 104 | Carp::croak('Invalid, missing, or empty config'); | ||
| 105 | } | ||
| 106 | |||
| 107 | $self; | ||
| 108 | } | ||
| 109 | |||
| 110 | sub scheme { | ||
| 111 | $_[0]->{scheme}; | ||
| 112 | } | ||
| 113 | |||
| 114 | sub path { | ||
| 115 | $_[0]->{path}; | ||
| 116 | } | ||
| 117 | |||
| 118 | sub env { | ||
| 119 | $_[0]->{env}; | ||
| 120 | } | ||
| 121 | |||
| 122 | sub config { | ||
| 123 | $_[0]->{config}; | ||
| 124 | } | ||
| 125 | |||
| 126 | 1; | ||
| 127 | |||
| 128 | =pod | ||
| 129 | |||
| 130 | =head1 SUPPORT | ||
| 131 | |||
| 132 | Bugs should be reported via the CPAN bug tracker at | ||
| 133 | |||
| 134 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=PITA-XML> | ||
| 135 | |||
| 136 | For other issues, contact the author. | ||
| 137 | |||
| 138 | =head1 AUTHOR | ||
| 139 | |||
| 140 | Adam Kennedy E<lt>adamk@cpan.orgE<gt>, L<http://ali.as/> | ||
| 141 | |||
| 142 | =head1 SEE ALSO | ||
| 143 | |||
| 144 | L<PITA::XML> | ||
| 145 | |||
| 146 | The Perl Image-based Testing Architecture (L<http://ali.as/pita/>) | ||
| 147 | |||
| 148 | =head1 COPYRIGHT | ||
| 149 | |||
| 150 | Copyright 2005 - 2013 Adam Kennedy. | ||
| 151 | |||
| 152 | This program is free software; you can redistribute | ||
| 153 | it and/or modify it under the same terms as Perl itself. | ||
| 154 | |||
| 155 | The full text of the license can be found in the | ||
| 156 | LICENSE file included with this module. | ||
| 157 | |||
| 158 | =cut |