[Bast-commits] r7688 - in DBIx-Class/0.08/trunk/lib/DBIx/Class: .
Storage Storage/DBI Storage/DBI/ODBC
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Fri Sep 18 12:12:05 GMT 2009
Author: ribasushi
Date: 2009-09-18 12:12:05 +0000 (Fri, 18 Sep 2009)
New Revision: 7688
Modified:
DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSetColumn.pm
DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm
DBIx-Class/0.08/trunk/lib/DBIx/Class/Row.pm
DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage.pm
DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI.pm
DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm
DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated.pm
DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Sybase.pm
Log:
Cleanup exception handling
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm 2009-09-18 11:05:39 UTC (rev 7687)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm 2009-09-18 12:12:05 UTC (rev 7688)
@@ -7,6 +7,7 @@
'bool' => "_bool",
fallback => 1;
use Carp::Clan qw/^DBIx::Class/;
+use DBIx::Class::Exception;
use Data::Page;
use Storable;
use DBIx::Class::ResultSetColumn;
@@ -3117,12 +3118,13 @@
sub throw_exception {
my $self=shift;
+
if (ref $self && $self->_source_handle->schema) {
$self->_source_handle->schema->throw_exception(@_)
- } else {
- croak(@_);
}
-
+ else {
+ DBIx::Class::Exception->throw(@_);
+ }
}
# XXX: FIXME: Attributes docs need clearing up
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSetColumn.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSetColumn.pm 2009-09-18 11:05:39 UTC (rev 7687)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSetColumn.pm 2009-09-18 12:12:05 UTC (rev 7688)
@@ -1,7 +1,11 @@
package DBIx::Class::ResultSetColumn;
+
use strict;
use warnings;
+
use base 'DBIx::Class';
+
+use DBIx::Class::Exception;
use List::Util;
=head1 NAME
@@ -414,11 +418,13 @@
sub throw_exception {
my $self=shift;
+
if (ref $self && $self->{_parent_resultset}) {
- $self->{_parent_resultset}->throw_exception(@_)
- } else {
- croak(@_);
+ $self->{_parent_resultset}->throw_exception(@_);
}
+ else {
+ DBIx::Class::Exception->throw(@_);
+ }
}
# _resultset
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm 2009-09-18 11:05:39 UTC (rev 7687)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm 2009-09-18 12:12:05 UTC (rev 7688)
@@ -5,6 +5,8 @@
use DBIx::Class::ResultSet;
use DBIx::Class::ResultSourceHandle;
+
+use DBIx::Class::Exception;
use Carp::Clan qw/^DBIx::Class/;
use base qw/DBIx::Class/;
@@ -1591,11 +1593,13 @@
sub throw_exception {
my $self = shift;
- if (defined $self->schema) {
+
+ if (defined $self->schema);
$self->schema->throw_exception(@_);
- } else {
- croak(@_);
}
+ else {
+ DBIx::Class::Exception->throw(@_);
+ }
}
=head2 source_info
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Row.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Row.pm 2009-09-18 11:05:39 UTC (rev 7687)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Row.pm 2009-09-18 12:12:05 UTC (rev 7688)
@@ -4,9 +4,9 @@
use warnings;
use base qw/DBIx::Class/;
-use Carp::Clan qw/^DBIx::Class/;
+
+use DBIx::Class::Exception;
use Scalar::Util ();
-use Scope::Guard;
###
### Internal method
@@ -168,7 +168,8 @@
foreach my $key (keys %$attrs) {
if (ref $attrs->{$key}) {
## Can we extract this lot to use with update(_or .. ) ?
- confess "Can't do multi-create without result source" unless $source;
+ $new->throw_exception("Can't do multi-create without result source")
+ unless $source;
my $info = $source->relationship_info($key);
if ($info && $info->{attrs}{accessor}
&& $info->{attrs}{accessor} eq 'single')
@@ -1330,11 +1331,13 @@
sub throw_exception {
my $self=shift;
+
if (ref $self && ref $self->result_source && $self->result_source->schema) {
- $self->result_source->schema->throw_exception(@_);
- } else {
- croak(@_);
+ $self->result_source->schema->throw_exception(@_)
}
+ else {
+ DBIx::Class::Exception->throw(@_);
+ }
}
=head2 id
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm 2009-09-18 11:05:39 UTC (rev 7687)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm 2009-09-18 12:12:05 UTC (rev 7688)
@@ -5,7 +5,6 @@
use base qw/DBIx::Class::Storage::DBI::MSSQL/;
use mro 'c3';
-use Carp::Clan qw/^DBIx::Class/;
use List::Util();
use Scalar::Util ();
@@ -62,7 +61,7 @@
my $self = shift;
if (ref($self->_dbi_connect_info->[0]) eq 'CODE') {
- croak 'cannot set DBI attributes on a CODE ref connect_info';
+ $self->throw_exception ('cannot set DBI attributes on a CODE ref connect_info');
}
my $dbi_attrs = $self->_dbi_connect_info->[-1];
@@ -91,7 +90,7 @@
$dbh->do('SELECT @@IDENTITY');
};
if ($@) {
- croak <<'EOF';
+ $self->throw_exception (<<'EOF');
Your drivers do not seem to support dynamic cursors (odbc_cursortype => 2),
if you're using FreeTDS, make sure to set tds_version to 8.0 or greater.
@@ -105,8 +104,15 @@
sub _init {
my $self = shift;
- if (ref($self->_dbi_connect_info->[0]) ne 'CODE' &&
- eval { $self->_dbi_connect_info->[-1]{odbc_cursortype} } == 2) {
+ no warnings qw/uninitialized/;
+
+ if (
+ ref($self->_dbi_connect_info->[0]) ne 'CODE'
+ &&
+ ref ($self->_dbi_connect_info->[-1]) eq 'HASH'
+ &&
+ $self->_dbi_connect_info->[-1]{odbc_cursortype} == 2
+ ) {
$self->_set_dynamic_cursors;
return;
}
@@ -158,7 +164,7 @@
my $dsn = $self->_dbi_connect_info->[0];
if (ref($dsn) eq 'CODE') {
- croak 'cannot change the DBI DSN on a CODE ref connect_info';
+ $self->throw_exception('cannot change the DBI DSN on a CODE ref connect_info');
}
if ($dsn !~ /MARS_Connection=/) {
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated.pm 2009-09-18 11:05:39 UTC (rev 7687)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated.pm 2009-09-18 12:12:05 UTC (rev 7688)
@@ -17,9 +17,9 @@
my @didnt_load;
for my $module (keys %replication_required) {
- eval "use $module $replication_required{$module}";
- push @didnt_load, "$module $replication_required{$module}"
- if $@;
+ eval "use $module $replication_required{$module}";
+ push @didnt_load, "$module $replication_required{$module}"
+ if $@;
}
croak("@{[ join ', ', @didnt_load ]} are missing and are required for Replication")
@@ -33,7 +33,6 @@
use DBIx::Class::Storage::DBI::Replicated::Types qw/BalancerClassNamePart DBICSchema DBICStorageDBI/;
use MooseX::Types::Moose qw/ClassName HashRef Object/;
use Scalar::Util 'reftype';
-use Carp::Clan qw/^DBIx::Class/;
use Hash::Merge 'merge';
use namespace::clean -except => 'meta';
@@ -495,7 +494,7 @@
for my $r (@args) {
$r = [ $r ] unless reftype $r eq 'ARRAY';
- croak "coderef replicant connect_info not supported"
+ $self->throw_exception('coderef replicant connect_info not supported')
if ref $r->[0] && reftype $r->[0] eq 'CODE';
# any connect_info options?
@@ -508,10 +507,10 @@
# merge if two hashes
my @hashes = @$r[$i .. $#{$r}];
- croak "invalid connect_info options"
+ $self->throw_exception('invalid connect_info options')
if (grep { reftype($_) eq 'HASH' } @hashes) != @hashes;
- croak "too many hashrefs in connect_info"
+ $self->throw_exception('too many hashrefs in connect_info')
if @hashes > 2;
my %opts = %{ merge(reverse @hashes) };
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Sybase.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Sybase.pm 2009-09-18 11:05:39 UTC (rev 7687)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Sybase.pm 2009-09-18 12:12:05 UTC (rev 7688)
@@ -461,7 +461,7 @@
my (@primary_cols) = $source->primary_columns;
- croak "Cannot update TEXT/IMAGE column(s) without a primary key"
+ $self->throw_exception('Cannot update TEXT/IMAGE column(s) without a primary key')
unless @primary_cols;
# check if we're updating a single row by PK
@@ -496,12 +496,11 @@
my %row = %$row;
my (@primary_cols) = $source->primary_columns;
- croak "Cannot update TEXT/IMAGE column(s) without a primary key"
+ $self->throw_exception('Cannot update TEXT/IMAGE column(s) without a primary key')
unless @primary_cols;
- if ((grep { defined $row{$_} } @primary_cols) != @primary_cols) {
- croak "Cannot update TEXT/IMAGE column(s) without primary key values";
- }
+ $self->throw_exception('Cannot update TEXT/IMAGE column(s) without primary key values')
+ if ((grep { defined $row{$_} } @primary_cols) != @primary_cols);
for my $col (keys %$blob_cols) {
my $blob = $blob_cols->{$col};
@@ -535,12 +534,12 @@
$sth->finish if $sth;
if ($exception) {
if ($self->using_freetds) {
- croak (
+ $self->throw_exception (
'TEXT/IMAGE operation failed, probably because you are using FreeTDS: '
. $exception
);
} else {
- croak $exception;
+ $self->throw_exception($exception);
}
}
}
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI.pm 2009-09-18 11:05:39 UTC (rev 7687)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI.pm 2009-09-18 12:12:05 UTC (rev 7688)
@@ -1002,6 +1002,8 @@
$weak_self->throw_exception("DBI Exception: $_[0]");
}
else {
+ # the handler may be invoked by something totally out of
+ # the scope of DBIC
croak ("DBI Exception: $_[0]");
}
};
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage.pm 2009-09-18 11:05:39 UTC (rev 7687)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage.pm 2009-09-18 12:12:05 UTC (rev 7688)
@@ -6,8 +6,8 @@
use base qw/DBIx::Class/;
use mro 'c3';
-use Scalar::Util qw/weaken/;
-use Carp::Clan qw/^DBIx::Class/;
+use DBIx::Class::Exception;
+use Scalar::Util();
use IO::File;
use DBIx::Class::Storage::TxnScopeGuard;
@@ -83,7 +83,7 @@
sub set_schema {
my ($self, $schema) = @_;
$self->schema($schema);
- weaken($self->{schema}) if ref $self->{schema};
+ Scalar::Util::weaken($self->{schema}) if ref $self->{schema};
}
=head2 connected
@@ -120,8 +120,12 @@
sub throw_exception {
my $self = shift;
- $self->schema->throw_exception(@_) if $self->schema;
- croak @_;
+ if ($self->schema) {
+ $self->schema->throw_exception(@_);
+ }
+ else {
+ DBIx::Class::Exception->throw(@_);
+ }
}
=head2 txn_do
More information about the Bast-commits
mailing list