[Jifty-commit] r2570 - in Jifty-DBI/branches/od: lib/Jifty/DBI t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri Jan 26 06:28:15 EST 2007
Author: audreyt
Date: Fri Jan 26 06:27:28 2007
New Revision: 2570
Modified:
Jifty-DBI/branches/od/lib/Jifty/DBI/Collection.pm
Jifty-DBI/branches/od/lib/Jifty/DBI/Column.pm
Jifty-DBI/branches/od/lib/Jifty/DBI/Filter/Truncate.pm
Jifty-DBI/branches/od/lib/Jifty/DBI/Record.pm
Jifty-DBI/branches/od/lib/Jifty/DBI/Schema.pm
Jifty-DBI/branches/od/t/11schema_records.t
Log:
* Completely finish porting Jifty::DBI::Schema to use Object::Declare.
Visible differences are:
- "refers App::Class" is now an alias for "refers_to App::Class".
- In refers/refers_to it is no longer neccessary to load App::Class
beforehand; therefore circular references can now be expressed.
- "length is 30" is now invalid; a compile-time exception will be
raised that tells the user to use "maxlength id 40" instead.
Modified: Jifty-DBI/branches/od/lib/Jifty/DBI/Collection.pm
==============================================================================
--- Jifty-DBI/branches/od/lib/Jifty/DBI/Collection.pm (original)
+++ Jifty-DBI/branches/od/lib/Jifty/DBI/Collection.pm Fri Jan 26 06:27:28 2007
@@ -1754,17 +1754,6 @@
return $self->{table};
}
-=head2 refers_to
-
-Private convenience method needed for the declarative schema generation.
-
-=cut
-
-sub refers_to {
- my $class = shift;
- return ( Jifty::DBI::Schema::Trait->new( refers_to => $class ), @_ );
-}
-
=head2 clone
Returns copy of the current object with all search restrictions.
Modified: Jifty-DBI/branches/od/lib/Jifty/DBI/Column.pm
==============================================================================
--- Jifty-DBI/branches/od/lib/Jifty/DBI/Column.pm (original)
+++ Jifty-DBI/branches/od/lib/Jifty/DBI/Column.pm Fri Jan 26 06:27:28 2007
@@ -12,7 +12,7 @@
type
default
readable writable
- length
+ max_length
mandatory
virtual
distinct
@@ -76,4 +76,6 @@
*read = \&readable;
*write = \&writable;
+sub length { Carp::croak('$column->length is no longer supported; use $column->max_length instead') }
+
1;
Modified: Jifty-DBI/branches/od/lib/Jifty/DBI/Filter/Truncate.pm
==============================================================================
--- Jifty-DBI/branches/od/lib/Jifty/DBI/Filter/Truncate.pm (original)
+++ Jifty-DBI/branches/od/lib/Jifty/DBI/Filter/Truncate.pm Fri Jan 26 06:27:28 2007
@@ -15,8 +15,8 @@
my $column = $self->column();
my $truncate_to;
- if ( $column->length && !$column->is_numeric ) {
- $truncate_to = $column->length;
+ if ( $column->max_length && !$column->is_numeric ) {
+ $truncate_to = $column->max_length;
} elsif ( $column->type && $column->type =~ /char\((\d+)\)/ ) {
$truncate_to = $1;
}
Modified: Jifty-DBI/branches/od/lib/Jifty/DBI/Record.pm
==============================================================================
--- Jifty-DBI/branches/od/lib/Jifty/DBI/Record.pm (original)
+++ Jifty-DBI/branches/od/lib/Jifty/DBI/Record.pm Fri Jan 26 06:27:28 2007
@@ -183,6 +183,7 @@
$column->readable(1);
$column->type('serial');
$column->mandatory(1);
+
$self->_init_methods_for_column($column);
}
}
@@ -329,6 +330,7 @@
return $prefetched_col;
}
+ use Devel::SimpleTrace;
my $coll = $classname->new( handle => $self->_handle );
$coll->limit( column => $column->by(), value => $self->id );
return $coll;
@@ -1162,12 +1164,6 @@
=cut
-sub refers_to {
- my $class = shift;
- die 'broken';
- return ( Jifty::DBI::Schema::Trait->new(refers_to => $class), @_ );
-}
-
sub _filters {
my $self = shift;
my %args = ( direction => 'input', column => undef, @_ );
Modified: Jifty-DBI/branches/od/lib/Jifty/DBI/Schema.pm
==============================================================================
--- Jifty-DBI/branches/od/lib/Jifty/DBI/Schema.pm (original)
+++ Jifty-DBI/branches/od/lib/Jifty/DBI/Schema.pm Fri Jan 26 06:27:28 2007
@@ -52,25 +52,72 @@
valid => 'valid_values',
render => 'render_as',
order => 'sort_order',
- max_length => 'length',
filters => 'input_filters',
},
copula => {
- is => '',
- are => '',
- as => '',
- by => '',
- ajax => 'ajax_',
+ is => '',
+ are => '',
+ as => '',
+ ajax => 'ajax_',
+ refers_to => sub { refers_to => @_ },
+ refers => sub { refers_to => @_ },
}
);
-use Exporter::Lite;
use Class::Data::Inheritable;
-our @EXPORT = qw( defer lazy column schema );
+our @EXPORT = qw( defer lazy column schema by );
our $SCHEMA;
our $SORT_ORDERS = {};
+use Exporter::Lite ();
+# TODO - This "sub import" is strictly here to catch the deprecated "length is 40".
+# Once the deprecation cycle is over we should take this away and rever to
+# "use Exporter::Lite" in the line above.
+sub import {
+ my $old_sig_die = $SIG{__DIE__};
+
+ $SIG{__DIE__} = sub {
+ if (!@_) {
+ # Calling it by hand means we restore the old sighandler.
+ $SIG{__DIE__} = $old_sig_die;
+ return;
+ }
+
+ if ($_[0] =~ /near "is (\d+)"/) {
+ push @_, << ".";
+
+*********************************************************
+
+ Due to an incompatible API change, the "length" field in
+ Jifty::DBI columns has been renamed to "max_length".
+
+ Instead of this:
+
+ column foo =>
+ length is $1; # NOT VALID
+
+ Please write this instead:
+
+ column foo =>
+ max_length is $1 # VALID
+
+ Sorry for the inconvenience.
+
+**********************************************************
+
+
+.
+ }
+
+ die @_;
+ };
+
+ goto &Exporter::Lite::import;
+}
+
+sub by { @_ }
+
=head1 FUNCTIONS
All these functions are exported. However, if you use the C<schema> helper function,
@@ -100,19 +147,18 @@
my @columns = &declare($code);
- foreach my $column (@columns) {
- next if !ref($column);
- _init_column($column);
- }
-
- # XXX: merge superclasses' columns?
-
# Unimport all our symbols from the calling package.
foreach my $sym (@EXPORT) {
no strict 'refs';
undef *{"$from\::$sym"}
if \&{"$from\::$sym"} == \&$sym;
}
+
+ foreach my $column (@columns) {
+ next if !ref($column);
+ _init_column($column);
+ }
+
# Then initialize all columns
foreach my $column ( sort keys %{ $from->COLUMNS || {} } ) {
$from->_init_methods_for_column( $from->COLUMNS->{$column} );
@@ -127,15 +173,15 @@
no warnings 'uninitialized';
use constant MERGE_PARAM_BEHAVIOUR => {
SCALAR => {
- SCALAR => sub { length($_[1]) ? $_[1] : $_[0] },
+ SCALAR => sub { CORE::length($_[1]) ? $_[1] : $_[0] },
ARRAY => sub { [ @{$_[1]} ] },
HASH => sub { $_[1] } },
ARRAY => {
- SCALAR => sub { length($_[1]) ? $_[1] : $_[0] },
+ SCALAR => sub { CORE::length($_[1]) ? $_[1] : $_[0] },
ARRAY => sub { [ @{$_[1]} ] },
HASH => sub { $_[1] } },
HASH => {
- SCALAR => sub { length($_[1]) ? $_[1] : $_[0] },
+ SCALAR => sub { CORE::length($_[1]) ? $_[1] : $_[0] },
ARRAY => sub { [ @{$_[1]} ] },
HASH => sub { Hash::Merge::_merge_hashes( $_[0], $_[1] ) } }
};
@@ -184,9 +230,15 @@
$column->sort_order($SORT_ORDERS->{$from}++);
- if (0) {
-# if ( my $refclass = $column->refers_to ) {
- my $refclass;
+ $column->input_filters($column->{input_filters} || []);
+ $column->output_filters($column->{output_filters} || []);
+
+ if ( my $refclass = $column->refers_to ) {
+ if (ref($refclass) eq 'ARRAY') {
+ $column->by($refclass->[1]);
+ $column->refers_to($refclass = $refclass->[0]);
+ }
+
$refclass->require();
$column->type('integer') unless ( $column->type );
@@ -297,12 +349,12 @@
the like. The data is still accessible via C<< $record->_value('') >>.
Correct usage is C<is unreadable>.
-=head2 length
+=head2 max_length
-Sets a maximum length to store in the database; values longer than
+Sets a maximum max_length to store in the database; values longer than
this are truncated before being inserted into the database, using
L<Jifty::DBI::Filter::Truncate>. Note that this is in B<bytes>, not
-B<characters>. Correct usage is C<length is 42>.
+B<characters>. Correct usage is C<max_length is 42>.
=head2 mandatory
Modified: Jifty-DBI/branches/od/t/11schema_records.t
==============================================================================
--- Jifty-DBI/branches/od/t/11schema_records.t (original)
+++ Jifty-DBI/branches/od/t/11schema_records.t Fri Jan 26 06:27:28 2007
@@ -266,7 +266,7 @@
use Jifty::DBI::Schema;
use Jifty::DBI::Record schema {
column name => type is 'varchar';
- column phones => refers_to TestApp::PhoneCollection by 'employee';
+ column phones => refers TestApp::PhoneCollection by 'employee';
}
}
More information about the Jifty-commit
mailing list