efff8d72a9d7784300bf3699e11a193ea84390ac
[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.9900';
5 $VERSION = eval $VERSION;
6 our $AUTHORITY = 'cpan:STEVAN';
7
8 with 'Moose::Meta::Attribute::Native::Trait';
9
10 sub _helper_type { 'CodeRef' }
11
12 no Moose::Role;
13
14 1;
15
16 =pod
17
18 =head1 NAME
19
20 Moose::Meta::Attribute::Native::Trait::Code - Helper trait for Code attributes
21
22 =head1 SYNOPSIS
23
24   package Foo;
25   use Moose;
26
27   has 'callback' => (
28       traits  => ['Code'],
29       is      => 'ro',
30       isa     => 'CodeRef',
31       default => sub {
32           sub { print "called" }
33       },
34       handles => {
35           call => 'execute',
36       },
37   );
38
39   my $foo = Foo->new;
40   $foo->call;    # prints "called"
41
42 =head1 DESCRIPTION
43
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>.
50
51 =head1 PROVIDED METHODS
52
53 =over 4
54
55 =item * B<execute(@args)>
56
57 Calls the coderef with the given args.
58
59 =item * B<execute_method(@args)>
60
61 Calls the coderef with the the instance as invocant and given args.
62
63 =back
64
65 =head1 BUGS
66
67 See L<Moose/BUGS> for details on reporting bugs.
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