line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
use strict; |
2
|
21
|
|
|
21
|
|
104753
|
use warnings; |
|
21
|
|
|
|
|
51
|
|
|
21
|
|
|
|
|
581
|
|
3
|
21
|
|
|
21
|
|
102
|
use parent qw/Exporter/; |
|
21
|
|
|
|
|
48
|
|
|
21
|
|
|
|
|
547
|
|
4
|
21
|
|
|
21
|
|
538
|
use Scalar::Util (); |
|
21
|
|
|
|
|
350
|
|
|
21
|
|
|
|
|
139
|
|
5
|
21
|
|
|
21
|
|
1056
|
use mro; |
|
21
|
|
|
|
|
53
|
|
|
21
|
|
|
|
|
496
|
|
6
|
21
|
|
|
21
|
|
142
|
|
|
21
|
|
|
|
|
75
|
|
|
21
|
|
|
|
|
204
|
|
7
|
|
|
|
|
|
|
our @EXPORT = qw/add_trigger call_trigger get_trigger_code/; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my ($class, %args) = @_; |
10
|
|
|
|
|
|
|
|
11
|
8
|
|
|
8
|
1
|
4833
|
if (ref $class) { |
12
|
|
|
|
|
|
|
while (my ($hook, $code) = each %args) { |
13
|
8
|
100
|
|
|
|
25
|
push @{$class->{_trigger}->{$hook}}, $code; |
14
|
2
|
|
|
|
|
8
|
} |
15
|
2
|
|
|
|
|
4
|
} else { |
|
2
|
|
|
|
|
11
|
|
16
|
|
|
|
|
|
|
no strict 'refs'; |
17
|
|
|
|
|
|
|
while (my ($hook, $code) = each %args) { |
18
|
21
|
|
|
21
|
|
2351
|
push @{${"${class}::_trigger"}->{$hook}}, $code; |
|
21
|
|
|
|
|
44
|
|
|
21
|
|
|
|
|
4698
|
|
19
|
6
|
|
|
|
|
33
|
} |
20
|
7
|
|
|
|
|
12
|
} |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
67
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my ($class, $hook, @args) = @_; |
24
|
|
|
|
|
|
|
my @code = $class->get_trigger_code($hook); |
25
|
|
|
|
|
|
|
for my $code (@code) { |
26
|
26
|
|
|
26
|
1
|
2459
|
$code->($class, @args); |
27
|
26
|
|
|
|
|
69
|
} |
28
|
26
|
|
|
|
|
77
|
} |
29
|
6
|
|
|
|
|
26
|
|
30
|
|
|
|
|
|
|
my ($class, $hook) = @_; |
31
|
|
|
|
|
|
|
my @code; |
32
|
|
|
|
|
|
|
if (Scalar::Util::blessed($class)) { |
33
|
|
|
|
|
|
|
push @code, @{ $class->{_trigger}->{$hook} || [] }; |
34
|
48
|
|
|
48
|
1
|
96
|
$class = ref $class; |
35
|
48
|
|
|
|
|
69
|
} |
36
|
48
|
50
|
|
|
|
182
|
no strict 'refs'; |
37
|
48
|
100
|
|
|
|
79
|
my $klass = ref $class || $class; |
|
48
|
|
|
|
|
277
|
|
38
|
48
|
|
|
|
|
103
|
for (@{mro::get_linear_isa($class)}) { |
39
|
|
|
|
|
|
|
push @code, @{${"${_}::_trigger"}->{$hook} || []}; |
40
|
21
|
|
|
21
|
|
160
|
} |
|
21
|
|
|
|
|
53
|
|
|
21
|
|
|
|
|
2915
|
|
41
|
48
|
|
33
|
|
|
214
|
return @code; |
42
|
48
|
|
|
|
|
74
|
} |
|
48
|
|
|
|
|
204
|
|
43
|
173
|
100
|
|
|
|
226
|
|
|
173
|
|
|
|
|
207
|
|
|
173
|
|
|
|
|
694
|
|
44
|
|
|
|
|
|
|
1; |
45
|
48
|
|
|
|
|
133
|
|
46
|
|
|
|
|
|
|
=head1 NAME |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Amon2::Trigger - Trigger system for Amon2 |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 SYNOPSIS |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
package MyClass; |
53
|
|
|
|
|
|
|
use parent qw/Amon2::Trigger/; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__PACKAGE__->add_trigger('Foo'); |
56
|
|
|
|
|
|
|
__PACKAGE__->call_trigger('Foo'); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 DESCRIPTION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
This is a trigger system for Amon2. You can use this class for your class using trigger system. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 METHODS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=over 4 |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item C<< __PACKAGE__->add_trigger($name:Str, \&code:CodeRef) >> |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item C<< $obj->add_trigger($name:Str, \&code:CodeRef) >> |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
You can register the callback function for the class or object. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
When you register callback code on object, the callback is only registered to object, not for class. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
I<Return Value>: Not defined. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item C<< __PACKAGE__->call_trigger($name:Str); >> |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item C<< $obj->call_trigger($name:Str); >> |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This method calls all callback code for $name. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
I<Return Value>: Not defined. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item C<< __PACKAGE__->get_trigger_code($name:Str) >> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item C<< $obj->get_trigger_code($name:Str) >> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
You can get all of trigger code from the class and ancestors. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=back |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 FAQ |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=over 4 |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item WHY DON'T YOU USE L<Class::Trigger>? |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
L<Class::Trigger> does not support get_trigger_code. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=back |