PITA/Guest/Server/Process.pm untested

filter: Statementstmt 0.0% 0 / 48 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 73 CC 3 SCAR 11.2
CC
3
Cov
0%
upload
6.0
finish
6.0
new
2.0
CRAP 3.1
1 package PITA::Guest::Server::Process;
2  
3 # A Process.pm compatible wrapper around PITA::Guest::Server
4  
5 use 5.008;
6 use strict;
7 use Process ();
8  
9 our $VERSION = '0.60';
10 our @ISA = 'Process';
11  
12  
13  
14  
15  
16 ######################################################################
17 # Constructor and Accessors
18  
19 sub new {
20 my $class = shift;
21 my $self = bless { @_ }, $class;
22 return $self;
23 }
24  
25 sub pinged {
26 $_[0]->{pinged};
27 }
28  
29 sub mirrored {
30 $_[0]->{mirrored};
31 }
32  
33 sub uploaded {
34 $_[0]->{uploaded};
35 }
36  
37 # Find a single named upload
38 sub upload {
39 my $self = shift;
40 my $path = shift;
41 foreach my $array ( @{$self->uploaded} ) {
42 if ( $array->[0] eq $path ) {
43 return $array->[1];
44 }
45 }
46 return undef;
47 }
48  
49  
50  
51  
52  
53 ######################################################################
54 # Process Methods
55  
56 sub prepare {
57 my $self = shift;
58  
59 # Create the server object passing capitalised params in
60 require PITA::Guest::Server;
61 $self->{server} = PITA::Guest::Server->new(
62 map { $_ => $self->{$_} } grep { /^[A-Z]/ } keys %$self
63 );
64  
65 return 1;
66 }
67  
68 sub run {
69 my $self = shift;
70  
71 # Prepare to run POE
72 require POE;
73 POE->import;
74  
75 # Bootstrap the server and just hope for the best :)
76 $self->{server}->start;
77 POE::Kernel->run;
78  
79 return 1;
80 }
81  
82 sub finish {
83 my $self = shift;
84  
85 # Save the results and clean up the server
86 if ( $self->{server} ) {
87 $self->{pinged} = $self->{server}->pinged;
88 $self->{mirrored} = $self->{server}->mirrored;
89 $self->{uploaded} = $self->{server}->uploaded;
90 delete $self->{server};
91 }
92  
93 return 1;
94 }
95  
96 1;