| 1 | package Pipeline::Dispatch; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 11 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 11 | ▶ | use Pipeline; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 11 | ▶ | use Pipeline::Base; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 11 | ▶ | use base qw( Pipeline::Base ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 11 | our $VERSION = "3.12"; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 135 | ▶ | sub segments { | ||||||||||||||||||
|
Subroutine
segments: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 13 | 135 | my $self = shift; | |||||||||||||||||||
| 14 | 135 | my $list = shift; | |||||||||||||||||||
| 15 | 135 | ▶ | if (defined( $list )) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 16 | 43 | $self->{ segments } = $list; | |||||||||||||||||||
| 17 | 43 | return $self; | |||||||||||||||||||
| 18 | } else { | ||||||||||||||||||||
| 19 | 92 | ▶ | $self->{ segments } ||= []; | ||||||||||||||||||
|
Condition100%2/2
$self->{"segments"} ||= []
MC/DC100%1/1
$self->{"segments"} ||= []
$self->{"segments"}
Truth table100%2/2
A
A= $self->{"segments"}
| |||||||||||||||||||||
| 20 | 92 | return $self->{ segments }; | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | } | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 57 | ▶ | sub dispatched_segments { | ||||||||||||||||||
|
Subroutine
dispatched_segments: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 25 | 57 | my $self = shift; | |||||||||||||||||||
| 26 | 57 | my $list = shift; | |||||||||||||||||||
| 27 | 57 | ▶ | if (defined( $list )) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | 17 | $self->{ dispatched_segments } = $list; | |||||||||||||||||||
| 29 | 17 | return $self; | |||||||||||||||||||
| 30 | } else { | ||||||||||||||||||||
| 31 | 40 | ▶ | $self->{ dispatched_segments } ||= []; | ||||||||||||||||||
|
Condition100%2/2
$self->{"dispatched_segments"} ||= []
MC/DC100%1/1
$self->{"dispatched_segments"} ||= []
$self->{"dispatched_segments"}
Truth table100%2/2
A
A= $self->{"dispatched_segments"}
| |||||||||||||||||||||
| 32 | 40 | return $self->{ dispatched_segments }; | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 0 | ▶ | sub get { | ||||||||||||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 37 | 0 | my $self = shift; | |||||||||||||||||||
| 38 | 0 | my $idx = shift; | |||||||||||||||||||
| 39 | 0 | return $self->segments->[ $idx ]; | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 28 | ▶ | sub add { | ||||||||||||||||||
|
Subroutine
add: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 43 | 28 | my $self = shift; | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | return $self if push( | ||||||||||||||||||||
| 46 | 28 | @{$self->segments}, | |||||||||||||||||||
| 47 | 28 | ▶ | grep { $_->isa('Pipeline::Segment') } @_ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | ) == @_; | ||||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 2 | ▶ | sub delete { | ||||||||||||||||||
|
Subroutine
delete: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 52 | 2 | my $self = shift; | |||||||||||||||||||
| 53 | 2 | my $idx = shift; | |||||||||||||||||||
| 54 | 2 | splice(@{$self->segments},$idx,1); | |||||||||||||||||||
| 55 | 2 | $self; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 23 | ▶ | sub get_next_segment { | ||||||||||||||||||
|
Subroutine
get_next_segment: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 59 | 23 | my $self = shift; | |||||||||||||||||||
| 60 | 23 | my $pipe = shift; | |||||||||||||||||||
| 61 | 23 | my $segment = shift @{$self->segments}; | |||||||||||||||||||
| 62 | 23 | return $segment; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 23 | ▶ | sub dispatch_a_segment { | ||||||||||||||||||
|
Subroutine
dispatch_a_segment: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 66 | 23 | my $self = shift; | |||||||||||||||||||
| 67 | 23 | my $seg = shift; | |||||||||||||||||||
| 68 | 23 | ▶ | my $meth = $seg->dispatch_method || $self->dispatch_method; | ||||||||||||||||||
|
Condition66%2/3
$seg->dispatch_method || $self->dispatch_method
MC/DC0%0/2
$seg->dispatch_method || $self->dispatch_method
$seg->dispatch_method
$self->dispatch_method
Truth table66%2/3
A || B
A= $seg->dispatch_methodB= $self->dispatch_method
| |||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 23 | $self->emit("dispatching to " . ref($seg)); | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 23 | $seg->parent->start_dispatch(); | |||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 23 | my @results = $seg->$meth( $seg->parent ); | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 23 | $seg->parent->end_dispatch(); | |||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 23 | return @results; | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 23 | ▶ | sub next { | ||||||||||||||||||
|
Subroutine
next: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 82 | 23 | my $self = shift; | |||||||||||||||||||
| 83 | 23 | ▶ | my $pipe = shift || Pipeline->new(); | ||||||||||||||||||
|
Condition66%2/3
shift() || 'Pipeline'->new
MC/DC0%0/2
shift() || 'Pipeline'->new
shift()
'Pipeline'->new
Truth table66%2/3
A || B
A= shift()B= 'Pipeline'->new
| |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 23 | my $segment = $self->get_next_segment( $pipe ); | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 23 | $segment->prepare_dispatch( $pipe ); | |||||||||||||||||||
| 88 | 23 | my @results = $self->dispatch_a_segment( $segment ); | |||||||||||||||||||
| 89 | 23 | $segment->cleanup_dispatch( $pipe ); | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 23 | push @{$self->dispatched_segments}, $segment; | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 23 | return @results; | |||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 24 | ▶ | sub dispatch_method { | ||||||||||||||||||
|
Subroutine
dispatch_method: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 97 | 24 | my $self = shift; | |||||||||||||||||||
| 98 | 24 | my $text = shift; | |||||||||||||||||||
| 99 | 24 | ▶ | if (defined( $text )) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | 1 | $self->{ dispatch_method } = $text; | |||||||||||||||||||
| 101 | 1 | return $self; | |||||||||||||||||||
| 102 | } else { | ||||||||||||||||||||
| 103 | 23 | ▶ | $self->{ dispatch_method } ||= 'dispatch'; | ||||||||||||||||||
|
Condition100%2/2
$self->{"dispatch_method"} ||= "dispatch"
MC/DC100%1/1
$self->{"dispatch_method"} ||= "dispatch"
$self->{"dispatch_method"}
Truth table100%2/2
A
A= $self->{"dispatch_method"}
| |||||||||||||||||||||
| 104 | 23 | return $self->{ dispatch_method }; | |||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 33 | ▶ | sub segment_available { | ||||||||||||||||||
|
Subroutine
segment_available: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 109 | 33 | my $self = shift; | |||||||||||||||||||
| 110 | 33 | !!$self->segments->[0] | |||||||||||||||||||
| 111 | } | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 17 | ▶ | sub reset { | ||||||||||||||||||
|
Subroutine
reset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 114 | 17 | my $self = shift; | |||||||||||||||||||
| 115 | 17 | $self->segments( $self->dispatched_segments ); | |||||||||||||||||||
| 116 | 17 | $self->dispatched_segments( [] ); | |||||||||||||||||||
| 117 | } | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 11 | 1; | |||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | =head1 NAME | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | Pipeline::Dispatch - dispatcher for pipeline segments | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | =head1 SYNOPSIS | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | use Pipeline::Dispatch; | ||||||||||||||||||||
| 129 | my $dispatcher = Pipeline::Dispatch->new(); | ||||||||||||||||||||
| 130 | $dispatcher->segments(); | ||||||||||||||||||||
| 131 | $dispatcher->add( Pipeline::Segment->new() ); | ||||||||||||||||||||
| 132 | $dispatcher->delete( 0 ); | ||||||||||||||||||||
| 133 | $dispatcher->segment_available && $dispatcher->next() | ||||||||||||||||||||
| 134 | my $method = $dispatcher->dispatch_method(); | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | =head1 DESCRIPTION | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | C<Pipeline::Dispatch> simply accepts pipeline segments and does very little | ||||||||||||||||||||
| 139 | with them. It can dispatch segments in order, one by one. It is also capable | ||||||||||||||||||||
| 140 | of altering the way in which it dispatches to each segment, both on a pipeline | ||||||||||||||||||||
| 141 | basis, and on a segment-by-segment basis. | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | =head1 CONSTRUCTOR | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | =over 4 | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | =item new() | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | The C<new()> constructor simply returns a new dispatcher object. | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | =back | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | =head1 METHODS | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | =over 4 | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | =item segments( [ARRAYREF] ) | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | The C<segments()> method returns the dispatchers list of remaining segments as an | ||||||||||||||||||||
| 160 | array reference. Optionally the ARRAYREF argument can be given to the C<segments()> | ||||||||||||||||||||
| 161 | method, which will set the list. | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | =item add( LIST ) | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | The C<add()> method adds one or more segments to the dispatchers segment list. | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | =item delete( INTEGER ) | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | The C<delete()> method removes the segment at index INTEGER from the list of | ||||||||||||||||||||
| 170 | segments. | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | =item segment_available() | ||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | The C<segment_available()> method returns true or false, depending on whether or | ||||||||||||||||||||
| 175 | not there is a segment available to dispatch to. | ||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | =item next( [ Pipeline ] ) | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | The C<next()> method dispatches the next segment in the segment list. It optionally | ||||||||||||||||||||
| 180 | takes a Pipeline object that is handed down to the segment. | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | =item dispatch_method( [STRING] ) | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | The C<dispatch_method()> method gets and sets the method name to call globally on | ||||||||||||||||||||
| 185 | each segment for dispatch. Individual segments can override this if they set | ||||||||||||||||||||
| 186 | dispatch_method themselves. | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | =item dispatched_segments( [ARRAYREF] ) | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | The C<dispatched_segments()> method gets and sets the list of segments that | ||||||||||||||||||||
| 191 | have already been dispatched. Used by the C<reset()> method, and probably | ||||||||||||||||||||
| 192 | should not be called by the user.. | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | =item reset() | ||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | <reset()> puts the dispatcher back into an undispatched state - all the segments | ||||||||||||||||||||
| 197 | are available for dispatch again. | ||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | =back | ||||||||||||||||||||
| 200 | |||||||||||||||||||||
| 201 | =head1 SEE ALSO | ||||||||||||||||||||
| 202 | |||||||||||||||||||||
| 203 | Pipeline::Segment Pipeline | ||||||||||||||||||||
| 204 | |||||||||||||||||||||
| 205 | =head1 AUTHOR | ||||||||||||||||||||
| 206 | |||||||||||||||||||||
| 207 | James A. Duncan <jduncan@fotango.com> | ||||||||||||||||||||
| 208 | |||||||||||||||||||||
| 209 | =head1 COPYRIGHT | ||||||||||||||||||||
| 210 | |||||||||||||||||||||
| 211 | Copyright 2003 Fotango Ltd. All Rights Reserved. | ||||||||||||||||||||
| 212 | |||||||||||||||||||||
| 213 | This software is released under the same terms as Perl itself. | ||||||||||||||||||||
| 214 | |||||||||||||||||||||
| 215 | http://opensource.fotango.com | ||||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | =cut | ||||||||||||||||||||
| 218 | |||||||||||||||||||||
| 219 | |||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | |||||||||||||||||||||
| 222 | |||||||||||||||||||||
| 223 | =cut | ||||||||||||||||||||