Commit | Line | Data |
952b939d |
1 | package Moose::Meta::Attribute::Native::Trait::Code; |
cdf3cae6 |
2 | use Moose::Role; |
cdf3cae6 |
3 | |
b6cca0d5 |
4 | our $VERSION = '1.14'; |
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' => ( |
31 | traits => ['Code'], |
32 | is => 'ro', |
33 | isa => 'CodeRef', |
34 | default => sub { sub { print "called" } }, |
35 | handles => { |
36 | call => 'execute', |
37 | }, |
38 | ); |
39 | |
40 | my $foo = Foo->new; |
41 | $foo->call; # prints "called" |
42 | |
43 | |
44 | =head1 DESCRIPTION |
45 | |
46 | This provides operations on coderef attributes. |
47 | |
48 | =head1 PROVIDED METHODS |
49 | |
50 | =over 4 |
51 | |
52 | =item B<execute(@args)> |
53 | |
54 | Calls the coderef with the given args. |
55 | |
d9299060 |
56 | =item B<execute_method(@args)> |
57 | |
58 | Calls the coderef with the the instance as invocant and given args. |
59 | |
e8953f86 |
60 | =back |
61 | |
b86a4688 |
62 | =head1 METHODS |
63 | |
64 | =over 4 |
65 | |
66 | =item B<meta> |
67 | |
b86a4688 |
68 | =back |
69 | |
e8953f86 |
70 | =head1 BUGS |
71 | |
d4048ef3 |
72 | See L<Moose/BUGS> for details on reporting bugs. |
e8953f86 |
73 | |
74 | =head1 AUTHOR |
75 | |
76 | Florian Ragwitz <rafl@debian.org> |
77 | |
78 | =head1 COPYRIGHT AND LICENSE |
79 | |
80 | Copyright 2007-2009 by Infinity Interactive, Inc. |
81 | |
82 | L<http://www.iinteractive.com> |
83 | |
84 | This library is free software; you can redistribute it and/or modify |
85 | it under the same terms as Perl itself. |
86 | |
87 | =cut |