Wrote meta recipe 5 - metaclass traits
[gitmo/Moose.git] / lib / Moose / Cookbook / Meta / Recipe5.pod
1
2 =pod
3
4 =head1 NAME
5
6 Moose::Cookbook::Meta::Recipe5 - The "table" attribute as a metaclass trait
7
8 =head1 SYNOPSIS
9
10   package MyApp::Meta::Class::Trait::HasTable;
11   use Moose::Role;
12
13   has table =>
14       ( is       => 'rw',
15         isa      => 'Str',
16       );
17
18   package Moose::Meta::Class::Custom::Trait::HasTable;
19   sub register_implementation { 'MyApp::Meta::Class::Trait::HasTable' }
20
21   package MyApp::User;
22   use Moose -traits => 'HasTable';
23
24   __PACKAGE__->table('User');
25
26 =head1 DESCRIPTION
27
28 This recipe takes the metaclass table attribute and reimplements it as
29 a metaclass trait. Traits are just roles that Moose applies to
30 something for you. In this case, that "something" is the class's
31 metaclass object.
32
33 The advantage of using traits is that it's easy to combine multiple
34 traits, whereas combining multiple metaclasses can be tricky (which
35 subclasses which?).
36
37 The disadvantage is that it's not easy to combine a trait with some
38 sort of sugar (like our notional C<has_table> sugar).
39
40 =head2 Using this Metaclass Trait in Practice
41
42 Once this trait has been applied to a metaclass, it looks exactly like
43 the example we saw in L<Moose::Cookbook::Meta::Recipe4>:
44
45   my $table = MyApp::User->meta()->table();
46
47 =head1 SEE ALSO
48
49 L<Moose::Cookbook::Meta::Recipe3> - Labels implemented via attribute
50 traits
51
52 L<Moose::Cookbook::Meta::Recipe4> - Adding a "table" attribute to the
53 metaclass
54
55 =head1 AUTHOR
56
57 Dave Rolsky E<lt>autarch@urth.orgE<gt>
58
59 =head1 COPYRIGHT AND LICENSE
60
61 Copyright 2006-2008 by Infinity Interactive, Inc.
62
63 L<http://www.iinteractive.com>
64
65 This library is free software; you can redistribute it and/or modify
66 it under the same terms as Perl itself.
67
68 =pod