Commit | Line | Data |
---|---|---|
952b939d | 1 | package Moose::Meta::Attribute::Native::Trait::Code; |
cdf3cae6 | 2 | use Moose::Role; |
cdf3cae6 | 3 | |
fc6ef638 | 4 | with 'Moose::Meta::Attribute::Native::Trait'; |
cdf3cae6 | 5 | |
cdf3cae6 | 6 | sub _helper_type { 'CodeRef' } |
7 | ||
8 | no Moose::Role; | |
9 | ||
10 | 1; | |
e8953f86 | 11 | |
20544c31 | 12 | # ABSTRACT: Helper trait for CodeRef attributes |
13 | ||
14 | __END__ | |
15 | ||
e8953f86 | 16 | =pod |
17 | ||
e8953f86 | 18 | =head1 SYNOPSIS |
19 | ||
20 | package Foo; | |
21 | use Moose; | |
22 | ||
23 | has 'callback' => ( | |
e132fd56 | 24 | traits => ['Code'], |
25 | is => 'ro', | |
26 | isa => 'CodeRef', | |
27 | default => sub { | |
28 | sub { print "called" } | |
29 | }, | |
30 | handles => { | |
e8953f86 | 31 | call => 'execute', |
32 | }, | |
33 | ); | |
34 | ||
35 | my $foo = Foo->new; | |
e132fd56 | 36 | $foo->call; # prints "called" |
e8953f86 | 37 | |
38 | =head1 DESCRIPTION | |
39 | ||
7795e4de | 40 | This trait provides native delegation methods for code references. |
41 | ||
42 | =head1 DEFAULT TYPE | |
43 | ||
44 | If you don't provide an C<isa> value for your attribute, it will default to | |
45 | C<CodeRef>. | |
e8953f86 | 46 | |
47 | =head1 PROVIDED METHODS | |
48 | ||
49 | =over 4 | |
50 | ||
e132fd56 | 51 | =item * B<execute(@args)> |
e8953f86 | 52 | |
53 | Calls the coderef with the given args. | |
54 | ||
e132fd56 | 55 | =item * B<execute_method(@args)> |
d9299060 | 56 | |
57 | Calls the coderef with the the instance as invocant and given args. | |
58 | ||
e8953f86 | 59 | =back |
60 | ||
61 | =head1 BUGS | |
62 | ||
d4048ef3 | 63 | See L<Moose/BUGS> for details on reporting bugs. |
e8953f86 | 64 | |
e8953f86 | 65 | =cut |