| 1 | package PITA::XML::Command; | ||
| 2 | |||
| 3 | =pod | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | PITA::XML::Command - An executed command, with stored output | ||
| 8 | |||
| 9 | =head1 SYNOPSIS | ||
| 10 | |||
| 11 | # Create a command | ||
| 12 | my $dist = PITA::XML::Request->new( | ||
| 13 | cmd => 'perl Makefile.PL', | ||
| 14 | stdout => \"...", | ||
| 15 | stderr => \"...", | ||
| 16 | ); | ||
| 17 | |||
| 18 | =head1 DESCRIPTION | ||
| 19 | |||
| 20 | C<PITA::XML::Command> is an object for holding information about | ||
| 21 | a command executed during the installation process. | ||
| 22 | |||
| 23 | It holds the actual command, and the STDOUT and STDERR output. | ||
| 24 | |||
| 25 | =head1 METHODS | ||
| 26 | |||
| 27 | =cut | ||
| 28 | |||
| 29 | use 5.006; | ||
| 30 | use strict; | ||
| 31 | use Carp (); | ||
| 32 | use Params::Util qw{ _SCALAR0 _STRING }; | ||
| 33 | |||
| 34 | use vars qw{$VERSION}; | ||
| 35 | BEGIN { | ||
| 36 | $VERSION = '0.52'; | ||
| 37 | } | ||
| 38 | |||
| 39 | |||
| 40 | |||
| 41 | |||
| 42 | |||
| 43 | ##################################################################### | ||
| 44 | # Constructors and Accessors | ||
| 45 | |||
| 46 | =pod | ||
| 47 | |||
| 48 | =head2 new | ||
| 49 | |||
| 50 | The C<new> constructor is used to create a new ::Command object. | ||
| 51 | |||
| 52 | It takes a set of key/value names params. | ||
| 53 | |||
| 54 | =over | ||
| 55 | |||
| 56 | =item cmd | ||
| 57 | |||
| 58 | The C<cmd> param should contains the command that was executed, | ||
| 59 | as it was sent to the operating system, as as a plain string. | ||
| 60 | |||
| 61 | =item stdout | ||
| 62 | |||
| 63 | The C<stdout> param should be the resulting output to C<STDOUT>, | ||
| 64 | provided as a reference to a C<SCALAR> string. | ||
| 65 | |||
| 66 | =item stderr | ||
| 67 | |||
| 68 | The C<stderr> param should be the resulting output to C<STDERR>, | ||
| 69 | provided as a reference to a C<SCALAR> string. | ||
| 70 | |||
| 71 | =back | ||
| 72 | |||
| 73 | Returns a new L<PITA::XML::Command> object, or dies on error. | ||
| 74 | |||
| 75 | =cut | ||
| 76 | |||
| 77 | sub new { | ||
| 78 | my $class = shift; | ||
| 79 | my $self = bless { @_ }, $class; | ||
| 80 | |||
| 81 | # Check the object | ||
| 82 | $self->_init; | ||
| 83 | |||
| 84 | $self; | ||
| 85 | } | ||
| 86 | |||
| 87 | sub _init { | ||
| 88 | my $self = shift; | ||
| 89 | |||
| 90 | # Check the actual command string | ||
| 91 | unless ( _STRING($self->{cmd}) ) { | ||
| 92 | Carp::croak('Invalid or missing cmd'); | ||
| 93 | } | ||
| 94 | |||
| 95 | # Check the STDOUT | ||
| 96 | unless ( PITA::XML->_OUTPUT($self, 'stdout') ) { | ||
| 97 | Carp::croak('Invalid or missing stdout'); | ||
| 98 | } | ||
| 99 | |||
| 100 | # Check the STDERR | ||
| 101 | unless ( PITA::XML->_OUTPUT($self, 'stderr') ) { | ||
| 102 | Carp::croak('Invalid or missing stderr'); | ||
| 103 | } | ||
| 104 | |||
| 105 | $self; | ||
| 106 | } | ||
| 107 | |||
| 108 | =pod | ||
| 109 | |||
| 110 | =head2 cmd | ||
| 111 | |||
| 112 | The C<cmd> accessor returns the actual command sent to the system. | ||
| 113 | |||
| 114 | =cut | ||
| 115 | |||
| 116 | sub cmd { | ||
| 117 | $_[0]->{cmd}; | ||
| 118 | } | ||
| 119 | |||
| 120 | =pod | ||
| 121 | |||
| 122 | =head2 stdout | ||
| 123 | |||
| 124 | The C<stdout> accessor returns the output of the command as a | ||
| 125 | C<SCALAR> reference. | ||
| 126 | |||
| 127 | =cut | ||
| 128 | |||
| 129 | sub stdout { | ||
| 130 | $_[0]->{stdout}; | ||
| 131 | } | ||
| 132 | |||
| 133 | =pod | ||
| 134 | |||
| 135 | =head2 stderr | ||
| 136 | |||
| 137 | The C<stderr> accessor returns the output of the command as a | ||
| 138 | C<SCALAR> reference. | ||
| 139 | |||
| 140 | =cut | ||
| 141 | |||
| 142 | sub stderr { | ||
| 143 | $_[0]->{stderr}; | ||
| 144 | } | ||
| 145 | |||
| 146 | 1; | ||
| 147 | |||
| 148 | =pod | ||
| 149 | |||
| 150 | =head1 SUPPORT | ||
| 151 | |||
| 152 | Bugs should be reported via the CPAN bug tracker at | ||
| 153 | |||
| 154 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=PITA-XML> | ||
| 155 | |||
| 156 | For other issues, contact the author. | ||
| 157 | |||
| 158 | =head1 AUTHOR | ||
| 159 | |||
| 160 | Adam Kennedy E<lt>adamk@cpan.orgE<gt>, L<http://ali.as/> | ||
| 161 | |||
| 162 | =head1 SEE ALSO | ||
| 163 | |||
| 164 | L<PITA::XML> | ||
| 165 | |||
| 166 | The Perl Image-based Testing Architecture (L<http://ali.as/pita/>) | ||
| 167 | |||
| 168 | =head1 COPYRIGHT | ||
| 169 | |||
| 170 | Copyright 2005 - 2013 Adam Kennedy. | ||
| 171 | |||
| 172 | This program is free software; you can redistribute | ||
| 173 | it and/or modify it under the same terms as Perl itself. | ||
| 174 | |||
| 175 | The full text of the license can be found in the | ||
| 176 | LICENSE file included with this module. | ||
| 177 | |||
| 178 | =cut |