line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Devel::Events::Handler::Callback; |
4
|
9
|
|
|
9
|
|
135093
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
with qw/Devel::Events::Handler/; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has callback => ( |
9
|
|
|
|
|
|
|
isa => "CodeRef", |
10
|
|
|
|
|
|
|
is => "rw", |
11
|
|
|
|
|
|
|
required => 1, |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
around new => sub { |
15
|
|
|
|
|
|
|
my $next = shift; |
16
|
|
|
|
|
|
|
my ( $class, @args ) = @_; |
17
|
|
|
|
|
|
|
@args = ( callback => @args ) if @args == 1; |
18
|
|
|
|
|
|
|
$class->$next(@args); |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new_event { |
22
|
|
|
|
|
|
|
my ( $self, @event ) = @_; |
23
|
|
|
|
|
|
|
$self->callback->( @event ); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
__PACKAGE__; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
__END__ |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=pod |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 NAME |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Devel::Events::Handler::Callback - An event handler that delegates to code references. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 SYNOPSIS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
use Devel::Events::Handler::Callback; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $h = Devel::Events::Handler::Callback->new( |
42
|
|
|
|
|
|
|
callback => sub { |
43
|
|
|
|
|
|
|
my ( $type, %data ) = @_; |
44
|
|
|
|
|
|
|
# ... |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 DESCRIPTION |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This object will let you easily create handlers that are callbacks. This is |
51
|
|
|
|
|
|
|
used extensively in the test suites. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=over 4 |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item callback |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Accepts a code reference. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Required. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=back |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 METHODS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=over 4 |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item new |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
This method is overridden so that when it is passed only one parameter that |
72
|
|
|
|
|
|
|
parameter will be used for the C<callback> attribute. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item new_event @event |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Delegates to C<callback>. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=back |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|