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