X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FSQLAnywhere.pm;h=85b5614e6d219d699fabe2b536a4a90c9cf19062;hb=9e34d55419481925691c7177d43ba48ec02b02eb;hp=c8453794aea8df6d3afc0471bb581a00a878acd6;hpb=7e5fec1c5e5777334c7677c6aaa1a1699e2f2c6b;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm b/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm index c845379..85b5614 100644 --- a/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm +++ b/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm @@ -4,7 +4,9 @@ use strict; use warnings; use base qw/DBIx::Class::Storage::DBI::UniqueIdentifier/; use mro 'c3'; -use List::Util (); +use List::Util 'first'; +use Try::Tiny; +use namespace::clean; __PACKAGE__->mk_group_accessors(simple => qw/ _identity @@ -41,9 +43,8 @@ sub insert { my $self = shift; my ($source, $to_insert) = @_; - my $identity_col = List::Util::first { - $source->column_info($_)->{is_auto_increment} - } $source->columns; + my $identity_col = + first { $source->column_info($_)->{is_auto_increment} } $source->columns; # user might have an identity PK without is_auto_increment if (not $identity_col) { @@ -62,8 +63,8 @@ sub insert { my $table_name = $source->from; $table_name = $$table_name if ref $table_name; - my ($identity) = eval { - local $@; $dbh->selectrow_array("SELECT GET_IDENTITY('$table_name')") + my ($identity) = try { + $dbh->selectrow_array("SELECT GET_IDENTITY('$table_name')") }; if (defined $identity) { @@ -89,7 +90,7 @@ sub _select_args { my $data_type = $col_info->{$selected}{data_type}; - if ($data_type && $data_type =~ /^uniqueidentifier\z/i) { + if ($data_type && lc($data_type) eq 'uniqueidentifier') { $select->[$select_idx] = { UUIDTOSTR => $selected }; } } @@ -114,8 +115,13 @@ sub _sql_maker_opts { sub build_datetime_parser { my $self = shift; my $type = "DateTime::Format::Strptime"; - eval "use ${type}"; - $self->throw_exception("Couldn't load ${type}: $@") if $@; + try { + eval "require ${type}" + } + catch { + $self->throw_exception("Couldn't load ${type}: $_"); + }; + return $type->new( pattern => '%Y-%m-%d %H:%M:%S.%6N' ); }