File Coverage

blib/lib/PITA/XML/Command.pm
Criterion Covered Total %
statement 28 31 90.3
branch 3 6 50.0
condition n/a
subroutine 11 11 100.0
pod 4 4 100.0
total 46 52 88.4


line stmt bran cond sub pod time code
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 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 10     10   286 use 5.006;
  10         31  
  10         366  
30 10     10   51 use strict;
  10         18  
  10         271  
31 10     10   100 use Carp ();
  10         17  
  10         207  
32 10     10   47 use Params::Util qw{ _SCALAR0 _STRING };
  10         16  
  10         552  
33              
34 10     10   46 use vars qw{$VERSION};
  10         38  
  10         486  
35             BEGIN {
36 10     10   2623 $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 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 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 param should be the resulting output to C,
64             provided as a reference to a C string.
65              
66             =item stderr
67              
68             The C param should be the resulting output to C,
69             provided as a reference to a C string.
70              
71             =back
72              
73             Returns a new L object, or dies on error.
74              
75             =cut
76              
77             sub new {
78 1     1 1 622 my $class = shift;
79 1         6 my $self = bless { @_ }, $class;
80              
81             # Check the object
82 1         4 $self->_init;
83              
84 1         3 $self;
85             }
86              
87             sub _init {
88 2     2   5 my $self = shift;
89              
90             # Check the actual command string
91 2 50       13 unless ( _STRING($self->{cmd}) ) {
92 0         0 Carp::croak('Invalid or missing cmd');
93             }
94              
95             # Check the STDOUT
96 2 50       13 unless ( PITA::XML->_OUTPUT($self, 'stdout') ) {
97 0         0 Carp::croak('Invalid or missing stdout');
98             }
99              
100             # Check the STDERR
101 2 50       6 unless ( PITA::XML->_OUTPUT($self, 'stderr') ) {
102 0         0 Carp::croak('Invalid or missing stderr');
103             }
104              
105 2         4 $self;
106             }
107              
108             =pod
109              
110             =head2 cmd
111              
112             The C accessor returns the actual command sent to the system.
113              
114             =cut
115              
116             sub cmd {
117 1     1 1 5 $_[0]->{cmd};
118             }
119              
120             =pod
121              
122             =head2 stdout
123              
124             The C accessor returns the output of the command as a
125             C reference.
126              
127             =cut
128              
129             sub stdout {
130 3     3 1 20 $_[0]->{stdout};
131             }
132              
133             =pod
134              
135             =head2 stderr
136              
137             The C accessor returns the output of the command as a
138             C reference.
139              
140             =cut
141              
142             sub stderr {
143 3     3 1 15 $_[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
155              
156             For other issues, contact the author.
157              
158             =head1 AUTHOR
159              
160             Adam Kennedy Eadamk@cpan.orgE, L
161              
162             =head1 SEE ALSO
163              
164             L
165              
166             The Perl Image-based Testing Architecture (L)
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