line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Launcher::Cascade::Container; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Launcher::Cascade::Container - a class to run L::C::Base launchers in cascade |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Launcher::Cascade::Base::...; |
10
|
|
|
|
|
|
|
use Launcher::Cascade::Container; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $launcher1 = new Launcher::Cascade::Base:... ...; |
13
|
|
|
|
|
|
|
my $launcher2 = new Launcher::Cascade::Base:... ...; |
14
|
|
|
|
|
|
|
my $launcher3 = new Launcher::Cascade::Base:... ...; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $container = new Launcher::Cascade::Container |
17
|
|
|
|
|
|
|
-launchers => [ $launcher1, $launcher2, $launcher3 ]; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$container->run_session(); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
A C object maintains a list of launchers, which are instances |
24
|
|
|
|
|
|
|
of C or of its subclasses. The run_session() method let all the |
25
|
|
|
|
|
|
|
launchers run in turn and checks their status until all of them succeed or one |
26
|
|
|
|
|
|
|
of them fails. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
2
|
|
93129
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
71
|
|
31
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
72
|
|
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
2
|
|
10
|
use base qw( Launcher::Cascade ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1146
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 Methods |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=over 4 |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item B |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item B I |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item B I |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Returns the list of C objects that are to be run in this section. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
When called with a I of arguments, this methods also sets the list of |
48
|
|
|
|
|
|
|
launchers to I. The argument can also be an I, in which case |
49
|
|
|
|
|
|
|
it will automatically be dereferenced. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
All elements in I or I should be instances of |
52
|
|
|
|
|
|
|
C or one of its subclasses. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub launchers { |
57
|
|
|
|
|
|
|
|
58
|
29
|
|
|
29
|
1
|
37
|
my $self = shift; |
59
|
|
|
|
|
|
|
|
60
|
29
|
|
100
|
|
|
114
|
$self->{_launchers} ||= []; |
61
|
29
|
100
|
|
|
|
67
|
if ( @_ ) { |
62
|
1
|
50
|
|
|
|
5
|
if ( UNIVERSAL::isa($_[0], 'ARRAY') ) { |
63
|
|
|
|
|
|
|
# Dereference the first arg if it is an arrayref (so that the |
64
|
|
|
|
|
|
|
# method can be called with an arrayref from the constructor). |
65
|
1
|
|
|
|
|
3
|
$self->{_launchers} = $_[0]; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
else { |
68
|
0
|
|
|
|
|
0
|
$self->{_launchers} = [ @_ ]; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
29
|
|
|
|
|
34
|
return @{$self->{_launchers}}; |
|
29
|
|
|
|
|
104
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item B I |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Pushes a launcher to list of launchers. All elements in I should be |
77
|
|
|
|
|
|
|
instances of C or one of its subclasses. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub add_launcher { |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
84
|
0
|
|
0
|
|
|
0
|
push @{$self->{_launchers} ||= []}, @_; |
|
0
|
|
|
|
|
0
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item B |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Returns a true status if all the contained launchers are successfull (their |
90
|
|
|
|
|
|
|
is_success() yields true). |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub is_success { |
95
|
|
|
|
|
|
|
|
96
|
10
|
|
|
10
|
1
|
23
|
my $self = shift; |
97
|
|
|
|
|
|
|
|
98
|
10
|
|
|
|
|
34
|
foreach ( $self->launchers() ) { |
99
|
22
|
100
|
|
|
|
69
|
return unless $_->is_success(); |
100
|
|
|
|
|
|
|
} |
101
|
2
|
|
|
|
|
12
|
return 1; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item B |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Returns a true status if at least one contained launcher has failed (its |
107
|
|
|
|
|
|
|
is_failure() yields true). |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub is_failure { |
112
|
|
|
|
|
|
|
|
113
|
9
|
|
|
9
|
1
|
15
|
my $self = shift; |
114
|
|
|
|
|
|
|
|
115
|
9
|
|
|
|
|
24
|
foreach ( $self->launchers() ) { |
116
|
27
|
100
|
|
|
|
83
|
return 1 if $_->is_failure(); |
117
|
|
|
|
|
|
|
} |
118
|
7
|
|
|
|
|
42
|
return 0; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item B |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Returns 1 if is_success(), 0 if is_failure() and C if the status is yet |
124
|
|
|
|
|
|
|
undetermined, i.e. some launchers are still running or haven't run yet. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub status { |
129
|
|
|
|
|
|
|
|
130
|
6
|
|
|
6
|
1
|
9
|
my $self = shift; |
131
|
|
|
|
|
|
|
|
132
|
6
|
100
|
|
|
|
14
|
return $self->is_success() ? 1 |
|
|
100
|
|
|
|
|
|
133
|
|
|
|
|
|
|
: $self->is_failure() ? 0 |
134
|
|
|
|
|
|
|
: undef; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item B |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item B |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Invokes run(), respectively check_status() on all the contained launchers. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub run { |
146
|
|
|
|
|
|
|
|
147
|
4
|
|
|
4
|
1
|
8
|
my $self = shift; |
148
|
|
|
|
|
|
|
|
149
|
4
|
|
|
|
|
11
|
foreach ( $self->launchers() ) { |
150
|
12
|
|
|
|
|
41
|
$_->run() |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub check_status { |
155
|
|
|
|
|
|
|
|
156
|
4
|
|
|
4
|
1
|
6
|
my $self = shift; |
157
|
|
|
|
|
|
|
|
158
|
4
|
|
|
|
|
8
|
foreach ( $self->launchers() ) { |
159
|
12
|
|
|
|
|
36
|
$_->check_status(); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item B |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Launches run() and check_status() in loop, until either all the contained |
166
|
|
|
|
|
|
|
launchers are successfull or one of them fails. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub run_session { |
171
|
|
|
|
|
|
|
|
172
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
173
|
|
|
|
|
|
|
|
174
|
2
|
|
|
|
|
8
|
while ( !defined($self->status()) ) { |
175
|
4
|
|
|
|
|
14
|
$self->run(); |
176
|
4
|
|
|
|
|
11
|
$self->check_status(); |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=back |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 SEE ALSO |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
L, L |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 AUTHOR |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Cédric Bouvier C<< >> |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Copyright (C) 2006 Cédric Bouvier, All Rights Reserved. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under |
195
|
|
|
|
|
|
|
the same terms as Perl itself. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=cut |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
1; # end of Launcher::Cascade::Container |