From: David Kamholz Date: Wed, 8 Mar 2006 23:47:30 +0000 (+0000) Subject: cleanup ResultSource a bit, plus a couple trivial cleanups X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8e04bf91b7324ae925517cfa5d8398bc30f795a6;p=dbsrgits%2FDBIx-Class-Historic.git cleanup ResultSource a bit, plus a couple trivial cleanups --- diff --git a/lib/DBIx/Class/Relationship/HasMany.pm b/lib/DBIx/Class/Relationship/HasMany.pm index 1e61c74..864eaac 100644 --- a/lib/DBIx/Class/Relationship/HasMany.pm +++ b/lib/DBIx/Class/Relationship/HasMany.pm @@ -28,7 +28,7 @@ sub has_many { } $class->throw_exception("No such column ${f_key} on foreign class ${f_class} ($guess)") if $f_class_loaded && !$f_class->has_column($f_key); - $cond = { "foreign.${f_key}" => "self.${pri}" }, + $cond = { "foreign.${f_key}" => "self.${pri}" }; } $class->add_relationship($rel, $f_class, $cond, diff --git a/lib/DBIx/Class/Relationship/HasOne.pm b/lib/DBIx/Class/Relationship/HasOne.pm index 66662c9..682d150 100644 --- a/lib/DBIx/Class/Relationship/HasOne.pm +++ b/lib/DBIx/Class/Relationship/HasOne.pm @@ -22,9 +22,8 @@ sub _has_one { my ($pri, $too_many) = $class->primary_columns; $class->throw_exception( "might_have/has_one can only infer join for a single primary key; ${class} has more" ) if $too_many; - my $f_key; my $f_class_loaded = eval { $f_class->columns }; - my $guess; + my ($f_key,$guess); if (defined $cond && length $cond) { $f_key = $cond; $guess = "caller specified foreign key '$f_key'"; diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index e8b1b96..5c93cd8 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -126,18 +126,15 @@ Convenience alias to add_columns sub add_columns { my ($self, @cols) = @_; - $self->_ordered_columns( \@cols ) - if !$self->_ordered_columns; + $self->_ordered_columns(\@cols) unless $self->_ordered_columns; + my @added; my $columns = $self->_columns; while (my $col = shift @cols) { - + # If next entry is { ... } use that for the column info, if not + # use an empty hashref my $column_info = ref $cols[0] ? shift(@cols) : {}; - # If next entry is { ... } use that for the column info, if not - # use an empty hashref - push(@added, $col) unless exists $columns->{$col}; - $columns->{$col} = $column_info; } push @{ $self->_ordered_columns }, @added; @@ -173,22 +170,21 @@ sub column_info { $self->throw_exception("No such column $column") unless exists $self->_columns->{$column}; #warn $self->{_columns_info_loaded}, "\n"; - if ( ! $self->_columns->{$column}->{data_type} - && ! $self->{_columns_info_loaded} - && $self->schema && $self->storage() ){ - $self->{_columns_info_loaded}++; - my $info; -############ eval for the case of storage without table - eval{ - $info = $self->storage->columns_info_for ( $self->from() ); - }; - if ( ! $@ ){ - for my $col ( keys %{$self->_columns} ){ - for my $i ( keys %{$info->{$col}} ){ - $self->_columns()->{$col}->{$i} = $info->{$col}->{$i}; - } - } + if ( ! $self->_columns->{$column}{data_type} + and ! $self->{_columns_info_loaded} + and $self->schema and $self->storage ) + { + $self->{_columns_info_loaded}++; + my $info; + # eval for the case of storage without table + eval { $info = $self->storage->columns_info_for($self->from) }; + unless ($@) { + foreach my $col ( keys %{$self->_columns} ) { + foreach my $i ( keys %{$info->{$col}} ) { + $self->_columns->{$col}{$i} = $info->{$col}{$i}; + } } + } } return $self->_columns->{$column}; } @@ -202,7 +198,7 @@ Returns all column names in the order they were declared to add_columns =cut sub columns { - my $self=shift; + my $self = shift; $self->throw_exception("columns() is a read-only accessor, did you mean add_columns()?") if (@_ > 1); return @{$self->{_ordered_columns}||[]}; } @@ -224,9 +220,9 @@ retrieve automatically created values from the database. sub set_primary_key { my ($self, @cols) = @_; # check if primary key columns are valid columns - for (@cols) { - $self->throw_exception("No such column $_ on table ".$self->name) - unless $self->has_column($_); + foreach my $col (@cols) { + $self->throw_exception("No such column $col on table " . $self->name) + unless $self->has_column($col); } $self->_primaries(\@cols); @@ -257,9 +253,9 @@ L, only columns in the constraint are searched, sub add_unique_constraint { my ($self, $name, $cols) = @_; - for (@$cols) { - $self->throw_exception("No such column $_ on table ".$self->name) - unless $self->has_column($_); + foreach my $col (@$cols) { + $self->throw_exception("No such column $col on table " . $self->name) + unless $self->has_column($col); } my %unique_constraints = $self->unique_constraints; diff --git a/lib/DBIx/Class/Storage.pm b/lib/DBIx/Class/Storage.pm index 6a51979..0448110 100644 --- a/lib/DBIx/Class/Storage.pm +++ b/lib/DBIx/Class/Storage.pm @@ -22,8 +22,6 @@ sub select_single { die "Virtual method!" } sub columns_info_for { die "Virtual method!" } - - package DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION; use overload '"' => sub { @@ -32,7 +30,6 @@ use overload '"' => sub { sub new { my $class = shift; - return bless {}, $class; }