| 1 | # You may distribute under the terms of either the GNU General Public License | ||||||||||||||||||||||||||||
| 2 | # or the Artistic License (the same terms as Perl itself) | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # (C) Paul Evans, 2014-2015 -- leonerd@leonerd.org.uk | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | package Event::Distributor::Query; | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use base qw( Event::Distributor::_Event ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Future; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | C<Event::Distributor::Query> - an event that collects a result | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | This subclass of L<Event::Distributor::_Event> invokes each of its subscribers | ||||||||||||||||||||||||||||
| 23 | in turn, yielding either the (first) successful result, or a failure if they | ||||||||||||||||||||||||||||
| 24 | all fail. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | sub fire | ||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||
| 30 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
fire: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 2 | my ( $dist, @args ) = @_; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 2 | my $await = $self->{await}; | |||||||||||||||||||||||||||
| 34 | 2 | my @f; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 2 | foreach my $sub ( $self->subscribers ) { | |||||||||||||||||||||||||||
| 37 | 2 | my $f = $sub->( $dist, @args ); | |||||||||||||||||||||||||||
| 38 | 2 | push @f, $f; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 2 | ▶ | last if $f->is_ready and !$f->failure; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$f->is_ready and not $f->failure
MC/DC0%0/2
$f->is_ready and not $f->failure
$f->is_ready
not $f->failure
Truth table33%1/3
A and not(B)
A= $f->is_readyB= not $f->failure
| |||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | return Future->needs_any( @f )->then( sub { | ||||||||||||||||||||||||||||
| 44 | 2 | ▶ | my @results = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | # TODO: conversions? | ||||||||||||||||||||||||||||
| 46 | 2 | Future->done( @results ); | |||||||||||||||||||||||||||
| 47 | 2 | }); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | Paul Evans <leonerd@leonerd.org.uk> | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =cut | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 3 | 0x55AA | |||||||||||||||||||||||||||