From: Peter Rabbitson Date: Fri, 24 Oct 2014 12:06:54 +0000 (+0200) Subject: Replace a couple useless string evals with their equivalent X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=63a18cfe04b404ec09424385980b03e439f36d0c;p=dbsrgits%2FDBIx-Class.git Replace a couple useless string evals with their equivalent Dliberately *not* using Module::Runtime, future improvements will replace ->ensure_class_loaded with something less volatile --- diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index a9b312b..6349037 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -1470,13 +1470,12 @@ sub compose_connection { carp_once "compose_connection deprecated as of 0.08000" unless $INC{"DBIx/Class/CDBICompat.pm"}; - my $base = 'DBIx::Class::ResultSetProxy'; try { - eval "require ${base};" + require DBIx::Class::ResultSetProxy; } catch { $self->throw_exception - ("No arguments to load_classes and couldn't load ${base} ($_)") + ("No arguments to load_classes and couldn't load DBIx::Class::ResultSetProxy ($_)") }; if ($self eq $target) { @@ -1484,7 +1483,7 @@ sub compose_connection { foreach my $source_name ($self->sources) { my $source = $self->source($source_name); my $class = $source->result_class; - $self->inject_base($class, $base); + $self->inject_base($class, 'DBIx::Class::ResultSetProxy'); $class->mk_classdata(resultset_instance => $source->resultset); $class->mk_classdata(class_resolver => $self); } @@ -1492,7 +1491,7 @@ sub compose_connection { return $self; } - my $schema = $self->compose_namespace($target, $base); + my $schema = $self->compose_namespace($target, 'DBIx::Class::ResultSetProxy'); quote_sub "${target}::schema", '$s', { '$s' => \$schema }; $schema->connection(@info); diff --git a/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm b/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm index cbc07d5..9cdd038 100644 --- a/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm +++ b/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm @@ -139,15 +139,14 @@ sub select_single { sub build_datetime_parser { my $self = shift; - my $type = "DateTime::Format::Strptime"; try { - eval "require ${type}" + require DateTime::Format::Strptime; } catch { - $self->throw_exception("Couldn't load ${type}: $_"); + $self->throw_exception("Couldn't load DateTime::Format::Strptime: $_"); }; - return $type->new( pattern => '%Y-%m-%d %H:%M:%S.%6N' ); + return DateTime::Format::Strptime->new( pattern => '%Y-%m-%d %H:%M:%S.%6N' ); } =head2 connect_call_datetime_setup diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index e197491..59aec2a 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -16,6 +16,7 @@ use Exporter; use SQL::Translator::Utils qw(debug normalize_name); use DBIx::Class::Carp qw/^SQL::Translator|^DBIx::Class|^Try::Tiny/; use DBIx::Class::Exception; +use Class::C3::Componentised; use Scalar::Util 'blessed'; use Try::Tiny; use namespace::clean; @@ -53,8 +54,11 @@ sub parse { DBIx::Class::Exception->throw('No DBIx::Class::Schema') unless ($dbicschema); if (!ref $dbicschema) { - eval "require $dbicschema" - or DBIx::Class::Exception->throw("Can't load $dbicschema: $@"); + try { + Class::C3::Componentised->ensure_class_loaded($dbicschema) + } catch { + DBIx::Class::Exception->throw("Can't load $dbicschema: $_"); + } } if (