[Rt-commit] r3906 - in Jifty-DBI/trunk: . lib/Jifty/DBI

alexmv at bestpractical.com alexmv at bestpractical.com
Wed Oct 5 00:13:10 EDT 2005


Author: alexmv
Date: Wed Oct  5 00:13:09 2005
New Revision: 3906

Modified:
   Jifty-DBI/trunk/   (props changed)
   Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm
   Jifty-DBI/trunk/lib/Jifty/DBI/Column.pm
   Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm
   Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm
   Jifty-DBI/trunk/lib/Jifty/DBI/SchemaGenerator.pm
Log:
 r6619 at zoq-fot-pik:  chmrr | 2005-10-05 00:11:01 -0400
  * More column properties (should get pushed into JFDI)
  * Column alias fixes
  * Fix unreadable columns


Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm	Wed Oct  5 00:13:09 2005
@@ -1432,7 +1432,6 @@
     my $class = shift;
     my (%args) = @_;
 
-    warn "Check if $class can $args{by}\n";
     return (refers_to => $class, %args);
 }
 

Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Column.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Column.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Column.pm	Wed Oct  5 00:13:09 2005
@@ -16,6 +16,10 @@
     null
     refers_to by
     alias_for_column
+    since until
+
+    label hints render_as
+    valid_values
     /;
 
 

Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm	Wed Oct  5 00:13:09 2005
@@ -288,7 +288,7 @@
 
 sub AUTOLOAD {
     my $self = $_[0];
-
+    
     $self->_init_columns() unless $self->COLUMNS;
 
     my ( $column_name, $action ) = $self->_parse_autoload_method($AUTOLOAD);
@@ -306,7 +306,8 @@
     }
 
     no strict 'refs'; # We're going to be defining subs
-    if ( $action eq 'read' and $column->readable ) {
+    if ( $action eq 'read' ) {
+        return '' unless $column->readable;
 
         if ( UNIVERSAL::isa($column->refers_to, "Jifty::DBI::Record") ) {
             *{$AUTOLOAD}
@@ -320,29 +321,25 @@
         }
         goto &$AUTOLOAD;
     }
+    elsif ( $action eq 'write' ) {
+        return (0, 'Immutable field') unless $column->writable;
 
-    if ( $action eq 'write' ) {
-        if ( $column->writable ) {
-
-            if ( UNIVERSAL::isa($column->refers_to, "Jifty::DBI::Record") ) {
-                *{$AUTOLOAD} = sub {
-                    my $self = shift;
-                    my $val  = shift;
-
-                    $val = $val->id
-                        if UNIVERSAL::isa( $val, 'Jifty::DBI::Record' );
-                    return ( $self->_set( column => $column_name, value => $val ) );
-                };
-            }
-            else {
-                *{$AUTOLOAD} = sub {
-                    return ( $_[0]->_set( column => $column_name, value => $_[1] ) );
-                };
-            }
-            goto &$AUTOLOAD;
-        } else {
-            return (0, 'Immutable field');
+        if ( UNIVERSAL::isa($column->refers_to, "Jifty::DBI::Record") ) {
+            *{$AUTOLOAD} = sub {
+                my $self = shift;
+                my $val  = shift;
+
+                $val = $val->id
+                  if UNIVERSAL::isa( $val, 'Jifty::DBI::Record' );
+                return ( $self->_set( column => $column_name, value => $val ) );
+            };
         }
+        else {
+            *{$AUTOLOAD} = sub {
+                return ( $_[0]->_set( column => $column_name, value => $_[1] ) );
+            };
+        }
+        goto &$AUTOLOAD;
     }
     elsif ( $action eq 'validate' ) {
         *{$AUTOLOAD}
@@ -352,7 +349,6 @@
 
     else {
         my ( $package, $filename, $line ) = caller;
-
         die "$AUTOLOAD Unimplemented in $package. ($filename line $line) \n";
     }
 
@@ -477,19 +473,15 @@
     my $column_name = shift;
     my $value = shift;
 
-
-
     my $column = $self->column($column_name);
     my $classname = $column->refers_to();
 
-
     return unless defined $value;
     return undef unless $classname;
     return unless UNIVERSAL::isa( $classname, 'Jifty::DBI::Record' );
 
     # XXX TODO FIXME we need to figure out the right way to call new here
     # perhaps the handle should have an initiializer for records/collections
-
     my $object = $classname->new( $self->_handle );
     $object->load_by_cols(id => $value);
     return $object;

Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm	Wed Oct  5 00:13:09 2005
@@ -1,6 +1,6 @@
 package Jifty::DBI::Schema;
 use Exporter::Lite;
-our @EXPORT = qw(column type default validator immutable length not_null valid_values input_filters output_filters mandatory is by are on);
+our @EXPORT = qw(column type default validator immutable unreadable length not_null valid_values label hints render_as since input_filters output_filters mandatory is by are on);
 
 our $SCHEMA;
 sub column {
@@ -16,6 +16,7 @@
                 null     => 1,
                 @_,
                );
+    my @original = @args;
 
     my $column = Jifty::DBI::Column->new();
     while (@args) {
@@ -30,13 +31,13 @@
         if ( UNIVERSAL::isa( $refclass, 'Jifty::DBI::Record' ) ) {
             if ( $name =~ /(.*)_id$/ ) {
                 my $virtual_column = $from->add_column($1);
-                $virtual_column->refers_to($refclass);
+                while (@original) {
+                    my ($method, $arguments) = splice @original, 0, 2;
+                    $virtual_column->$method($arguments);
+                }
+                $column->refers_to(undef);
                 $virtual_column->alias_for_column($name);
             }
-            else {
-                $column->refers_to($refclass);
-            }
-
         }
         elsif ( UNIVERSAL::isa( $refclass, 'Jifty::DBI::Collection' ) ) {
             $column->by('id') unless $column->by;
@@ -65,6 +66,10 @@
     return ([writable => 0]);
 }
 
+sub unreadable {
+    return ([readable => 0]);
+}
+
 sub length ($) {
     return (length => shift);
 }
@@ -82,6 +87,9 @@
 }
 
 
+sub since ($) {
+    return (since => shift);
+}
 
 sub mandatory () {
     return ([mandatory => 1]);
@@ -91,6 +99,17 @@
     return (valid_values => shift);
 }
 
+sub label ($) {
+    return (label => shift);
+}
+
+sub hints ($) {
+    return (hints => shift);
+}
+
+sub render_as ($) {
+    return (render_as => shift);
+}
 
 
 sub is ($) {

Modified: Jifty-DBI/trunk/lib/Jifty/DBI/SchemaGenerator.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/SchemaGenerator.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/SchemaGenerator.pm	Wed Oct  5 00:13:09 2005
@@ -189,11 +189,12 @@
     for my $column ( sort {$a->name cmp $b->name} @columns) {
         # Skip foreign keys
         next if defined $column->refers_to and defined $column->by;
+        next if defined $column->alias_for_column;
 
         push @cols,
             DBIx::DBSchema::Column->new(
             {   name    => $column->name,
-                type    => $column->name,
+                type    => $column->type,
                 null    => $column->null,
                 default => $column->default,
             }


More information about the Rt-commit mailing list