File Coverage

blib/lib/PITA/XML/Platform.pm
Criterion Covered Total %
statement 38 38 100.0
branch 8 8 100.0
condition n/a
subroutine 13 13 100.0
pod 0 6 0.0
total 59 65 90.7


line stmt bran cond sub pod time code
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 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
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 is still in flux, the methods
36             will be documented once we stop changing them daily :)
37              
38             =cut
39              
40 10     10   186 use 5.005;
  10         30  
  10         353  
41 10     10   52 use strict;
  10         13  
  10         270  
42 10     10   47 use Carp ();
  10         19  
  10         189  
43 10     10   58 use Params::Util qw{ _STRING _HASH };
  10         17  
  10         563  
44              
45 10     10   51 use vars qw{$VERSION};
  10         16  
  10         450  
46             BEGIN {
47 10     10   3931 $VERSION = '0.52';
48             }
49              
50              
51              
52              
53              
54             #####################################################################
55             # Constructor and Accessors
56              
57             sub new {
58 34     34 0 100063 my $class = shift;
59 34         154 my $self = bless { @_ }, $class;
60              
61             # Check the object
62 34         84 $self->_init;
63              
64 4         17 $self;
65             }
66              
67             sub autodetect_perl5 {
68 2     2 0 437 my $class = shift;
69              
70             # Source the information
71 2         5 my $path = $^X;
72 2         15 require Config;
73              
74             # Hand it off to the constructor
75 2         1817 $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 36     36   41 my $self = shift;
86              
87             # Check the platform scheme
88 36 100       82 unless ( PITA::XML->_SCHEME($self->scheme) ) {
89 25         3066 Carp::croak('Invalid or missing platform testing scheme');
90             }
91              
92             # Check the path we used
93 11 100       35 unless ( _STRING($self->path) ) {
94 1         166 Carp::croak('Invalid or missing scheme path');
95             }
96              
97             # Check we have an environment
98 10 100       28 unless ( _HASH($self->env) ) {
99 2         258 Carp::croak('Invalid, missing, or empty environment');
100             }
101              
102             # Check we have a config
103 8 100       26 unless ( _HASH($self->config) ) {
104 2         249 Carp::croak('Invalid, missing, or empty config');
105             }
106              
107 6         15 $self;
108             }
109              
110             sub scheme {
111 56     56 0 1296 $_[0]->{scheme};
112             }
113              
114             sub path {
115 16     16 0 120 $_[0]->{path};
116             }
117              
118             sub env {
119 13     13 0 64 $_[0]->{env};
120             }
121              
122             sub config {
123 11     11 0 55 $_[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
135              
136             For other issues, contact the author.
137              
138             =head1 AUTHOR
139              
140             Adam Kennedy Eadamk@cpan.orgE, L
141              
142             =head1 SEE ALSO
143              
144             L
145              
146             The Perl Image-based Testing Architecture (L)
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