[Rt-commit] r2991 - in DBIx-SearchBuilder/trunk: . SearchBuilder

glasser at bestpractical.com glasser at bestpractical.com
Mon May 30 23:23:43 EDT 2005


Author: glasser
Date: Mon May 30 23:23:43 2005
New Revision: 2991

Modified:
   DBIx-SearchBuilder/trunk/   (props changed)
   DBIx-SearchBuilder/trunk/SearchBuilder/Record.pm
Log:
 r33522 at stratton-five-seventy:  glasser | 2005-05-30 23:23:10 -0400
 Generate _ClassAccessible from Schema, if there is a Schema


Modified: DBIx-SearchBuilder/trunk/SearchBuilder/Record.pm
==============================================================================
--- DBIx-SearchBuilder/trunk/SearchBuilder/Record.pm	(original)
+++ DBIx-SearchBuilder/trunk/SearchBuilder/Record.pm	Mon May 30 23:23:43 2005
@@ -538,8 +538,10 @@
 
 =head2 _ClassAccessible 
 
-Preferred and most efficient way to specify fields attributes in a derived
-class. 
+An older way to specify fields attributes in a derived class.
+(The current preferred method is by overriding C<Schema>; if you do
+this and don't override C<_ClassAccessible>, the module will generate
+an appropriate C<_ClassAccessible> based on your C<Schema>.)
 
 Here's an example declaration:
 
@@ -553,11 +555,15 @@
 
 =cut
 
-# XXX This is stub code to deal with the old way we used to do _Accessible
-# It should never be called by modern code
 
 sub _ClassAccessible {
   my $self = shift;
+  
+  return $self->_ClassAccessibleFromSchema if $self->can('Schema');
+  
+  # XXX This is stub code to deal with the old way we used to do _Accessible
+  # It should never be called by modern code
+  
   my %accessible;
   while ( my $col = shift ) {
     $accessible{$col}->{lc($_)} = 1
@@ -566,6 +572,25 @@
   return(\%accessible);
 }
 
+sub _ClassAccessibleFromSchema {
+  my $self = shift;
+  
+  my $accessible = {
+    # XXX TODO FIXME: should fetch custom primary key name
+    'id' => { 'read' => 1 },
+  };
+  
+  my $schema = $self->Schema;
+  
+  for my $field (keys %$schema) {
+    next unless $schema->{$field}{'TYPE'} or $schema->{$field}{'REFERENCES'};
+    
+    $accessible->{$field} = { 'read' => 1, 'write' => 1 };
+  }
+  
+  return $accessible;  
+}
+
 # }}}
 
 # sub {{{ ReadableAttributes


More information about the Rt-commit mailing list