line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::MethodAttributes::Role::Meta::Role::Application; |
2
|
|
|
|
|
|
|
# ABSTRACT: generic role for applying a role with method attributes to something |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.30'; |
5
|
|
|
|
|
|
|
|
6
|
21
|
|
|
21
|
|
19221
|
use Moose::Role; |
|
21
|
|
|
|
|
47
|
|
|
21
|
|
|
|
|
187
|
|
7
|
21
|
|
|
21
|
|
109467
|
use Moose::Util qw/find_meta/; |
|
21
|
|
|
|
|
50
|
|
|
21
|
|
|
|
|
161
|
|
8
|
21
|
|
|
21
|
|
4038
|
use MooseX::MethodAttributes (); |
|
21
|
|
|
|
|
46
|
|
|
21
|
|
|
|
|
366
|
|
9
|
21
|
|
|
21
|
|
115
|
use MooseX::MethodAttributes::Role (); |
|
21
|
|
|
|
|
45
|
|
|
21
|
|
|
|
|
426
|
|
10
|
21
|
|
|
21
|
|
109
|
use Carp qw/croak/; |
|
21
|
|
|
|
|
65
|
|
|
21
|
|
|
|
|
1447
|
|
11
|
21
|
|
|
21
|
|
113
|
use namespace::autoclean; |
|
21
|
|
|
|
|
37
|
|
|
21
|
|
|
|
|
266
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
requires qw/ |
14
|
|
|
|
|
|
|
_copy_attributes |
15
|
|
|
|
|
|
|
apply |
16
|
|
|
|
|
|
|
/; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#pod =method apply |
19
|
|
|
|
|
|
|
#pod |
20
|
|
|
|
|
|
|
#pod The apply method is wrapped to ensure that the correct metaclasses to hold and propagate |
21
|
|
|
|
|
|
|
#pod method attribute data are present on the target for role application, delegates to |
22
|
|
|
|
|
|
|
#pod the original method to actually apply the role, then ensures that any attributes from |
23
|
|
|
|
|
|
|
#pod the role are copied to the target class. |
24
|
|
|
|
|
|
|
#pod |
25
|
|
|
|
|
|
|
#pod =cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
around 'apply' => sub { |
28
|
|
|
|
|
|
|
my ($orig, $self, $thing, %opts) = @_; |
29
|
|
|
|
|
|
|
$thing = $self->_apply_metaclasses($thing); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $ret = $self->$orig($thing, %opts); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$self->_copy_attributes($thing); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
return $ret; |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _apply_metaclasses { |
39
|
15
|
|
|
15
|
|
38
|
my ($self, $thing) = @_; |
40
|
15
|
100
|
|
|
|
123
|
if ($thing->isa('Moose::Meta::Class')) { |
|
|
50
|
|
|
|
|
|
41
|
13
|
|
|
|
|
154
|
$thing = MooseX::MethodAttributes->init_meta( for_class => $thing->name ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
elsif ($thing->isa('Moose::Meta::Role')) { |
44
|
2
|
|
|
|
|
45
|
$thing = MooseX::MethodAttributes::Role->init_meta( for_class => $thing->name ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
0
|
|
|
|
|
0
|
croak("Composing " . __PACKAGE__ . " onto instances is unsupported"); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Note that the metaclass instance we started out with may have been turned |
51
|
|
|
|
|
|
|
# into lies by the metatrait role application process, so we explicitly |
52
|
|
|
|
|
|
|
# re-fetch it here. |
53
|
|
|
|
|
|
|
|
54
|
15
|
|
|
|
|
4172
|
return find_meta($thing->name); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=pod |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=encoding UTF-8 |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 NAME |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
MooseX::MethodAttributes::Role::Meta::Role::Application - generic role for applying a role with method attributes to something |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 VERSION |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
version 0.30 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 METHODS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 apply |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
The apply method is wrapped to ensure that the correct metaclasses to hold and propagate |
78
|
|
|
|
|
|
|
method attribute data are present on the target for role application, delegates to |
79
|
|
|
|
|
|
|
the original method to actually apply the role, then ensures that any attributes from |
80
|
|
|
|
|
|
|
the role are copied to the target class. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 AUTHORS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=over 4 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item * |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item * |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Tomas Doran <bobtfish@bobtfish.net> |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=back |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This software is copyright (c) 2009 by Florian Ragwitz. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
101
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |