Commit | Line | Data |
3f002851 |
1 | |
2 | =pod |
3 | |
4 | =head1 NAME |
5 | |
6 | Moose::Cookbook::Meta::Recipe4 - Adding a "table" attribute to the metaclass |
7 | |
8 | =head1 SYNOPSIS |
9 | |
10 | package MyApp::Meta::Class; |
11 | use Moose; |
12 | extends 'Moose::Meta::Class'; |
13 | |
14 | has table => |
15 | ( is => 'rw', |
16 | isa => 'Str', |
17 | ); |
18 | |
19 | =head1 DESCRIPTION |
20 | |
21 | In this recipe, we'll create a new metaclass which has a "table" |
22 | attribute. This metaclass is for classes associated with a DBMS table, |
23 | as one might do for an ORM. |
24 | |
25 | In this example, the table name is just a string, but in a real ORM |
26 | the table might be an object describing the table. |
27 | |
28 | =head1 THE METACLASS |
29 | |
30 | The metaclass example really is as simple as the one in the |
31 | synopsis. The trick is getting your classes to use this metaclass, and |
32 | providing some sort of sugar for declaring the table. This is covered |
33 | in L<Moose::Cookbook::Meta::Recipe5>, which shows how to make a module |
34 | like C<Moose.pm> itself, with sugar like C<has_table()>. |
35 | |
36 | =head2 Using It |
37 | |
38 | Using this new "table" attribute is quite simple. Let's say we have a |
39 | class named C<MyApp::User>, we could simply write the following: |
40 | |
41 | my $table = MyApp::User->meta()->table(); |
42 | |
43 | As long as MyApp::User has arranged to use C<MyApp::Meta::Class> as |
44 | its metaclass, this method call just works. |
45 | |
46 | =head1 SEE ALSO |
47 | |
48 | L<Moose::Cookbook::Meta::Recipe5> - The "table" attribute implemented |
49 | via a metaclass trait |
50 | |
51 | =head1 AUTHOR |
52 | |
53 | Dave Rolsky E<lt>autarch@urth.orgE<gt> |
54 | |
55 | =head1 COPYRIGHT AND LICENSE |
56 | |
57 | Copyright 2006-2008 by Infinity Interactive, Inc. |
58 | |
59 | L<http://www.iinteractive.com> |
60 | |
61 | This library is free software; you can redistribute it and/or modify |
62 | it under the same terms as Perl itself. |
63 | |
64 | =pod |