| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MooseX::Role::Callback; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Execute a callback function when a role is applied |
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
923
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
39
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
30
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
461
|
use Moose qw//; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Moose::Exporter; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Moose::Exporter->setup_import_methods( |
|
14
|
|
|
|
|
|
|
with_meta => ['included'], |
|
15
|
|
|
|
|
|
|
role_metaroles => { |
|
16
|
|
|
|
|
|
|
role => ['MooseX::Role::Callback::Meta::Trait'], |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub included { |
|
21
|
|
|
|
|
|
|
my ($meta, $callback) = @_; |
|
22
|
|
|
|
|
|
|
push @{$meta->include_callbacks}, $callback; |
|
23
|
|
|
|
|
|
|
return; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
1; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
__END__ |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=pod |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 NAME |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
MooseX::Role::Callback |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
package Foo; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
use Moose::Role; |
|
41
|
|
|
|
|
|
|
use MooseX::Role::Callback; |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
included(sub { |
|
44
|
|
|
|
|
|
|
my ($meta, $user) = @_; |
|
45
|
|
|
|
|
|
|
print "Foo applied to " . $user->name . "\n"; |
|
46
|
|
|
|
|
|
|
}); |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
package Bar; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
use Moose; |
|
51
|
|
|
|
|
|
|
with 'Foo'; # Prints "Foo applied to Bar" |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Execute a callback function when a role is applied. |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 C<included> |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Registers a function to be called when the role is applied. Takes a single |
|
62
|
|
|
|
|
|
|
coderef as an argument. |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
The function will be passed the role's metaclass and the C<$thing>'s metaclass, |
|
65
|
|
|
|
|
|
|
where C<$thing> can be either class or instance. |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Call multiple times to register multiple callbacks. |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 GITHUB |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Find this project on github: |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
https://github.com/pboyd/MooseX-Role-Callback |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 AUTHOR |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Paul Boyd <pboyd@cpan.org> |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Paul Boyd. |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
84
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |