Event.pm

filter: Statementstmt 100% 25 / 25 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 100% 35 / 35 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Emitter.pm ↑ Summary Listener.pm »
1 package Beam::Event;
2 12 our $VERSION = '1.007';
3 # ABSTRACT: Base Event class
4  
5 #pod =head1 SYNOPSIS
6 #pod
7 #pod # My::Emitter consumes the Beam::Emitter role
8 #pod my $emitter = My::Emitter->new;
9 #pod $emitter->on( "foo", sub {
10 #pod my ( $event ) = @_;
11 #pod print "Foo happened!\n";
12 #pod # stop this event from continuing
13 #pod $event->stop;
14 #pod } );
15 #pod my $event = $emitter->emit( "foo" );
16 #pod
17 #pod =head1 DESCRIPTION
18 #pod
19 #pod This is the base event class for C<Beam::Emitter> objects.
20 #pod
21 #pod The base class is only really useful for notifications. Create a subclass
22 #pod to add data attributes.
23 #pod
24 #pod =head1 SEE ALSO
25 #pod
26 #pod =over 4
27 #pod
28 #pod =item L<Beam::Emitter>
29 #pod
30 #pod =back
31 #pod
32 #pod =cut
33  
34 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 12 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 12 ▶use Types::Standard qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 #pod =attr name
41 #pod
42 #pod The name of the event. This is the string that is given to L<Beam::Emitter/on>.
43 #pod
44 #pod =cut
45  
46 12 has name => (
47 is => 'ro',
48 isa => Str,
49 required => 1,
50 );
51  
52 #pod =attr emitter
53 #pod
54 #pod The emitter of this event. This is the object that created the event.
55 #pod
56 #pod =cut
57  
58 12 has emitter => (
59 is => 'ro',
60 isa => ConsumerOf['Beam::Emitter'],
61 required => 1,
62 );
63  
64 #pod =attr is_default_stopped
65 #pod
66 #pod This is true if anyone called L</stop_default> on this event.
67 #pod
68 #pod Your L<emitter|Beam::Emitter> should check this attribute before trying to do
69 #pod what the event was notifying about.
70 #pod
71 #pod =cut
72  
73 has is_default_stopped => (
74 is => 'rw',
75 isa => Bool,
76 37 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
77 12 );
78  
79 #pod =attr is_stopped
80 #pod
81 #pod This is true if anyone called L</stop> on this event.
82 #pod
83 #pod When using L<the emit method|Beam::Emitter/emit>, this is checked automatically
84 #pod after every callback, and event processing is stopped if this is true.
85 #pod
86 #pod =cut
87  
88 has is_stopped => (
89 is => 'rw',
90 isa => Bool,
91 37 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
92 12 );
93  
94 #pod =method stop_default ()
95 #pod
96 #pod Calling this will cause the default behavior of this event to be stopped.
97 #pod
98 #pod B<NOTE:> Your event-emitting object must check L</is_default_stopped> for this
99 #pod behavior to work.
100 #pod
101 #pod =cut
102  
103 3 ▶sub stop_default {
Subroutine stop_default: called CC=1 SCAR=0.0
Pod documented
104 3 my ( $self ) = @_;
105 3 $self->is_default_stopped( 1 );
106 }
107  
108 #pod =method stop ()
109 #pod
110 #pod Calling this will immediately stop any further processing of this event.
111 #pod Also calls L</stop_default>.
112 #pod
113 #pod =cut
114  
115 2 ▶sub stop {
Subroutine stop: called CC=1 SCAR=0.0
Pod documented
116 2 my ( $self ) = @_;
117 2 $self->stop_default;
118 2 $self->is_stopped( 1 );
119 }
120  
121 12 1;
122  
123 __END__
« Emitter.pm ↑ Summary Listener.pm »