line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Devel::Events::Filter; |
4
|
1
|
|
|
1
|
|
2198
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
with qw/Devel::Events::Handler/; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
requires 'filter_event'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has handler => ( |
11
|
|
|
|
|
|
|
# does => "Devel::Events::Handler", # we like duck typing |
12
|
|
|
|
|
|
|
isa => "Object", |
13
|
|
|
|
|
|
|
is => "rw", |
14
|
|
|
|
|
|
|
required => 1, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new_event { |
18
|
|
|
|
|
|
|
my ( $self, @event ) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
if ( my @filtered = $self->filter_event( @event ) ) { |
21
|
|
|
|
|
|
|
$self->send_filtered_event(@filtered); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub send_filtered_event { |
26
|
|
|
|
|
|
|
my ( $self, @filtered ) = @_; |
27
|
|
|
|
|
|
|
$self->handler->new_event( @filtered ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
__PACKAGE__; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
__END__ |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=pod |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 NAME |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Devel::Events::Filter - A handler role that filters events and delegates to |
39
|
|
|
|
|
|
|
another. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 SYNOPSIS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
package MyFilter; |
44
|
|
|
|
|
|
|
use Moose; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
with qw/Devel::Events::Filter/; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub filter_event { |
49
|
|
|
|
|
|
|
my ( $self, @event ) = @_; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return (map { ... } @event); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 DESCRIPTION |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
This role allows you to build event filters easily: |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 USAGE |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
To use this role you must provide the C<filter_event> method. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
This role provides an optional C<handler> attribute and a C<new_event> method, |
63
|
|
|
|
|
|
|
and does the L<Devel::Events::Handler> role implicitly. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
If a sub handler was provided then the filtered event will be delegated to it, |
66
|
|
|
|
|
|
|
but due to the usefulness of filters as debugging aids this is currently |
67
|
|
|
|
|
|
|
optional. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
In the future this design choice might change. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item handler |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
A L<Devel::Events::Handler> to delegate to. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 METHODS |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=over 4 |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item new_event @event |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Filters the event through C<filter_event>. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
If C<handler> is set, delegates the filtered event to the handler. If not |
86
|
|
|
|
|
|
|
C<no_handler_error> is called instead. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item no_handler_error @filtered_event |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
This method is called if no handler is present. It is a stub, but in the future |
91
|
|
|
|
|
|
|
it may raise an error. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=back |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 SEE ALSO |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
L<Devel::Events>, L<Devel::Events::Handler>, L<Devel::Events::Filter::Stamp>, |
98
|
|
|
|
|
|
|
L<Devel::Events::Filter::Warn> |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |