blib/lib/Event/Distributor/_Event.pm

filter: Statementstmt 100% 20 / 20 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 66.6% 2 / 3 totaltotal 96.5% 28 / 29 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Event/Distributor/Action.pm ↑ Summary
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 our $VERSION = '0.05';
12  
13 5 ▶use Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 NAME
16  
17 C<Event::Distributor::_Event> - base class for L<Event::Distributor> 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<Event::Distributor::Signal>
28  
29 =item *
30  
31 L<Event::Distributor::Query>
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 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
44 18 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<CODE> reference that subscribes to the event. This code is
58 expected to return a L<Future> instance.
59  
60 =cut
61  
62 sub subscribe
63 {
64 22 ▶ my $self = shift;
Subroutine subscribe: called CC=1 SCAR=0.0
Pod documented
65 22 my ( $code ) = @_;
66  
67 22 push @{ $self->{subscribers} }, $code;
68 }
69  
70 =head2 subscribers
71  
72 @codes = $event->subscribers
73  
74 Returns a list of C<CODE> references previously subscribed.
75  
76 =cut
77  
78 sub subscribers
79 {
80 21 ▶ my $self = shift;
Subroutine subscribers: called CC=1 SCAR=0.0
Pod documented
81 21 return @{ $self->{subscribers} };
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<Event::Distributor> 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<Future> it returns.
98  
99 =cut
100  
101 =head1 AUTHOR
102  
103 Paul Evans <leonerd@leonerd.org.uk>
104  
105 =cut
106  
107 5 0x55AA
« blib/lib/Event/Distributor/Action.pm ↑ Summary