| line | stmt | bran | cond | sub | pod | time | code | 
| 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::Signal; | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 3 |  |  | 3 |  | 42643 | use strict; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 108 |  | 
| 9 | 3 |  |  | 3 |  | 18 | use warnings; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 109 |  | 
| 10 | 3 |  |  | 3 |  | 17 | use base qw( Event::Distributor::_Event ); | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 1792 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | our $VERSION = '0.04'; | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 3 |  |  | 3 |  | 16 | use Future; | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 631 |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | =head1 NAME | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | C - an event that returns no result | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | This subclass of L invokes each of its subscribers | 
| 23 |  |  |  |  |  |  | in turn, ensuring each has a chance to be invoked regardless of the result of | 
| 24 |  |  |  |  |  |  | the others. | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | Its L succeeds (with no value) if no subscriber failed. If one | 
| 27 |  |  |  |  |  |  | subscriber failed, the C fails in the same way. If two or more | 
| 28 |  |  |  |  |  |  | subscribers fail, the resulting C fails with a message composed by | 
| 29 |  |  |  |  |  |  | combining all the individual messages, in the C category, whose | 
| 30 |  |  |  |  |  |  | failure details are a list of the failed component futures. | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =cut | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | sub fire | 
| 35 |  |  |  |  |  |  | { | 
| 36 | 10 |  |  | 10 | 1 | 149 | my $self = shift; | 
| 37 | 10 |  |  |  |  | 21 | my ( $dist, @args ) = @_; | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | return Future->wait_all( | 
| 40 |  |  |  |  |  |  | map { | 
| 41 | 13 |  |  |  |  | 105 | my $sub = $_; local $_;  # protect against corruption of $_ | 
|  | 13 |  |  |  |  | 16 |  | 
| 42 | 13 |  |  |  |  | 49 | Future->call( $sub, $dist, @args ); | 
| 43 |  |  |  |  |  |  | } $self->subscribers | 
| 44 |  |  |  |  |  |  | )->then( sub { | 
| 45 | 10 |  |  | 10 |  | 5102 | my @failed = grep { $_->failure } @_; | 
|  | 13 |  |  |  |  | 59 |  | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 10 | 100 |  |  |  | 97 | return Future->done() if !@failed; | 
| 48 | 2 | 100 |  |  |  | 9 | return $failed[0] if @failed == 1; | 
| 49 |  |  |  |  |  |  | return Future->fail( "Multiple subscribers failed:\n" . | 
| 50 | 1 |  |  |  |  | 3 | join( "", map { " | " . $_->failure } @failed ), | 
|  | 2 |  |  |  |  | 17 |  | 
| 51 |  |  |  |  |  |  | distributor => @failed, | 
| 52 |  |  |  |  |  |  | ); | 
| 53 | 10 |  |  |  |  | 35 | }); | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | =head1 AUTHOR | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | Paul Evans | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | =cut | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | 0x55AA |