From: Dave Rolsky Date: Sat, 2 Aug 2008 02:54:52 +0000 (+0000) Subject: Wrote meta recipe 4, a very simple metaclss example. X-Git-Tag: 0_55~17 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3f002851ce52871cd04852ac6f1dfc0fd9295763;p=gitmo%2FMoose.git Wrote meta recipe 4, a very simple metaclss example. I also planned out several more meta recipes. Recipe 5 is pending on merging the metaclass traits branch. Recipe 6 is coming soon. Recipe 7 will come at some point, but needs to come after metaclasses and sugar/importing, since a new meta-instance probably both a new metaclass and a Moose.pm-like interface. --- diff --git a/lib/Moose/Cookbook.pod b/lib/Moose/Cookbook.pod index cd089e4..990961d 100644 --- a/lib/Moose/Cookbook.pod +++ b/lib/Moose/Cookbook.pod @@ -118,11 +118,20 @@ functionality. However, attributes can only have one metaclass. Applying roles to the attribute metaclass lets you provide composable attribute functionality. -=item L - The meta-instance example (TODO) +=item L - Adding a "table" attribute to the metaclass + +If you want to store more information about your classes, you'll have +to extend C. Doing so is simple, but you'll +probably also want to provide some sugar, so see +L as well. + +=item L - The "table" attribute implemented via a metaclass trait I -=item L - The meta-class example (TODO) +=item L - Acting like Moose.pm and providing sugar Moose-style + +=item L - I (TODO) I diff --git a/lib/Moose/Cookbook/Meta/Recipe4.pod b/lib/Moose/Cookbook/Meta/Recipe4.pod new file mode 100644 index 0000000..c7231bf --- /dev/null +++ b/lib/Moose/Cookbook/Meta/Recipe4.pod @@ -0,0 +1,64 @@ + +=pod + +=head1 NAME + +Moose::Cookbook::Meta::Recipe4 - Adding a "table" attribute to the metaclass + +=head1 SYNOPSIS + + package MyApp::Meta::Class; + use Moose; + extends 'Moose::Meta::Class'; + + has table => + ( is => 'rw', + isa => 'Str', + ); + +=head1 DESCRIPTION + +In this recipe, we'll create a new metaclass which has a "table" +attribute. This metaclass is for classes associated with a DBMS table, +as one might do for an ORM. + +In this example, the table name is just a string, but in a real ORM +the table might be an object describing the table. + +=head1 THE METACLASS + +The metaclass example really is as simple as the one in the +synopsis. The trick is getting your classes to use this metaclass, and +providing some sort of sugar for declaring the table. This is covered +in L, which shows how to make a module +like C itself, with sugar like C. + +=head2 Using It + +Using this new "table" attribute is quite simple. Let's say we have a +class named C, we could simply write the following: + + my $table = MyApp::User->meta()->table(); + +As long as MyApp::User has arranged to use C as +its metaclass, this method call just works. + +=head1 SEE ALSO + +L - The "table" attribute implemented +via a metaclass trait + +=head1 AUTHOR + +Dave Rolsky Eautarch@urth.orgE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006-2008 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=pod