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