X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSource.pm;h=5c93cd8b252ca3e16c03c5222ef7a69134647fd7;hb=8e04bf91b7324ae925517cfa5d8398bc30f795a6;hp=e8b1b966f9320d8d011ace62d86cb10f409345ed;hpb=223aea40a757afb7a352b5496ae332eaed5a43c0;p=dbsrgits%2FDBIx-Class.git 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;