From: Peter Rabbitson Date: Mon, 23 Nov 2009 15:30:13 +0000 (+0000) Subject: Add missing Sub::Name invocations and improve the SQLA Carp overrides X-Git-Tag: v0.08116~129 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8637bb249bdda94dbbe47ad898cde0b7e89bad20;p=dbsrgits%2FDBIx-Class.git Add missing Sub::Name invocations and improve the SQLA Carp overrides --- diff --git a/lib/DBIx/Class/CDBICompat/Constructor.pm b/lib/DBIx/Class/CDBICompat/Constructor.pm index 190c223..f2e78b9 100644 --- a/lib/DBIx/Class/CDBICompat/Constructor.pm +++ b/lib/DBIx/Class/CDBICompat/Constructor.pm @@ -3,6 +3,8 @@ package # hide from PAUSE use base qw(DBIx::Class::CDBICompat::ImaDBI); +use Sub::Name(); + use strict; use warnings; @@ -22,7 +24,7 @@ sub add_constructor { return carp("$method already exists in $class") if *$meth{CODE}; - *$meth = sub { + *$meth = Sub::Name::subname $meth => sub { my $self = shift; $self->sth_to_objects($self->sql_Retrieve($fragment), \@_); }; diff --git a/lib/DBIx/Class/SQLAHacks.pm b/lib/DBIx/Class/SQLAHacks.pm index 429be4f..81661fb 100644 --- a/lib/DBIx/Class/SQLAHacks.pm +++ b/lib/DBIx/Class/SQLAHacks.pm @@ -9,6 +9,7 @@ use base qw/SQL::Abstract::Limit/; use strict; use warnings; use Carp::Clan qw/^DBIx::Class|^SQL::Abstract/; +use Sub::Name(); BEGIN { # reinstall the carp()/croak() functions imported into SQL::Abstract @@ -18,17 +19,15 @@ BEGIN { for my $f (qw/carp croak/) { my $orig = \&{"SQL::Abstract::$f"}; - *{"SQL::Abstract::$f"} = sub { - - local $Carp::CarpLevel = 1; # even though Carp::Clan ignores this, $orig will not - - if (Carp::longmess() =~ /DBIx::Class::SQLAHacks::[\w]+ .+? called \s at/x) { - __PACKAGE__->can($f)->(@_); - } - else { - $orig->(@_); - } - } + *{"SQL::Abstract::$f"} = Sub::Name::subname "SQL::Abstract::$f" => + sub { + if (Carp::longmess() =~ /DBIx::Class::SQLAHacks::[\w]+ .+? called \s at/x) { + __PACKAGE__->can($f)->(@_); + } + else { + goto $orig; + } + }; } } diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index 7e60cbf..c905730 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -908,7 +908,7 @@ sub compose_namespace { no strict 'refs'; no warnings 'redefine'; foreach my $meth (qw/class source resultset/) { - *{"${target}::${meth}"} = + *{"${target}::${meth}"} = Sub::Name::subname "${target}::${meth}" => sub { shift->schema->$meth(@_) }; } } diff --git a/t/95sql_maker.t b/t/95sql_maker.t index 629eed6..ec137e1 100644 --- a/t/95sql_maker.t +++ b/t/95sql_maker.t @@ -70,8 +70,7 @@ my $sql_maker = $schema->storage->sql_maker; } # Make sure the carp/croak override in SQLA works (via SQLAHacks) -my $file = __FILE__; -$file = "\Q$file\E"; +my $file = quotemeta (__FILE__); throws_ok (sub { $schema->resultset ('Artist')->search ({}, { order_by => { -asc => 'stuff', -desc => 'staff' } } )->as_query; }, qr/$file/, 'Exception correctly croak()ed');