Cascade/Container.pm

filter: Statementstmt 90.2% 37 / 41 Branchbran 92.8% 13 / 14 Conditioncond 50.0% 2 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 90.9% 10 / 11 Podpod 100% 8 / 8 totaltotal 88.7% 71 / 80 CC 14 SCAR 10.7
CC
14
Cov
88%
add_launcher
6.0
launchers
4.0
is_success
3.0
CRAP 2.9
« Cascade/FileReader/Seekable.pm ↑ Summary Cascade/ListOfStrings.pm »
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<L::C::Container> object maintains a list of launchers, which are instances
24 of C<L::C::Base> 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 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 3 ▶use base qw( Launcher::Cascade );
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 =head2 Methods
36  
37 =over 4
38  
39 =item B<launchers>
40  
41 =item B<launchers> I<LIST>
42  
43 =item B<launchers> I<ARRAYREF>
44  
45 Returns the list of C<Launcher::Cascade::Base> objects that are to be run in this section.
46  
47 When called with a I<LIST> of arguments, this methods also sets the list of
48 launchers to I<LIST>. The argument can also be an I<ARRAYREF>, in which case
49 it will automatically be dereferenced.
50  
51 All elements in I<LIST> or I<ARRAYREF> should be instances of
52 C<Launcher::Cascade::Base> or one of its subclasses.
53  
54 =cut
55  
56 29 ▶sub launchers {
Subroutine launchers: called CC=4 SCAR=14.0
Pod documented
57  
58 29 my $self = shift;
59  
60 29 ▶ $self->{_launchers} ||= [];
Condition100%2/2
$self->{"_launchers"} ||= []
l!l
281
MC/DC100%1/1
$self->{"_launchers"} ||= []
$self->{"_launchers"}
Truth table100%2/2
A
A= $self->{"_launchers"}
Aresult
11
00
61 29 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 28 29
62 1 ▶ if ( UNIVERSAL::isa($_[0], 'ARRAY') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($_[0], 'ARRAY')) { } 1 0 1
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 $self->{_launchers} = $_[0];
66 }
67 else {
68 0 $self->{_launchers} = [ @_ ];
69 }
70 }
71 29 return @{$self->{_launchers}};
72 }
73  
74 =item B<add_launcher> I<LIST>
75  
76 Pushes a launcher to list of launchers. All elements in I<LIST> should be
77 instances of C<Launcher::Cascade::Base> or one of its subclasses.
78  
79 =cut
80  
81 0 ▶sub add_launcher {
Subroutine add_launcher: not called CC=2 SCAR=17.9
Pod documented
82  
83 0 my $self = shift;
84 0 ▶ push @{$self->{_launchers} ||= []}, @_;
Condition0%0/2
$self->{"_launchers"} ||= []
l!l
00
MC/DC0%0/1
$self->{"_launchers"} ||= []
$self->{"_launchers"}
Truth table0%0/2
A
A= $self->{"_launchers"}
Aresult
11
00
85 }
86  
87 =item B<is_success>
88  
89 Returns a true status if all the contained launchers are successfull (their
90 is_success() yields true).
91  
92 =cut
93  
94 10 ▶sub is_success {
Subroutine is_success: called CC=3 SCAR=11.0
Pod documented
95  
96 10 my $self = shift;
97
98 10 foreach ( $self->launchers() ) {
99 22 ▶ return unless $_->is_success();
Branch: 1 branch
BranchTrueFalseTotal
unless $_->is_success 8 14 22
100 }
101 2 return 1;
102 }
103  
104 =item B<is_failure>
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 9 ▶sub is_failure {
Subroutine is_failure: called CC=3 SCAR=11.0
Pod documented
112  
113 9 my $self = shift;
114  
115 9 foreach ( $self->launchers() ) {
116 27 ▶ return 1 if $_->is_failure();
Branch: 1 branch
BranchTrueFalseTotal
if $_->is_failure 2 25 27
117 }
118 7 return 0;
119 }
120  
121 =item B<status>
122  
123 Returns 1 if is_success(), 0 if is_failure() and C<undef> if the status is yet
124 undetermined, i.e. some launchers are still running or haven't run yet.
125  
126 =cut
127  
128 6 ▶sub status {
Subroutine status: called CC=3 SCAR=11.0
Pod documented
129  
130 6 my $self = shift;
131  
132 6 ▶ return $self->is_success() ? 1
Branch: 2 branches
BranchTrueFalseTotal
$self->is_success ? : 1 5 6
$self->is_failure ? : 1 4 5
133 : $self->is_failure() ? 0
134 : undef;
135 }
136  
137 =item B<run>
138  
139 =item B<check_status>
140  
141 Invokes run(), respectively check_status() on all the contained launchers.
142  
143 =cut
144  
145 4 ▶sub run {
Subroutine run: called CC=2 SCAR=6.9
Pod documented
146  
147 4 my $self = shift;
148  
149 4 foreach ( $self->launchers() ) {
150 12 $_->run()
151 }
152 }
153  
154 4 ▶sub check_status {
Subroutine check_status: called CC=2 SCAR=6.9
Pod documented
155  
156 4 my $self = shift;
157  
158 4 foreach ( $self->launchers() ) {
159 12 $_->check_status();
160 }
161 }
162  
163 =item B<run_session>
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 2 ▶sub run_session {
Subroutine run_session: called CC=2 SCAR=6.9
Pod documented
171  
172 2 my $self = shift;
173
174 2 ▶ while ( !defined($self->status()) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->status) 4 2 6
175 4 $self->run();
176 4 $self->check_status();
177 }
178 }
179  
180 =back
181  
182 =head1 SEE ALSO
183  
184 L<Launcher::Cascade>, L<Launcher::Cascade::Base>
185  
186 =head1 AUTHOR
187  
188 Cédric Bouvier C<< <cbouvi@cpan.org> >>
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 3 1; # end of Launcher::Cascade::Container
« Cascade/FileReader/Seekable.pm ↑ Summary Cascade/ListOfStrings.pm »