[Bast-commits] r6271 - DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual

abraxxa at dev.catalyst.perl.org abraxxa at dev.catalyst.perl.org
Fri May 15 11:45:55 GMT 2009


Author: abraxxa
Date: 2009-05-15 11:45:54 +0000 (Fri, 15 May 2009)
New Revision: 6271

Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/Cookbook.pod
Log:
added Static sub-classing DBIx::Class result classes section to the cookbook


Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/Cookbook.pod
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/Cookbook.pod	2009-05-15 09:45:00 UTC (rev 6270)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/Cookbook.pod	2009-05-15 11:45:54 UTC (rev 6271)
@@ -733,6 +733,48 @@
     # do whatever else you wanted if it was a new row
   }
 
+=head2 Static sub-classing DBIx::Class result classes 
+
+AKA adding additional relationships/methods/etc. to a model for a
+specific usage of the (shared) model.
+
+B<Schema definition> 
+ 
+    package My::App::Schema; 
+     
+    use base DBIx::Class::Schema; 
+
+    # load subclassed classes from My::App::Schema::Result/ResultSet
+    __PACKAGE__->load_namespaces;
+
+    # load classes from shared model
+    load_classes({
+        'My::Shared::Model::Result' => [qw/
+            Foo
+            Bar
+        /]});
+
+    1;
+ 
+B<Result-Subclass definition> 
+ 
+    package My::App::Schema::Result::Baz;
+     
+    use strict; 
+    use warnings; 
+    use base My::Shared::Model::Result::Baz; 
+    
+    # WARNING: Make sure you call table() again in your subclass,
+    # otherwise DBIx::Class::ResultSourceProxy::Table will not be called
+    # and the class name is not correctly registered as a source
+    __PACKAGE__->table('baz'); 
+     
+    sub additional_method { 
+        return "I'm an additional method only needed by this app"; 
+    }
+
+    1;
+     
 =head2 Dynamic Sub-classing DBIx::Class proxy classes 
 
 AKA multi-class object inflation from one table
@@ -760,7 +802,9 @@
      
     use base qw/DBIx::Class::Schema/; 
  
-    __PACKAGE__->load_namespaces; 
+    __PACKAGE__->load_namespaces;
+
+    1;
  
  
 B<Proxy-Class definitions> 
@@ -798,8 +842,10 @@
         print "I am a regular user.\n"; 
         return ; 
     } 
+    
+    1;
+
      
-     
     package My::Schema::Result::User::Admin; 
      
     use strict; 
@@ -816,7 +862,9 @@
     { 
         print "I am doing admin stuff\n"; 
         return ; 
-    } 
+    }
+
+    1;
  
 B<Test File> test.pl 
  




More information about the Bast-commits mailing list