Beginning of dzilization
[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 $AUTHORITY = 'cpan:STEVAN';
5
6 with 'Moose::Meta::Attribute::Native::Trait';
7
8 sub _helper_type { 'CodeRef' }
9
10 no Moose::Role;
11
12 1;
13
14 =pod
15
16 =head1 SYNOPSIS
17
18   package Foo;
19   use Moose;
20
21   has 'callback' => (
22       traits  => ['Code'],
23       is      => 'ro',
24       isa     => 'CodeRef',
25       default => sub {
26           sub { print "called" }
27       },
28       handles => {
29           call => 'execute',
30       },
31   );
32
33   my $foo = Foo->new;
34   $foo->call;    # prints "called"
35
36 =head1 DESCRIPTION
37
38 This trait provides native delegation methods for code references.
39
40 =head1 DEFAULT TYPE
41
42 If you don't provide an C<isa> value for your attribute, it will default to
43 C<CodeRef>.
44
45 =head1 PROVIDED METHODS
46
47 =over 4
48
49 =item * B<execute(@args)>
50
51 Calls the coderef with the given args.
52
53 =item * B<execute_method(@args)>
54
55 Calls the coderef with the the instance as invocant and given args.
56
57 =back
58
59 =head1 BUGS
60
61 See L<Moose/BUGS> for details on reporting bugs.
62
63 =cut