X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FTable.pm;h=ed2e86efeacd5e8013830caecfbcf85cb1f542ad;hb=78bab9cad621ac5e3d1d12b02c41d662dec7a22a;hp=6caae423c5520fdec79bd651d2ba86467eac6280;hpb=2840de8fbf8506d2edbec5a9c7500136f0fc1c2a;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Table.pm b/lib/DBIx/Class/Table.pm index 6caae42..ed2e86e 100644 --- a/lib/DBIx/Class/Table.pm +++ b/lib/DBIx/Class/Table.pm @@ -37,7 +37,7 @@ sub new { $class = ref $class if ref $class; my $new = bless({ _column_data => { } }, $class); if ($attrs) { - die "attrs must be a hashref" unless ref($attrs) eq 'HASH'; + $new->throw("attrs must be a hashref" ) unless ref($attrs) eq 'HASH'; while (my ($k, $v) = each %{$attrs}) { $new->store_column($k => $v); } @@ -66,13 +66,13 @@ sub in_database { sub create { my ($class, $attrs) = @_; - die "create needs a hashref" unless ref $attrs eq 'HASH'; + $class->throw( "create needs a hashref" ) unless ref $attrs eq 'HASH'; return $class->new($attrs)->insert; } sub update { my ($self) = @_; - die "Not in database" unless $self->in_database; + $self->throw( "Not in database" ) unless $self->in_database; my @to_update = keys %{$self->{_dirty_columns} || {}}; return -1 unless @to_update; my $sth = $self->_get_sth('update', \@to_update, @@ -81,9 +81,9 @@ sub update { $self->_ident_values ); $sth->finish; if ($rows == 0) { - die "Can't update $self: row not found"; + $self->throw( "Can't update $self: row not found" ); } elsif ($rows > 1) { - die "Can't update $self: updated more than one row"; + $self->throw("Can't update $self: updated more than one row"); } $self->{_dirty_columns} = {}; return $self; @@ -92,7 +92,7 @@ sub update { sub delete { my $self = shift; if (ref $self) { - die "Not in database" unless $self->in_database; + $self->throw( "Not in database" ) unless $self->in_database; #warn $self->_ident_cond.' '.join(', ', $self->_ident_values); my $sth = $self->_get_sth('delete', undef, $self->_table_name, $self->_ident_cond); @@ -115,8 +115,8 @@ sub delete { sub get_column { my ($self, $column) = @_; - die "Can't fetch data as class method" unless ref $self; - die "No such column '${column}'" unless $self->_columns->{$column}; + $self->throw( "Can't fetch data as class method" ) unless ref $self; + $self->throw( "No such column '${column}'" ) unless $self->_columns->{$column}; return $self->{_column_data}{$column} if exists $self->{_column_data}{$column}; return undef; @@ -132,8 +132,10 @@ sub set_column { sub store_column { my ($self, $column, $value) = @_; - die "No such column '${column}'" unless $self->_columns->{$column}; - die "set_column called for ${column} without value" if @_ < 3; + $self->throw( "No such column '${column}'" ) + unless $self->_columns->{$column}; + $self->throw( "set_column called for ${column} without value" ) + if @_ < 3; return $self->{_column_data}{$column} = $value; }