From: Marcus Ramberg Date: Fri, 20 Jan 2006 21:23:34 +0000 (+0000) Subject: use croak instead of die for user errors. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=aa5624077a0da8763f3482b5912c45e97b4214f8;p=dbsrgits%2FDBIx-Class-Historic.git use croak instead of die for user errors. --- diff --git a/Changes b/Changes index ae23cea..4b929a6 100644 --- a/Changes +++ b/Changes @@ -7,6 +7,7 @@ Revision history for DBIx::Class - made Storage::DBI use prepare_cached safely (thanks to Tim Bunce) - many documentation improvements (thanks guys!) - added ->connection, ->connect, ->register_source and ->clone schema methods + - Use croak instead of die for user errors. 0.04999_02 2006-01-14 07:17:35 - Schema is now self-contained; no requirement for co-operation diff --git a/lib/DBIx/Class/InflateColumn.pm b/lib/DBIx/Class/InflateColumn.pm index 9cfea79..6a8e1e7 100644 --- a/lib/DBIx/Class/InflateColumn.pm +++ b/lib/DBIx/Class/InflateColumn.pm @@ -2,6 +2,9 @@ package DBIx::Class::InflateColumn; use strict; use warnings; + +use Carp qw/croak/; + use base qw/DBIx::Class::Row/; =head1 NAME @@ -56,8 +59,8 @@ used in the database layer. sub inflate_column { my ($self, $col, $attrs) = @_; - die "No such column $col to inflate" unless $self->has_column($col); - die "inflate_column needs attr hashref" unless ref $attrs eq 'HASH'; + croak "No such column $col to inflate" unless $self->has_column($col); + croak "inflate_column needs attr hashref" unless ref $attrs eq 'HASH'; $self->column_info($col)->{_inflate_info} = $attrs; $self->mk_group_accessors('inflated_column' => $col); return 1; @@ -66,20 +69,20 @@ sub inflate_column { sub _inflated_column { my ($self, $col, $value) = @_; return $value unless defined $value; # NULL is NULL is NULL - my $info = $self->column_info($col) || die "No column info for $col"; + my $info = $self->column_info($col) || croak "No column info for $col"; return $value unless exists $info->{_inflate_info}; my $inflate = $info->{_inflate_info}{inflate}; - die "No inflator for $col" unless defined $inflate; + croak "No inflator for $col" unless defined $inflate; return $inflate->($value, $self); } sub _deflated_column { my ($self, $col, $value) = @_; return $value unless ref $value; # If it's not an object, don't touch it - my $info = $self->column_info($col) || die "No column info for $col"; + my $info = $self->column_info($col) || croak "No column info for $col"; return $value unless exists $info->{_inflate_info}; my $deflate = $info->{_inflate_info}{deflate}; - die "No deflator for $col" unless defined $deflate; + croak "No deflator for $col" unless defined $deflate; return $deflate->($value, $self); } diff --git a/lib/DBIx/Class/PK/Auto/Oracle.pm b/lib/DBIx/Class/PK/Auto/Oracle.pm index f1b318b..e12b16c 100644 --- a/lib/DBIx/Class/PK/Auto/Oracle.pm +++ b/lib/DBIx/Class/PK/Auto/Oracle.pm @@ -3,6 +3,8 @@ package DBIx::Class::PK::Auto::Oracle; use strict; use warnings; +use Carp qw/croak/; + use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/PK::Auto/); @@ -41,7 +43,7 @@ sub get_autoinc_seq { } } unless ($self->{_autoinc_seq}) { - die "Unable to find a sequence INSERT trigger on table '" . $self->_table_name . "'."; + croak "Unable to find a sequence INSERT trigger on table '" . $self->_table_name . "'."; } } diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index a6d884a..fea1533 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -2,6 +2,7 @@ package DBIx::Class::ResultSet; use strict; use warnings; +use Carp qw/croak/; use overload '0+' => 'count', 'bool' => sub { 1; }, @@ -285,7 +286,7 @@ on the resultset and counts the results of that. sub count { my $self = shift; return $self->search(@_)->count if @_ && defined $_[0]; - die "Unable to ->count with a GROUP BY" if defined $self->{attrs}{group_by}; + croak "Unable to ->count with a GROUP BY" if defined $self->{attrs}{group_by}; unless (defined $self->{count}) { my $attrs = { %{ $self->{attrs} }, select => { 'count' => '*' }, @@ -354,7 +355,7 @@ Sets the specified columns in the resultset to the supplied values sub update { my ($self, $values) = @_; - die "Values for update must be a hash" unless ref $values eq 'HASH'; + croak "Values for update must be a hash" unless ref $values eq 'HASH'; return $self->{source}->storage->update( $self->{source}->from, $values, $self->{cond}); } @@ -368,7 +369,7 @@ cascade triggers, ->update will not. sub update_all { my ($self, $values) = @_; - die "Values for update must be a hash" unless ref $values eq 'HASH'; + croak "Values for update must be a hash" unless ref $values eq 'HASH'; foreach my $obj ($self->all) { $obj->set_columns($values)->update; } @@ -410,7 +411,7 @@ sense for queries with page turned on. sub pager { my ($self) = @_; my $attrs = $self->{attrs}; - die "Can't create pager for non-paged rs" unless $self->{page}; + croak "Can't create pager for non-paged rs" unless $self->{page}; $attrs->{rows} ||= 10; $self->count; return $self->{pager} ||= Data::Page->new( diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index 04dfd8a..bc71706 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -224,7 +224,7 @@ created, which calls C for the relationship. sub add_relationship { my ($self, $rel, $f_source_name, $cond, $attrs) = @_; - die "Can't create relationship without join condition" unless $cond; + croak "Can't create relationship without join condition" unless $cond; $attrs ||= {}; my %rels = %{ $self->_relationships }; @@ -257,7 +257,7 @@ sub add_relationship { if ($@) { # If the resolve failed, back out and re-throw the error delete $rels{$rel}; # $self->_relationships(\%rels); - die "Error creating relationship $rel: $@"; + croak "Error creating relationship $rel: $@"; } 1; } @@ -309,10 +309,10 @@ sub resolve_join { $self->related_source($_)->resolve_join($join->{$_}, $_) } keys %$join; } elsif (ref $join) { - die("No idea how to resolve join reftype ".ref $join); + croak ("No idea how to resolve join reftype ".ref $join); } else { my $rel_info = $self->relationship_info($join); - die("No such relationship ${join}") unless $rel_info; + croak("No such relationship ${join}") unless $rel_info; my $type = $rel_info->{attrs}{join_type} || ''; return [ { $join => $self->related_source($join)->from, -join_type => $type }, @@ -335,8 +335,8 @@ sub resolve_condition { my %ret; while (my ($k, $v) = each %{$cond}) { # XXX should probably check these are valid columns - $k =~ s/^foreign\.// || die "Invalid rel cond key ${k}"; - $v =~ s/^self\.// || die "Invalid rel cond val ${v}"; + $k =~ s/^foreign\.// || croak "Invalid rel cond key ${k}"; + $v =~ s/^self\.// || croak "Invalid rel cond val ${v}"; if (ref $for) { # Object #warn "$self $k $for $v"; $ret{$k} = $for->get_column($v); diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index a03a3d7..26b0c14 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -3,6 +3,8 @@ package DBIx::Class::Row; use strict; use warnings; +use Carp qw/croak/; + use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/AccessorGroup/); @@ -37,7 +39,7 @@ sub new { if ($attrs) { $new->throw("attrs must be a hashref" ) unless ref($attrs) eq 'HASH'; while (my ($k, $v) = each %{$attrs}) { - die "No such column $k on $class" unless $class->has_column($k); + croak "No such column $k on $class" unless $class->has_column($k); $new->store_column($k => $v); } } @@ -60,7 +62,7 @@ sub insert { $self->{result_source} ||= $self->result_source_instance if $self->can('result_source_instance'); my $source = $self->{result_source}; - die "No result_source set on this object; can't insert" unless $source; + croak "No result_source set on this object; can't insert" unless $source; #use Data::Dumper; warn Dumper($self); $source->storage->insert($source->from, { $self->get_columns }); $self->in_storage(1); @@ -126,7 +128,7 @@ sub delete { $self->result_source->from, $self->ident_condition); $self->in_storage(undef); } else { - die "Can't do class delete without a ResultSource instance" + croak "Can't do class delete without a ResultSource instance" unless $self->can('result_source_instance'); my $attrs = { }; if (@_ > 1 && ref $_[$#_] eq 'HASH') { @@ -270,7 +272,7 @@ sub inflate_result { my $schema; PRE: foreach my $pre (keys %{$prefetch||{}}) { my $pre_source = $source->related_source($pre); - die "Can't prefetch non-existant relationship ${pre}" unless $pre_source; + croak "Can't prefetch non-existant relationship ${pre}" unless $pre_source; my $fetched = $pre_source->result_class->inflate_result( $pre_source, @{$prefetch->{$pre}}); my $accessor = $source->relationship_info($pre)->{attrs}{accessor}; diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index d9971d4..ba03d01 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -2,6 +2,8 @@ package DBIx::Class::Schema; use strict; use warnings; + +use Carp qw/croak/; use UNIVERSAL::require; use base qw/DBIx::Class/; @@ -119,7 +121,7 @@ sub source { # if we got here, they probably passed a full class name my $mapped = $self->class_mappings->{$moniker}; - die "Can't find source for ${moniker}" + croak "Can't find source for ${moniker}" unless $mapped && exists $sreg->{$mapped}; return $sreg->{$mapped}; } diff --git a/lib/DBIx/Class/UUIDColumns.pm b/lib/DBIx/Class/UUIDColumns.pm index dca0c58..08968da 100644 --- a/lib/DBIx/Class/UUIDColumns.pm +++ b/lib/DBIx/Class/UUIDColumns.pm @@ -1,6 +1,8 @@ package DBIx::Class::UUIDColumns; use base qw/DBIx::Class/; +use Carp qw/croak/; + use Data::UUID; __PACKAGE__->mk_classdata( 'uuid_auto_columns' => [] ); @@ -32,7 +34,7 @@ Note that the component needs to be loaded before Core. sub uuid_columns { my $self = shift; for (@_) { - die "column $_ doesn't exist" unless $self->has_column($_); + croak "column $_ doesn't exist" unless $self->has_column($_); } $self->uuid_auto_columns(\@_); }