[Rt-commit] r4038 - in Jifty-DBI/trunk: . lib/Jifty/DBI
lib/Jifty/DBI/Filter
jesse at bestpractical.com
jesse at bestpractical.com
Sun Nov 6 18:13:00 EST 2005
Author: jesse
Date: Sun Nov 6 18:12:40 2005
New Revision: 4038
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/Filter.pm
Jifty-DBI/trunk/lib/Jifty/DBI/Filter/DateTime.pm
Jifty-DBI/trunk/lib/Jifty/DBI/Filter/Truncate.pm
Jifty-DBI/trunk/lib/Jifty/DBI/Filter/utf8.pm
Jifty-DBI/trunk/lib/Jifty/DBI/Handle.pm
Jifty-DBI/trunk/lib/Jifty/DBI/HasFilters.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:
r18416 at truegrounds: jesse | 2005-11-06 18:09:07 -0500
* perltidy!
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 Sun Nov 6 18:12:40 2005
@@ -267,7 +267,8 @@
&& $self->{'order_clause'} =~ /(?<!main)\./ )
{
$$statementref = "SELECT main.* FROM $$statementref";
- } else {
+ }
+ else {
$self->_handle->distinct_query( $statementref, $table );
}
}
@@ -296,7 +297,8 @@
my $self = shift;
if ( keys( %{ $self->{'leftjoins'} } ) ) {
return (1);
- } else {
+ }
+ else {
return ( @{ $self->{'aliases'} } );
}
@@ -314,7 +316,8 @@
$limit_clause .= $self->first_row . ", ";
}
$limit_clause .= $self->rows_per_page;
- } else {
+ }
+ else {
$limit_clause = "";
}
return $limit_clause;
@@ -331,7 +334,8 @@
my $self = shift;
if (@_) {
$self->{'is_limited'} = shift;
- } else {
+ }
+ else {
return ( $self->{'is_limited'} );
}
}
@@ -355,7 +359,8 @@
# DISTINCT query only required for multi-table selects
if ( $self->_is_joined ) {
$self->_distinct_query( \$QueryString, $self->table );
- } else {
+ }
+ else {
$QueryString = "SELECT main.* FROM $QueryString";
}
@@ -389,7 +394,8 @@
# DISTINCT query only required for multi-table selects
if ( $self->_is_joined ) {
$QueryString = $self->_handle->distinct_count( \$QueryString );
- } else {
+ }
+ else {
$QueryString = "SELECT count(main.id) FROM " . $QueryString;
}
@@ -419,7 +425,8 @@
my $item = ( $self->{'items'}[ $self->{'itemscount'} ] );
$self->{'itemscount'}++;
return ($item);
- } else { #we've gone through the whole list. reset the count.
+ }
+ else { #we've gone through the whole list. reset the count.
$self->goto_first_item();
return (undef);
}
@@ -497,14 +504,14 @@
}
sub new_item {
- my $self = shift;
- my $class =$self->record_class();
+ my $self = shift;
+ my $class = $self->record_class();
die "Jifty::DBI::Collection needs to be subclassed; override new_item\n"
- unless $class;
+ unless $class;
$class->require();
- return $class->new($self->_handle);
+ return $class->new( $self->_handle );
}
=head2 record_class
@@ -529,7 +536,7 @@
if (@_) {
$self->{record_class} = shift if (@_);
}
- elsif (not $self->{record_class}) {
+ elsif ( not $self->{record_class} ) {
my $class = ref($self);
$class =~ s/Collection$//;
$self->{record_class} = $class;
@@ -628,16 +635,16 @@
sub limit {
my $self = shift;
my %args = (
- table => $self->table,
+ table => $self->table,
column => 'fuck',
- value => 'hate',
- alias => undef,
+ value => 'hate',
+ alias => undef,
quote_value => 1,
entry_aggregator => 'or',
case_sensitive => undef,
- operator => '=',
- subclause => undef,
- leftjoin => undef,
+ operator => '=',
+ subclause => undef,
+ leftjoin => undef,
@_ # get the real argumentlist
);
@@ -650,14 +657,17 @@
#If it's a like, we supply the %s around the search term
if ( $args{'operator'} =~ /LIKE/i ) {
- $args{'value'} = $args{'value'} ;
- } elsif ( $args{'operator'} =~ /MATCHES/i ) {
- $args{'value'} = "%".$args{'value'} . "%";
+ $args{'value'} = $args{'value'};
+ }
+ elsif ( $args{'operator'} =~ /MATCHES/i ) {
+ $args{'value'} = "%" . $args{'value'} . "%";
$args{'operator'} = "LIKE";
- } elsif ( $args{'operator'} =~ /STARTSWITH/i ) {
+ }
+ elsif ( $args{'operator'} =~ /STARTSWITH/i ) {
$args{'value'} = $args{'value'} . "%";
$args{'operator'} = "LIKE";
- } elsif ( $args{'operator'} =~ /ENDSWITH/i ) {
+ }
+ elsif ( $args{'operator'} =~ /ENDSWITH/i ) {
$args{'value'} = "%" . $args{'value'};
$args{'operator'} = "LIKE";
}
@@ -679,8 +689,6 @@
}
}
-
-
my ( $Clause, $qualified_field );
#TODO: $args{'value'} should take an array of values and generate
@@ -723,11 +731,12 @@
if ( $args{'subclause'} ) {
$Clause = $args{'subclause'};
- } else {
+ }
+ else {
$Clause = $qualified_field;
}
- warn "$self->_generic_restriction qualified_field=$qualified_field\n"
+ warn "$self->_generic_restriction qualified_field=$qualified_field\n"
if ( $self->DEBUG );
my ($restriction);
@@ -738,7 +747,8 @@
if ( $args{'leftjoin'} ) {
$restriction = \$self->{'leftjoins'}{ $args{'leftjoin'} }{'criteria'}
{"$Clause"};
- } else {
+ }
+ else {
$restriction = \$self->{'restrictions'}{"$Clause"};
}
@@ -777,23 +787,23 @@
$$restriction = $prefix . $clause;
- } else {
+ }
+ else {
$$restriction .= $args{'entry_aggregator'} . $prefix . $clause;
}
-
# We're now limited. people can do searches.
$self->_is_limited(1);
- if ( defined($args{'alias'}) ) {
- return ($args{'alias'});
- } else {
+ if ( defined( $args{'alias'} ) ) {
+ return ( $args{'alias'} );
+ }
+ else {
return (1);
}
}
-
sub _open_paren {
my ( $self, $clause ) = @_;
$self->{_open_parens}{$clause}++;
@@ -805,7 +815,8 @@
my $restriction = \$self->{'restrictions'}{"$clause"};
if ( !$$restriction ) {
$$restriction = " ) ";
- } else {
+ }
+ else {
$$restriction .= " ) ";
}
}
@@ -823,10 +834,10 @@
my $self = shift;
my ( $subclause, $where_clause );
-# Go through all the generic restrictions and build up the
-# "generic_restrictions" subclause. That's the only one that the
-# collection builds itself. Arguably, the abstraction should be
-# better, but I don't really see where to put it.
+ # Go through all the generic restrictions and build up the
+ # "generic_restrictions" subclause. That's the only one that the
+ # collection builds itself. Arguably, the abstraction should be
+ # better, but I don't really see where to put it.
$self->_compile_generic_restrictions();
#Go through all restriction types. Build the where clause from the
@@ -928,14 +939,15 @@
foreach my $row (@args) {
my %rowhash = (
- alias => 'main',
+ alias => 'main',
column => undef,
- order => 'ASC',
+ order => 'ASC',
%$row
);
if ( $rowhash{'order'} =~ /^des/i ) {
$rowhash{'order'} = "DESC";
- } else {
+ }
+ else {
$rowhash{'order'} = "ASC";
}
@@ -1016,7 +1028,7 @@
my $clause = '';
foreach my $row (@args) {
my %rowhash = (
- alias => 'main',
+ alias => 'main',
column => undef,
%$row
);
@@ -1024,7 +1036,8 @@
$clause .= ( $clause ? ", " : " " );
$clause .= $rowhash{'function'};
- } elsif ( ( $rowhash{'alias'} )
+ }
+ elsif ( ( $rowhash{'alias'} )
and ( $rowhash{'column'} ) )
{
@@ -1061,13 +1074,14 @@
=cut
sub new_alias {
- my $self = shift;
+ my $self = shift;
my $refers_to = shift || die "Missing parameter";
my $table;
- if ($refers_to->can('table')) {
+ if ( $refers_to->can('table') ) {
$table = $refers_to->table;
- } else {
+ }
+ else {
$table = $refers_to;
}
@@ -1120,12 +1134,12 @@
sub join {
my $self = shift;
my %args = (
- type => 'normal',
+ type => 'normal',
column1 => undef,
- alias1 => 'main',
- table2 => undef,
+ alias1 => 'main',
+ table2 => undef,
column2 => undef,
- alias2 => undef,
+ alias2 => undef,
@_
);
@@ -1147,7 +1161,8 @@
my $self = shift;
if ( ( $self->first_row - $self->rows_per_page ) > 1 ) {
$self->first_row( $self->first_row - $self->rows_per_page );
- } else {
+ }
+ else {
$self->first_row(1);
}
}
@@ -1158,7 +1173,8 @@
if ( $self->rows_per_page ) {
$self->first_row( 1 + ( $self->rows_per_page * $page ) );
- } else {
+ }
+ else {
$self->first_row(1);
}
}
@@ -1307,7 +1323,8 @@
if ( $self->_items_counter == $self->count ) {
return (1);
- } else {
+ }
+ else {
return (0);
}
}
@@ -1335,7 +1352,7 @@
my %args = (
table => undef,
alias => undef,
- column => undef,
+ column => undef,
function => undef,
@_
);
@@ -1344,7 +1361,8 @@
if ( my $alias = $args{alias} ) {
$alias =~ s/_\d+$//;
$alias;
- } else {
+ }
+ else {
$self->table;
}
};
@@ -1363,7 +1381,8 @@
# If we want to call a simple function on the column
elsif ( $func !~ /\(/ ) {
$name = "\U$func\E($name)";
- } else {
+ }
+ else {
$name = $func;
}
@@ -1423,11 +1442,11 @@
my $self = shift;
my %args = (
column => undef,
- table => undef,
+ table => undef,
@_
);
- my $table = $args{table} or die;
+ my $table = $args{table} or die;
my $field = $args{column} or die;
return grep { $_ eq $field } $self->fields($table);
}
@@ -1455,7 +1474,7 @@
my $class = shift;
my (%args) = @_;
- return (refers_to => $class, %args);
+ return ( refers_to => $class, %args );
}
1;
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 Sun Nov 6 18:12:40 2005
@@ -7,11 +7,11 @@
use UNIVERSAL::require;
__PACKAGE__->mk_accessors qw/
- name
- type
- default
- validator
- readable writable
+ name
+ type
+ default
+ validator
+ readable writable
length
null
refers_to by
@@ -22,7 +22,6 @@
valid_values
/;
-
=head1 NAME
Jifty::DBI::Column
@@ -41,7 +40,7 @@
sub is_numeric {
my $self = shift;
- if ($self->type =~ /INT|NUMERIC|DECIMAL|REAL|DOUBLE|FLOAT/i ) {
+ if ( $self->type =~ /INT|NUMERIC|DECIMAL|REAL|DOUBLE|FLOAT/i ) {
return 1;
}
return 0;
@@ -49,7 +48,7 @@
}
# Aliases for compatibility with searchbuilder code
-*read = \&readable;
+*read = \&readable;
*write = \&writable;
1;
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Filter.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Filter.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Filter.pm Sun Nov 6 18:12:40 2005
@@ -6,7 +6,6 @@
__PACKAGE__->mk_accessors(qw(record column value_ref));
-
=head2 new
Takes
@@ -28,15 +27,17 @@
sub new {
my $class = shift;
- my %args = (column => undef,
- value_ref => undef,
- @_);
+ my %args = (
+ column => undef,
+ value_ref => undef,
+ @_
+ );
my $self = {};
bless $self, $class;
-
- for ( keys %args) {
- if ($self->can($_)) {
- $self->$_($args{$_});
+
+ for ( keys %args ) {
+ if ( $self->can($_) ) {
+ $self->$_( $args{$_} );
}
}
@@ -70,5 +71,4 @@
}
-
1;
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Filter/DateTime.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Filter/DateTime.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Filter/DateTime.pm Sun Nov 6 18:12:40 2005
@@ -4,7 +4,7 @@
use strict;
use base qw(Jifty::DBI::Filter);
-use DateTime ();
+use DateTime ();
use DateTime::Format::Strptime ();
=head1 NAME
@@ -32,7 +32,7 @@
return unless UNIVERSAL::isa( $$value_ref, 'DateTime' );
- $$value_ref = $$value_ref->strftime( "%Y-%m-%d %H:%M:%S" );
+ $$value_ref = $$value_ref->strftime("%Y-%m-%d %H:%M:%S");
return 1;
}
@@ -50,19 +50,19 @@
my $value_ref = $self->value_ref;
return unless defined $$value_ref;
- # XXX: Looks like we should use special modules for parsing DT because
- # different MySQL versions can return DT in different formats(none strict ISO)
- # Pg has also special format that depends on "european" and
- # server time_zone, by default ISO
- # other DBs may have own formats(Interbase for example can be forced to use special format)
- # but we need Jifty::DBI::Handle here to get DB type
- my $parser = DateTime::Format::Strptime->new(
- pattern => '%Y-%m-%d %H:%M:%S',
- );
- my $dt = $parser->parse_datetime( $$value_ref );
- if( $dt ) {
+# XXX: Looks like we should use special modules for parsing DT because
+# different MySQL versions can return DT in different formats(none strict ISO)
+# Pg has also special format that depends on "european" and
+# server time_zone, by default ISO
+# other DBs may have own formats(Interbase for example can be forced to use special format)
+# but we need Jifty::DBI::Handle here to get DB type
+ my $parser
+ = DateTime::Format::Strptime->new( pattern => '%Y-%m-%d %H:%M:%S', );
+ my $dt = $parser->parse_datetime($$value_ref);
+ if ($dt) {
$$value_ref = $dt;
- } else {
+ }
+ else {
return;
}
}
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Filter/Truncate.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Filter/Truncate.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Filter/Truncate.pm Sun Nov 6 18:12:40 2005
@@ -10,7 +10,7 @@
my $self = shift;
my $value_ref = $self->value_ref;
- return undef unless ( defined( $$value_ref ) );
+ return undef unless ( defined($$value_ref) );
my $column = $self->column();
@@ -24,14 +24,15 @@
return unless ($truncate_to); # don't need to truncate
- my $utf8 = Encode::is_utf8( $$value_ref );
+ my $utf8 = Encode::is_utf8($$value_ref);
{
use bytes;
- $$value_ref = substr( $$value_ref, 0, $truncate_to );
+ $$value_ref = substr( $$value_ref, 0, $truncate_to );
}
- if( $utf8 ) {
+ if ($utf8) {
+
# return utf8 flag back, but use Encode::FB_QUIET because
- # we could broke tail char
+ # we could broke tail char
$$value_ref = Encode::decode_utf8( $$value_ref, Encode::FB_QUIET );
}
}
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Filter/utf8.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Filter/utf8.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Filter/utf8.pm Sun Nov 6 18:12:40 2005
@@ -32,16 +32,19 @@
my $self = shift;
my $value_ref = $self->value_ref;
- return undef unless ( defined( $$value_ref ) );
+ return undef unless ( defined($$value_ref) );
+
+ if ( Encode::is_utf8($$value_ref) ) {
+ $$value_ref = Encode::encode_utf8($$value_ref);
+ }
+ else {
- if( Encode::is_utf8( $$value_ref ) ) {
- $$value_ref = Encode::encode_utf8( $$value_ref );
- } else {
# if value has no utf8 flag but filter on the stack
- # we do double encoding, and stop on the first bad characters
- # with FB_QUIET fallback schema. We this schema because we
- # don't want data grow
- $$value_ref = Encode::encode_utf8( Encode::decode_utf8( $$value_ref, Encode::FB_QUIET ) );
+ # we do double encoding, and stop on the first bad characters
+ # with FB_QUIET fallback schema. We this schema because we
+ # don't want data grow
+ $$value_ref = Encode::encode_utf8(
+ Encode::decode_utf8( $$value_ref, Encode::FB_QUIET ) );
}
return 1;
}
@@ -59,10 +62,10 @@
my $self = shift;
my $value_ref = $self->value_ref;
- return undef unless ( defined( $$value_ref ) );
+ return undef unless ( defined($$value_ref) );
- unless( Encode::is_utf8( $$value_ref ) ) {
- $$value_ref = Encode::decode_utf8( $$value_ref );
+ unless ( Encode::is_utf8($$value_ref) ) {
+ $$value_ref = Encode::decode_utf8($$value_ref);
}
return 1;
}
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Handle.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Handle.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Handle.pm Sun Nov 6 18:12:40 2005
@@ -1,9 +1,9 @@
package Jifty::DBI::Handle;
use strict;
-use Carp ();
-use DBI ();
+use Carp ();
+use DBI ();
use Class::ReturnValue ();
-use Encode ();
+use Encode ();
use base qw/Jifty::DBI::HasFilters/;
@@ -229,7 +229,7 @@
my $self = shift;
my $statement = shift;
my $duration = shift;
- my @bind = @_;
+ my @bind = @_;
push @{ $self->{'StatementLog'} },
( [ Time::HiRes::time(), $statement, [@bind], $duration ] );
@@ -459,7 +459,8 @@
eval { $executed = $sth->execute(@bind_values) };
}
if ( $self->log_sql_statements ) {
- $self->_log_sql_statement( $QueryString, Time::HiRes::time() - $basetime, @bind_values );
+ $self->_log_sql_statement( $QueryString,
+ Time::HiRes::time() - $basetime, @bind_values );
}
@@ -565,21 +566,25 @@
my $self = shift;
my %args = ( short => 1, @_ );
- unless( defined $self->{'database_version'} ) {
+ unless ( defined $self->{'database_version'} ) {
+
# turn off error handling, store old values to restore later
- my $re = $self->raise_error; $self->raise_error(0);
- my $pe = $self->print_error; $self->print_error(0);
+ my $re = $self->raise_error;
+ $self->raise_error(0);
+ my $pe = $self->print_error;
+ $self->print_error(0);
my $statement = "SELECT VERSION()";
- my $sth = $self->simple_query($statement);
+ my $sth = $self->simple_query($statement);
- my $ver = '';
- $ver = ($sth->fetchrow_arrayref->[0] || '') if $sth;
- $ver =~ /(\d+(?:\.\d+)*(?:-[a-z0-9]+)?)/i;
- $self->{'database_version'} = $ver;
- $self->{'database_version_short'} = $1 || $ver;
+ my $ver = '';
+ $ver = ( $sth->fetchrow_arrayref->[0] || '' ) if $sth;
+ $ver =~ /(\d+(?:\.\d+)*(?:-[a-z0-9]+)?)/i;
+ $self->{'database_version'} = $ver;
+ $self->{'database_version_short'} = $1 || $ver;
- $self->raise_error($re); $self->print_error($pe);
+ $self->raise_error($re);
+ $self->print_error($pe);
}
return $self->{'database_version_short'} if $args{'short'};
@@ -758,10 +763,10 @@
my %args = (
collection => undef,
type => 'normal',
- column1 => 'main',
+ column1 => 'main',
alias1 => undef,
table2 => undef,
- column2 => undef,
+ column2 => undef,
alias2 => undef,
EXPRESSION => undef,
@_
@@ -771,11 +776,11 @@
my $alias;
-#If we're handed in an alias2, we need to go remove it from the
-# Aliases array. Basically, if anyone generates an alias and then
-# tries to use it in a join later, we want to be smart about creating
-# joins, so we need to go rip it out of the old aliases table and drop
-# it in as an explicit join
+ #If we're handed in an alias2, we need to go remove it from the
+ # Aliases array. Basically, if anyone generates an alias and then
+ # tries to use it in a join later, we want to be smart about creating
+ # joins, so we need to go rip it out of the old aliases table and drop
+ # it in as an explicit join
if ( $args{'alias2'} ) {
# this code is slow and wasteful, but it's clear.
@@ -798,9 +803,9 @@
# if we can't do that, can we reverse the join and have it work?
my $a1 = $args{'alias1'};
my $f1 = $args{'column1'};
- $args{'alias1'} = $args{'alias2'};
+ $args{'alias1'} = $args{'alias2'};
$args{'column1'} = $args{'column2'};
- $args{'alias2'} = $a1;
+ $args{'alias2'} = $a1;
$args{'column2'} = $f1;
@aliases = @{ $args{'collection'}->{'aliases'} };
@@ -849,8 +854,7 @@
$criterion = $args{'alias1'} . "." . $args{'column1'};
}
- $args{'collection'}->{'leftjoins'}{"$alias"}{'alias_string'}
- = $string;
+ $args{'collection'}->{'leftjoins'}{"$alias"}{'alias_string'} = $string;
$args{'collection'}->{'leftjoins'}{"$alias"}{'depends_on'}
= $args{'alias1'};
$args{'collection'}->{'leftjoins'}{"$alias"}{'criteria'}
@@ -866,10 +870,10 @@
my %args = (
collection => undef,
type => 'normal',
- column1 => undef,
+ column1 => undef,
alias1 => undef,
table2 => undef,
- column2 => undef,
+ column2 => undef,
alias2 => undef,
@_
);
@@ -891,9 +895,9 @@
$sb->Jifty::DBI::Collection::limit(
entry_aggregator => 'AND',
quote_value => 0,
- alias => $args{'alias1'},
+ alias => $args{'alias1'},
column => $args{'column1'},
- value => $args{'alias2'} . "." . $args{'column2'},
+ value => $args{'alias2'} . "." . $args{'column2'},
@_
);
}
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/HasFilters.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/HasFilters.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/HasFilters.pm Sun Nov 6 18:12:40 2005
@@ -5,8 +5,8 @@
use base qw/Class::Accessor/;
__PACKAGE__->mk_accessors qw/
- input_filters
- output_filters
+ input_filters
+ output_filters
/;
=head1 NAME
@@ -40,9 +40,9 @@
sub input_filters {
my $self = shift;
- if( @_ ) { # setting
- my @values = map { UNIVERSAL::isa($_, 'ARRAY')? @$_: $_ } @_;
- return $self->_input_filters_accessor( @values );
+ if (@_) { # setting
+ my @values = map { UNIVERSAL::isa( $_, 'ARRAY' ) ? @$_ : $_ } @_;
+ return $self->_input_filters_accessor(@values);
}
return grep $_, $self->_input_filters_accessor;
@@ -60,15 +60,15 @@
sub output_filters {
my $self = shift;
- if( @_ ) { # setting
- my @values = map { UNIVERSAL::isa($_, 'ARRAY')? @$_: $_ } @_;
- $self->_output_filters_accessor( @values );
+ if (@_) { # setting
+ my @values = map { UNIVERSAL::isa( $_, 'ARRAY' ) ? @$_ : $_ } @_;
+ $self->_output_filters_accessor(@values);
}
my @values = grep $_, $self->_output_filters_accessor;
return @values if @values;
- return reverse $self->input_filters
+ return reverse $self->input_filters;
}
=head1 SEE ALSO
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 Sun Nov 6 18:12:40 2005
@@ -623,12 +623,12 @@
=cut
sub _value {
- my $self = shift;
+ my $self = shift;
my $column = shift;
-
- my $value = $self->__value($column => @_);
+
+ my $value = $self->__value( $column => @_ );
my $method = "after_$column";
- $self->$method(\$value) if ($self->can($method));
+ $self->$method( \$value ) if ( $self->can($method) );
return $value;
}
@@ -648,11 +648,11 @@
'is_sql_function' => undef,
@_
);
-
- my $method = "before_set_".$args{column};
- $self->$method(\%args) if ($self->can($method));
- return $self->__set(%args) ;
+ my $method = "before_set_" . $args{column};
+ $self->$method( \%args ) if ( $self->can($method) );
+
+ return $self->__set(%args);
}
@@ -953,9 +953,7 @@
my $self = shift;
my %attribs = @_;
-
- $self->before_create(\%attribs) if $self->can('before_create');
-
+ $self->before_create( \%attribs ) if $self->can('before_create');
foreach my $column_name ( keys %attribs ) {
my $column = $self->column($column_name);
@@ -990,9 +988,9 @@
}
}
}
- my $ret = $self->_handle->insert( $self->table, %attribs );
+ my $ret = $self->_handle->insert( $self->table, %attribs );
$self->after_create($ret) if $self->can('after_create');
- return ( $ret );
+ return ($ret);
}
=head2 delete
@@ -1006,8 +1004,8 @@
my $self = shift;
$self->before_delete() if $self->can('before_delete');
my $ret = $self->__delete;
- $self->after_delete(\$ret) if $self->can('after_delete');
- return($ret);
+ $self->after_delete( \$ret ) if $self->can('after_delete');
+ return ($ret);
}
@@ -1055,15 +1053,14 @@
sub table {
my $self = shift;
- if ( not ref($self) ) {
+ if ( not ref($self) ) {
return $self->_guess_table_name();
}
$self->{__table_name} ||= $self->_guess_table_name;
-
+
return $self->{__table_name};
}
-
=head2 _guess_table_name
Guesses a table name based on the class's last part.
@@ -1071,19 +1068,18 @@
=cut
-sub _guess_table_name {
+sub _guess_table_name {
my $self = shift;
- my $class = ref($self) ? ref($self) : $self ;
- die "Couldn't turn " . $class . " into a table name"
- unless ( $class =~ /(?:\:\:)?(\w+)$/ );
- my $table = $1;
- $table =~ s/(?<=[a-z])([A-Z]+)/"_" . lc($1)/eg;
- $table =~ tr/A-Z/a-z/;
- $table = Lingua::EN::Inflect::PL_N($table);
- return($table);
-
- }
+ my $class = ref($self) ? ref($self) : $self;
+ die "Couldn't turn " . $class . " into a table name"
+ unless ( $class =~ /(?:\:\:)?(\w+)$/ );
+ my $table = $1;
+ $table =~ s/(?<=[a-z])([A-Z]+)/"_" . lc($1)/eg;
+ $table =~ tr/A-Z/a-z/;
+ $table = Lingua::EN::Inflect::PL_N($table);
+ return ($table);
+}
=head2 _handle
@@ -1099,7 +1095,6 @@
return ( $self->{'DBIxHandle'} );
}
-
=for private refers_to
used for the declarative syntax
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 Sun Nov 6 18:12:40 2005
@@ -1,8 +1,10 @@
package Jifty::DBI::Schema;
use Exporter::Lite;
-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 @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 {
my $name = shift;
@@ -10,21 +12,22 @@
$from =~ s/::Schema//;
$from->_init_columns;
- my @args = (name => $name,
- readable => 1,
- writable => 1,
- null => 1,
- @_,
- );
+ my @args = (
+ name => $name,
+ readable => 1,
+ writable => 1,
+ null => 1,
+ @_,
+ );
my @original = @args;
my $column = Jifty::DBI::Column->new();
while (@args) {
- my ($method, $arguments) = splice @args, 0, 2;
+ my ( $method, $arguments ) = splice @args, 0, 2;
$column->$method($arguments);
}
- if (my $refclass = $column->refers_to) {
+ if ( my $refclass = $column->refers_to ) {
$refclass->require();
$column->type('integer');
@@ -32,7 +35,7 @@
if ( $name =~ /(.*)_id$/ ) {
my $virtual_column = $from->add_column($1);
while (@original) {
- my ($method, $arguments) = splice @original, 0, 2;
+ my ( $method, $arguments ) = splice @original, 0, 2;
$virtual_column->$method($arguments);
}
$column->refers_to(undef);
@@ -46,79 +49,77 @@
warn "Error: $refclass neither Record nor Collection";
}
}
-
+
$from->COLUMNS->{$name} = $column;
}
sub type ($) {
- return (type => shift);
+ return ( type => shift );
}
sub default ($) {
- return (default => shift);
+ return ( default => shift );
}
sub validator ($) {
- return (validator => shift);
+ return ( validator => shift );
}
sub immutable () {
- return ([writable => 0]);
+ return ( [ writable => 0 ] );
}
sub unreadable {
- return ([readable => 0]);
+ return ( [ readable => 0 ] );
}
sub length ($) {
- return (length => shift);
+ return ( length => shift );
}
sub not_null () {
- return ([null => 0]);
+ return ( [ null => 0 ] );
}
sub input_filters ($) {
- return (input_filters => shift);
+ return ( input_filters => shift );
}
sub output_filters ($) {
- return (output_filters => shift);
+ return ( output_filters => shift );
}
-
sub since ($) {
- return (since => shift);
+ return ( since => shift );
}
sub mandatory () {
- return ([mandatory => 1]);
+ return ( [ mandatory => 1 ] );
}
sub valid_values ($) {
- return (valid_values => shift);
+ return ( valid_values => shift );
}
sub label ($) {
- return (label => shift);
+ return ( label => shift );
}
sub hints ($) {
- return (hints => shift);
+ return ( hints => shift );
}
sub render_as ($) {
- return (render_as => shift);
+ return ( render_as => shift );
}
-
sub is ($) {
my $thing = shift;
return ref $thing ? @{$thing} : $thing;
}
sub by ($) {
- return (by => shift);
+ return ( by => shift );
}
sub are (@) {
@@ -126,7 +127,7 @@
}
sub on ($) {
- return (self => shift);
+ return ( self => shift );
}
1;
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 Sun Nov 6 18:12:40 2005
@@ -129,9 +129,10 @@
return $self->_error("Error making new object from $model: $@");
}
- unless (UNIVERSAL::isa( $new_model, 'Jifty::DBI::Record' )) {
- return $self->_error(
- "Didn't get a Jifty::DBI::Record from $model, got $new_model")
+ unless ( UNIVERSAL::isa( $new_model, 'Jifty::DBI::Record' ) ) {
+ return $self->_error(
+ "Didn't get a Jifty::DBI::Record from $model, got $new_model"
+ );
}
$model = $new_model;
}
@@ -185,8 +186,10 @@
my @columns = $model->columns;
my @cols;
+
# The sort here is to make it predictable, so that we can write tests.
- for my $column ( sort {$a->name cmp $b->name} @columns) {
+ 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;
@@ -228,7 +231,6 @@
1; # Magic true value required at end of module
-
=head1 INCOMPATIBILITIES
=for author to fill in:
@@ -296,3 +298,4 @@
SUCH DAMAGES.
=cut
+
More information about the Rt-commit
mailing list