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