lazily load the native trait accessor roles
[gitmo/Moose.git] / lib / Moose / Meta / Attribute / Native / Trait / Code.pm
CommitLineData
952b939d 1package Moose::Meta::Attribute::Native::Trait::Code;
cdf3cae6 2use Moose::Role;
cdf3cae6 3
245478d5 4our $VERSION = '1.19';
cdf3cae6 5$VERSION = eval $VERSION;
6our $AUTHORITY = 'cpan:STEVAN';
7
fc6ef638 8with 'Moose::Meta::Attribute::Native::Trait';
cdf3cae6 9
cdf3cae6 10sub _helper_type { 'CodeRef' }
11
12no Moose::Role;
13
141;
e8953f86 15
16=pod
17
18=head1 NAME
19
8b09d5c3 20Moose::Meta::Attribute::Native::Trait::Code - Helper trait for Code attributes
e8953f86 21
22=head1 SYNOPSIS
23
24 package Foo;
25 use Moose;
26
27 has 'callback' => (
e132fd56 28 traits => ['Code'],
29 is => 'ro',
30 isa => 'CodeRef',
31 default => sub {
32 sub { print "called" }
33 },
34 handles => {
e8953f86 35 call => 'execute',
36 },
37 );
38
39 my $foo = Foo->new;
e132fd56 40 $foo->call; # prints "called"
e8953f86 41
42=head1 DESCRIPTION
43
7795e4de 44This trait provides native delegation methods for code references.
45
46=head1 DEFAULT TYPE
47
48If you don't provide an C<isa> value for your attribute, it will default to
49C<CodeRef>.
e8953f86 50
51=head1 PROVIDED METHODS
52
53=over 4
54
e132fd56 55=item * B<execute(@args)>
e8953f86 56
57Calls the coderef with the given args.
58
e132fd56 59=item * B<execute_method(@args)>
d9299060 60
61Calls the coderef with the the instance as invocant and given args.
62
e8953f86 63=back
64
65=head1 BUGS
66
d4048ef3 67See L<Moose/BUGS> for details on reporting bugs.
e8953f86 68
69=head1 AUTHOR
70
71 Florian Ragwitz <rafl@debian.org>
72
73=head1 COPYRIGHT AND LICENSE
74
75Copyright 2007-2009 by Infinity Interactive, Inc.
76
77L<http://www.iinteractive.com>
78
79This library is free software; you can redistribute it and/or modify
80it under the same terms as Perl itself.
81
82=cut