line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Eve::EventMap; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
47
|
use parent qw(Eve::Class); |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
77
|
|
4
|
|
|
|
|
|
|
|
5
|
8
|
|
|
8
|
|
577
|
use strict; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
276
|
|
6
|
8
|
|
|
8
|
|
61
|
use warnings; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
2985
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Eve::EventMap - maps events to event handlers. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $event_map = Eve::EventMap->new(); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$event_map->bind( |
17
|
|
|
|
|
|
|
event_class => 'Eve::Event::Foo', |
18
|
|
|
|
|
|
|
handler => $some_handler); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$event_map->bind( |
21
|
|
|
|
|
|
|
event_class => 'Eve::Event::Bar', |
22
|
|
|
|
|
|
|
handler => $another_handler); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $event = Eve::Event::Foo->new(event_map => $event_map); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
B is the facility on the one hand used to bind |
29
|
|
|
|
|
|
|
events to event handlers, on the other hand to extract handlers that |
30
|
|
|
|
|
|
|
need to be run when a certain event is triggered. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 METHODS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 B |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub init { |
39
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
$self->{'_map'} = {}; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 B |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Binds an event class to an event handler. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head3 Arguments |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=over 4 |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item C |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
an event class (B derivative) |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item C |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
a handler instance (B derivative). |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=back |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head3 Throws |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=over 4 |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item C |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
trying to bind a handler duplicating one that has already been bound |
71
|
|
|
|
|
|
|
to the event. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=back |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub bind { |
78
|
0
|
|
|
0
|
1
|
|
my ($self, %arg_hash) = @_; |
79
|
0
|
|
|
|
|
|
Eve::Support::arguments(\%arg_hash, my ($event_class, $handler)); |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
if (not exists $self->_map->{$event_class}) { |
82
|
0
|
|
|
|
|
|
$self->_map->{$event_class} = []; |
83
|
|
|
|
|
|
|
} else { |
84
|
0
|
0
|
|
|
|
|
if (grep($_ == $handler, @{$self->_map->{$event_class}})) { |
|
0
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
Eve::Exception::Duplicate->throw( |
86
|
|
|
|
|
|
|
message => 'Duplicate handler in the event map: '.$handler); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
push(@{$self->_map->{$event_class}}, $handler); |
|
0
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 B |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Returns handler list for an event. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head3 Arguments |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=over 4 |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item C |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
an event instance we are requesting handlers for. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=back |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head3 Returns |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Unified list of handlers bound to the event and to all its |
112
|
|
|
|
|
|
|
ancestors. Note that if one handler is bound to an event and its |
113
|
|
|
|
|
|
|
ancestors it will be returned only once. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub get_handler_list { |
118
|
0
|
|
|
0
|
1
|
|
my ($self, %arg_hash) = @_; |
119
|
0
|
|
|
|
|
|
Eve::Support::arguments(\%arg_hash, my $event); |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my $handler_list = []; |
122
|
0
|
|
|
|
|
|
for my $event_class (keys %{$self->_map}) { |
|
0
|
|
|
|
|
|
|
123
|
0
|
0
|
|
|
|
|
if ($event->isa($event_class)) { |
124
|
0
|
|
|
|
|
|
push(@{$handler_list}, @{$self->_map->{$event_class}}); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
return Eve::Support::unique(list => $handler_list); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 SEE ALSO |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=over 4 |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item L |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item L |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item L |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item L |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=back |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Copyright 2012 Igor Zinovyev. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
150
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
151
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 AUTHOR |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=over 4 |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item L |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=back |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
1; |