File Coverage

blib/lib/Event/Distributor/_Event.pm
Criterion Covered Total %
statement 18 18 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 2 3 66.6
total 26 27 96.3


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, 2015 -- leonerd@leonerd.org.uk
5              
6             package Event::Distributor::_Event;
7              
8 5     5   30 use strict;
  5         10  
  5         134  
9 5     5   25 use warnings;
  5         11  
  5         278  
10              
11             our $VERSION = '0.04';
12              
13 5     5   27 use Future;
  5         10  
  5         799  
14              
15             =head1 NAME
16              
17             C - base class for L events
18              
19             =head1 DESCRIPTION
20              
21             This class is the base from which the following actual classes are derived:
22              
23             =over 2
24              
25             =item *
26              
27             L
28              
29             =item *
30              
31             L
32              
33             =back
34              
35             Instances of this class shouldn't be directly created by end-user code, but it
36             is documented here in order to list the shared methods available on all the
37             subclasses.
38              
39             =cut
40              
41             sub new
42             {
43 14     14 0 6724 my $class = shift;
44 14         125 return bless {
45             subscribers => [],
46             }, $class;
47             }
48              
49             =head1 METHODS
50              
51             =cut
52              
53             =head2 subscribe
54              
55             $event->subscribe( $code )
56              
57             Adds a new C reference that subscribes to the event. This code is
58             expected to return a L instance.
59              
60             =cut
61              
62             sub subscribe
63             {
64 17     17 1 81 my $self = shift;
65 17         25 my ( $code ) = @_;
66              
67 17         23 push @{ $self->{subscribers} }, $code;
  17         68  
68             }
69              
70             =head2 subscribers
71              
72             @codes = $event->subscribers
73              
74             Returns a list of C references previously subscribed.
75              
76             =cut
77              
78             sub subscribers
79             {
80 17     17 1 25 my $self = shift;
81 17         23 return @{ $self->{subscribers} };
  17         297  
82             }
83              
84             =head1 EXPECTED METHODS
85              
86             Subclasses are expected to implement the following methods:
87              
88             =cut
89              
90             =head2 fire
91              
92             $f = $event->fire( @args )
93              
94             Invoked by L to actually run the signal. This is expected
95             to invoke any or all subscribers in whatever manner it implements, passing
96             arguments as required, and collecting results in some way to provide as the
97             eventual answer of the L it returns.
98              
99             =cut
100              
101             =head1 AUTHOR
102              
103             Paul Evans
104              
105             =cut
106              
107             0x55AA