PITA/Guest/Driver.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 108 CC 5 SCAR 18.3
CC
5
Cov
0%
new
20.0
DESTROY
6.0
guest
2.0
CRAP 6.2
1 package PITA::Guest::Driver;
2  
3 use 5.008;
4 use strict;
5 use Carp ();
6 use File::Temp ();
7 use File::Remove ();
8 use Params::Util ();
9 use PITA::XML ();
10  
11 our $VERSION = '0.60';
12  
13  
14  
15  
16  
17 #####################################################################
18 # Constructor and Accessors
19  
20 sub new {
21 my $class = shift;
22 my $self = bless { @_ }, $class;
23  
24 # Were we passed the guest object
25 unless ( Params::Util::_INSTANCE($self->guest, 'PITA::XML::Guest') ) {
26 Carp::croak('Missing or invalid guest');
27 }
28  
29 # Get ourselves a fresh tmp directory
30 unless ( $self->injector_dir ) {
31 $self->{injector_dir} = File::Temp::tempdir();
32 }
33 unless ( -d $self->injector_dir and -w _ ) {
34 die("Temporary directory " . $self->injector_dir . " is not writable");
35 }
36 $self->{pid} = $$;
37  
38 $self;
39 }
40  
41 sub guest {
42 $_[0]->{guest};
43 }
44  
45 sub injector_dir {
46 $_[0]->{injector_dir};
47 }
48  
49  
50  
51  
52  
53 #####################################################################
54 # PITA::Guest::Driver Main Methods
55  
56 sub ping {
57 my $self = shift;
58 Carp::croak(ref($self) . " failed to implement 'ping'");
59 }
60  
61 sub discover {
62 my $self = shift;
63 Carp::croak(ref($self) . " failed to implement 'discover'");
64 }
65  
66 sub test {
67 my $self = shift;
68 Carp::croak(ref($self) . " failed to implement 'test'");
69 }
70  
71  
72  
73  
74  
75 #####################################################################
76 # Support Methods
77  
78 # Is the param a fully resolved request
79 # To be usable, it needs an identifier and an absolute filename path
80 # that can be verified to exist.
81 # Returns the request or undef if not usable.
82 sub _REQUEST {
83 my $self = shift;
84 my $request = Params::Util::_INSTANCE(shift, 'PITA::XML::Request') or return undef;
85 $request->id or return undef;
86 File::Spec->file_name_is_absolute( $request->file->filename ) or return undef;
87 -f $request->file->filename or return undef;
88 $request;
89 }
90  
91 sub DESTROY {
92 # Delete the temp dirs, ignoring errors
93 if (
94 $_[0]->{pid} == $$
95 and
96 $_[0]->{injector_dir}
97 and
98 -d $_[0]->{injector_dir}
99 ) {
100 File::Remove::remove( \1, $_[0]->{injector_dir} );
101 delete $_[0]->{injector_dir};
102 }
103 }
104  
105 1;
106  
107 __END__