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