[Bast-commits] r5379 - DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual
jmmills at dev.catalyst.perl.org
jmmills at dev.catalyst.perl.org
Fri Jan 30 01:37:01 GMT 2009
Author: jmmills
Date: 2009-01-30 01:37:01 +0000 (Fri, 30 Jan 2009)
New Revision: 5379
Modified:
DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/FAQ.pod
Log:
Added a more verbose non column accessor example.
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/FAQ.pod
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/FAQ.pod 2009-01-29 21:14:10 UTC (rev 5378)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/FAQ.pod 2009-01-30 01:37:01 UTC (rev 5379)
@@ -428,6 +428,41 @@
You can add your own data accessors to your classes.
+One method is to use the built in mk_group_accessors (via L<Class::Accessor::Grouped>)
+
+ package MyTable;
+
+ use parent 'DBIx::Class';
+
+ __PACKAGE__->table('foo'); #etc
+ __PACKAGE__->mk_group_accessors('simple' => qw/non_column_data/); # must use simple group
+
+An another method is to use L<Moose> with your L<DBIx::Class> package.
+
+ package MyTable;
+
+ use Moose; # import Moose
+ use Moose::Util::TypeConstraint; # import Moose accessor type constraints
+
+ extends 'DBIx::Class'; # Moose changes the way we define our parent (base) package
+
+ has 'non_column_data' => ( is => 'rw', isa => 'Str' ); # define a simple attribute
+
+ __PACKAGE__->table('foo'); # etc
+
+With either of these methods the resulting use of the accesssor would be
+
+ my $row;
+
+ # assume that some where in her $row will get assigned to a MyTable row
+
+ $row->non_column_data('some string'); # would set the non_column_data accessor
+
+ # some other stuff happens here
+
+ $row->update(); # would not inline the non_column_data accessor into the update
+
+
=item How do I use DBIx::Class objects in my TT templates?
Like normal objects, mostly. However you need to watch out for TT
More information about the Bast-commits
mailing list