File Coverage

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


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