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   29 use strict;
  5         7  
  5         97  
9 5     5   18 use warnings;
  5         7  
  5         132  
10              
11             our $VERSION = '0.05';
12              
13 5     5   17 use Future;
  5         7  
  5         497  
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 18     18 0 6515 my $class = shift;
44 18         56 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 22     22 1 86 my $self = shift;
65 22         31 my ( $code ) = @_;
66              
67 22         26 push @{ $self->{subscribers} }, $code;
  22         47  
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 21     21 1 33 my $self = shift;
81 21         26 return @{ $self->{subscribers} };
  21         226  
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