6 Moose::Cookbook::Meta::Recipe5 - The "table" attribute as a metaclass trait
10 package MyApp::Meta::Class::Trait::HasTable;
18 package Moose::Meta::Class::Custom::Trait::HasTable;
19 sub register_implementation { 'MyApp::Meta::Class::Trait::HasTable' }
22 use Moose -traits => 'HasTable';
24 __PACKAGE__->table('User');
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
33 The advantage of using traits is that it's easy to combine multiple
34 traits, whereas combining multiple metaclasses can be tricky (which
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).
40 =head2 Using this Metaclass Trait in Practice
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>:
45 my $table = MyApp::User->meta()->table();
49 L<Moose::Cookbook::Meta::Recipe3> - Labels implemented via attribute
52 L<Moose::Cookbook::Meta::Recipe4> - Adding a "table" attribute to the
57 Dave Rolsky E<lt>autarch@urth.orgE<gt>
59 =head1 COPYRIGHT AND LICENSE
61 Copyright 2006-2008 by Infinity Interactive, Inc.
63 L<http://www.iinteractive.com>
65 This library is free software; you can redistribute it and/or modify
66 it under the same terms as Perl itself.