Commit | Line | Data |
952b939d |
1 | package Moose::Meta::Attribute::Native::Trait::Code; |
cdf3cae6 |
2 | use Moose::Role; |
952b939d |
3 | use Moose::Meta::Attribute::Native::MethodProvider::Code; |
cdf3cae6 |
4 | |
3eb89f70 |
5 | our $VERSION = '1.01'; |
cdf3cae6 |
6 | $VERSION = eval $VERSION; |
7 | our $AUTHORITY = 'cpan:STEVAN'; |
8 | |
952b939d |
9 | with 'Moose::Meta::Attribute::Native::Trait'; |
cdf3cae6 |
10 | |
11 | has method_provider => ( |
12 | is => 'ro', |
13 | isa => 'ClassName', |
14 | predicate => 'has_method_provider', |
952b939d |
15 | default => 'Moose::Meta::Attribute::Native::MethodProvider::Code', |
cdf3cae6 |
16 | ); |
17 | |
cdf3cae6 |
18 | sub _helper_type { 'CodeRef' } |
19 | |
20 | no Moose::Role; |
21 | |
22 | 1; |
e8953f86 |
23 | |
24 | =pod |
25 | |
26 | =head1 NAME |
27 | |
8b09d5c3 |
28 | Moose::Meta::Attribute::Native::Trait::Code - Helper trait for Code attributes |
e8953f86 |
29 | |
30 | =head1 SYNOPSIS |
31 | |
32 | package Foo; |
33 | use Moose; |
34 | |
35 | has 'callback' => ( |
36 | traits => ['Code'], |
37 | is => 'ro', |
38 | isa => 'CodeRef', |
39 | default => sub { sub { print "called" } }, |
40 | handles => { |
41 | call => 'execute', |
42 | }, |
43 | ); |
44 | |
45 | my $foo = Foo->new; |
46 | $foo->call; # prints "called" |
47 | |
48 | |
49 | =head1 DESCRIPTION |
50 | |
51 | This provides operations on coderef attributes. |
52 | |
53 | =head1 PROVIDED METHODS |
54 | |
55 | =over 4 |
56 | |
57 | =item B<execute(@args)> |
58 | |
59 | Calls the coderef with the given args. |
60 | |
d9299060 |
61 | =item B<execute_method(@args)> |
62 | |
63 | Calls the coderef with the the instance as invocant and given args. |
64 | |
e8953f86 |
65 | =back |
66 | |
b86a4688 |
67 | =head1 METHODS |
68 | |
69 | =over 4 |
70 | |
71 | =item B<meta> |
72 | |
73 | =item B<method_provider> |
74 | |
75 | =item B<has_method_provider> |
76 | |
77 | =back |
78 | |
e8953f86 |
79 | =head1 BUGS |
80 | |
d4048ef3 |
81 | See L<Moose/BUGS> for details on reporting bugs. |
e8953f86 |
82 | |
83 | =head1 AUTHOR |
84 | |
85 | Florian Ragwitz <rafl@debian.org> |
86 | |
87 | =head1 COPYRIGHT AND LICENSE |
88 | |
89 | Copyright 2007-2009 by Infinity Interactive, Inc. |
90 | |
91 | L<http://www.iinteractive.com> |
92 | |
93 | This library is free software; you can redistribute it and/or modify |
94 | it under the same terms as Perl itself. |
95 | |
96 | =cut |