- 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
use strict;
use warnings;
+
+use Carp qw/croak/;
+
use base qw/DBIx::Class::Row/;
=head1 NAME
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;
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);
}
use strict;
use warnings;
+use Carp qw/croak/;
+
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/PK::Auto/);
}
}
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 . "'.";
}
}
use strict;
use warnings;
+use Carp qw/croak/;
use overload
'0+' => 'count',
'bool' => sub { 1; },
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' => '*' },
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});
}
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;
}
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(
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 };
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;
}
$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 },
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);
use strict;
use warnings;
+use Carp qw/croak/;
+
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/AccessorGroup/);
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);
}
}
$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);
$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') {
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};
use strict;
use warnings;
+
+use Carp qw/croak/;
use UNIVERSAL::require;
use base qw/DBIx::Class/;
# 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};
}
package DBIx::Class::UUIDColumns;
use base qw/DBIx::Class/;
+use Carp qw/croak/;
+
use Data::UUID;
__PACKAGE__->mk_classdata( 'uuid_auto_columns' => [] );
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(\@_);
}