| 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, 2015 -- leonerd@leonerd.org.uk | ||||||||||
| 5 | |||||||||||
| 6 | package Event::Distributor::Action; | ||||||||||
| 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 Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 3 | ▶ | use Future; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | =head1 NAME | ||||||||||
| 19 | |||||||||||
| 20 | C<Event::Distributor::Action> - an event that requires one subscriber | ||||||||||
| 21 | |||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||
| 23 | |||||||||||
| 24 | This subclass of L<Event::Distributor::_Event> requires exactly one subscriber | ||||||||||
| 25 | at the time that it is invoked. It passes on the caller's arguments to the | ||||||||||
| 26 | subscriber, and the subscriber's return value back to the caller. | ||||||||||
| 27 | |||||||||||
| 28 | =cut | ||||||||||
| 29 | |||||||||||
| 30 | sub subscribe | ||||||||||
| 31 | { | ||||||||||
| 32 | 3 | ▶ | my $self = shift; | ||||||||
|
Subroutine
subscribe: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 33 | 3 | ▶ | $self->subscribers and croak "Too many subscribers"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | |||||||||||
| 35 | 2 | $self->SUPER::subscribe( @_ ); | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | sub fire | ||||||||||
| 39 | { | ||||||||||
| 40 | 2 | ▶ | my $self = shift; | ||||||||
|
Subroutine
fire: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 41 | 2 | my ( $dist, @args ) = @_; | |||||||||
| 42 | |||||||||||
| 43 | 2 | ▶ | my @subs = $self->subscribers or | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | return Future->fail( "No subscribers" ); | ||||||||||
| 45 | |||||||||||
| 46 | 1 | Future->call( $subs[0], $dist, @args ); | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | =head1 AUTHOR | ||||||||||
| 50 | |||||||||||
| 51 | Paul Evans <leonerd@leonerd.org.uk> | ||||||||||
| 52 | |||||||||||
| 53 | =cut | ||||||||||
| 54 | |||||||||||
| 55 | 3 | 0x55AA; | |||||||||