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