From: Rafael Kitover Date: Tue, 1 Jun 2010 14:46:52 +0000 (+0000) Subject: use namespace::cleaned out imports for some common utilities X-Git-Tag: v0.08122~32^2~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6298a324307439b76419d0f5db453b0d10f10517;p=dbsrgits%2FDBIx-Class.git use namespace::cleaned out imports for some common utilities --- diff --git a/lib/DBIx/Class/DB.pm b/lib/DBIx/Class/DB.pm index 3b2f7cc..5d459f9 100644 --- a/lib/DBIx/Class/DB.pm +++ b/lib/DBIx/Class/DB.pm @@ -8,7 +8,8 @@ use DBIx::Class::Schema; use DBIx::Class::Storage::DBI; use DBIx::Class::ClassResolver::PassThrough; use DBI; -use Scalar::Util; +use Scalar::Util 'blessed'; +use namespace::clean; unless ($INC{"DBIx/Class/CDBICompat.pm"}) { warn "IMPORTANT: DBIx::Class::DB is DEPRECATED AND *WILL* BE REMOVED. DO NOT USE.\n"; @@ -183,7 +184,7 @@ sub result_source_instance { } my($source, $result_class) = @{$class->_result_source_instance}; - return unless Scalar::Util::blessed($source); + return unless blessed $source; if ($result_class ne $class) { # new class # Give this new class its own source and register it. diff --git a/lib/DBIx/Class/Relationship/Base.pm b/lib/DBIx/Class/Relationship/Base.pm index d6563f4..ea6f391 100644 --- a/lib/DBIx/Class/Relationship/Base.pm +++ b/lib/DBIx/Class/Relationship/Base.pm @@ -3,8 +3,9 @@ package DBIx::Class::Relationship::Base; use strict; use warnings; -use Scalar::Util (); use base qw/DBIx::Class/; + +use Scalar::Util qw/weaken blessed/; use Try::Tiny; use namespace::clean; @@ -255,10 +256,10 @@ sub related_resultset { foreach my $rev_rel (keys %$reverse) { if ($reverse->{$rev_rel}{attrs}{accessor} && $reverse->{$rev_rel}{attrs}{accessor} eq 'multi') { $attrs->{related_objects}{$rev_rel} = [ $self ]; - Scalar::Util::weaken($attrs->{related_object}{$rev_rel}[0]); + weaken $attrs->{related_object}{$rev_rel}[0]; } else { $attrs->{related_objects}{$rev_rel} = $self; - Scalar::Util::weaken($attrs->{related_object}{$rev_rel}); + weaken $attrs->{related_object}{$rev_rel}; } } } @@ -459,7 +460,7 @@ sub set_from_related { if (defined $f_obj) { my $f_class = $rel_info->{class}; $self->throw_exception( "Object $f_obj isn't a ".$f_class ) - unless Scalar::Util::blessed($f_obj) and $f_obj->isa($f_class); + unless blessed $f_obj and $f_obj->isa($f_class); } $self->set_columns( $self->result_source->_resolve_condition( diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index cba01bc..e59a89c 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -2,10 +2,7 @@ package DBIx::Class::ResultSet; use strict; use warnings; -use overload - '0+' => "count", - 'bool' => "_bool", - fallback => 1; +use base qw/DBIx::Class/; use Carp::Clan qw/^DBIx::Class/; use DBIx::Class::Exception; use Data::Page; @@ -13,8 +10,13 @@ use Storable; use DBIx::Class::ResultSetColumn; use DBIx::Class::ResultSourceHandle; use List::Util (); -use Scalar::Util (); -use base qw/DBIx::Class/; +use Scalar::Util 'blessed'; +use namespace::clean; + +use overload + '0+' => "count", + 'bool' => "_bool", + fallback => 1; __PACKAGE__->mk_group_accessors('simple' => qw/_result_class _source_handle/); @@ -1933,7 +1935,7 @@ sub _is_deterministic_value { my $value = shift; my $ref_type = ref $value; return 1 if $ref_type eq '' || $ref_type eq 'SCALAR'; - return 1 if Scalar::Util::blessed($value); + return 1 if blessed $value; return 0; } diff --git a/lib/DBIx/Class/ResultSetColumn.pm b/lib/DBIx/Class/ResultSetColumn.pm index 4017466..13aeb85 100644 --- a/lib/DBIx/Class/ResultSetColumn.pm +++ b/lib/DBIx/Class/ResultSetColumn.pm @@ -7,7 +7,8 @@ use base 'DBIx::Class'; use Carp::Clan qw/^DBIx::Class/; use DBIx::Class::Exception; -use List::Util; +use List::Util (); +use namespace::clean; =head1 NAME diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index 492720c..34e5a7f 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -9,6 +9,7 @@ use DBIx::Class::ResultSourceHandle; use DBIx::Class::Exception; use Carp::Clan qw/^DBIx::Class/; use Try::Tiny; +use List::Util 'first'; use namespace::clean; use base qw/DBIx::Class/; @@ -1292,7 +1293,7 @@ sub _resolve_join { -is_single => ( $rel_info->{attrs}{accessor} && - List::Util::first { $rel_info->{attrs}{accessor} eq $_ } (qw/single filter/) + first { $rel_info->{attrs}{accessor} eq $_ } (qw/single filter/) ), -alias => $as, -relation_chain_depth => $seen->{-relation_chain_depth} || 0, diff --git a/lib/DBIx/Class/ResultSourceProxy/Table.pm b/lib/DBIx/Class/ResultSourceProxy/Table.pm index db82b47..1a0297f 100644 --- a/lib/DBIx/Class/ResultSourceProxy/Table.pm +++ b/lib/DBIx/Class/ResultSourceProxy/Table.pm @@ -6,7 +6,8 @@ use warnings; use base qw/DBIx::Class::ResultSourceProxy/; use DBIx::Class::ResultSource::Table; -use Scalar::Util (); +use Scalar::Util 'blessed'; +use namespace::clean; __PACKAGE__->mk_classdata(table_class => 'DBIx::Class::ResultSource::Table'); @@ -80,7 +81,7 @@ sub table { my ($class, $table) = @_; return $class->result_source_instance->name unless $table; - unless (Scalar::Util::blessed($table) && $table->isa($class->table_class)) { + unless (blessed $table && $table->isa($class->table_class)) { my $table_class = $class->table_class; $class->ensure_class_loaded($table_class); diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 1faee57..5555c57 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -6,7 +6,7 @@ use warnings; use base qw/DBIx::Class/; use DBIx::Class::Exception; -use Scalar::Util (); +use Scalar::Util 'blessed'; use Try::Tiny; use namespace::clean; @@ -190,7 +190,7 @@ sub new { my $acc_type = $info->{attrs}{accessor} || ''; if ($acc_type eq 'single') { my $rel_obj = delete $attrs->{$key}; - if(!Scalar::Util::blessed($rel_obj)) { + if(!blessed $rel_obj) { $rel_obj = $new->__new_related_find_or_new_helper($key, $rel_obj); } @@ -210,7 +210,7 @@ sub new { my @objects; foreach my $idx (0 .. $#$others) { my $rel_obj = $others->[$idx]; - if(!Scalar::Util::blessed($rel_obj)) { + if(!blessed $rel_obj) { $rel_obj = $new->__new_related_find_or_new_helper($key, $rel_obj); } @@ -228,7 +228,7 @@ sub new { elsif ($acc_type eq 'filter') { ## 'filter' should disappear and get merged in with 'single' above! my $rel_obj = delete $attrs->{$key}; - if(!Scalar::Util::blessed($rel_obj)) { + if(!blessed $rel_obj) { $rel_obj = $new->__new_related_find_or_new_helper($key, $rel_obj); } if ($rel_obj->in_storage) { @@ -304,8 +304,7 @@ sub insert { my $rel_obj = $related_stuff{$relname}; if (! $self->{_rel_in_storage}{$relname}) { - next unless (Scalar::Util::blessed($rel_obj) - && $rel_obj->isa('DBIx::Class::Row')); + next unless (blessed $rel_obj && $rel_obj->isa('DBIx::Class::Row')); next unless $source->_pk_depends_on( $relname, { $rel_obj->get_columns } @@ -399,9 +398,7 @@ sub insert { : $related_stuff{$relname} ; - if (@cands - && Scalar::Util::blessed($cands[0]) - && $cands[0]->isa('DBIx::Class::Row') + if (@cands && blessed $cands[0] && $cands[0]->isa('DBIx::Class::Row') ) { my $reverse = $source->reverse_relationship_info($relname); foreach my $obj (@cands) { diff --git a/lib/DBIx/Class/SQLAHacks.pm b/lib/DBIx/Class/SQLAHacks.pm index 32cc47f..db67bcf 100644 --- a/lib/DBIx/Class/SQLAHacks.pm +++ b/lib/DBIx/Class/SQLAHacks.pm @@ -9,7 +9,9 @@ use base qw/SQL::Abstract::Limit/; use strict; use warnings; use Carp::Clan qw/^DBIx::Class|^SQL::Abstract/; -use Sub::Name(); +use List::Util 'first'; +use Sub::Name 'subname'; +use namespace::clean; BEGIN { # reinstall the carp()/croak() functions imported into SQL::Abstract @@ -19,7 +21,7 @@ BEGIN { for my $f (qw/carp croak/) { my $orig = \&{"SQL::Abstract::$f"}; - *{"SQL::Abstract::$f"} = Sub::Name::subname "SQL::Abstract::$f" => + *{"SQL::Abstract::$f"} = subname "SQL::Abstract::$f" => sub { if (Carp::longmess() =~ /DBIx::Class::SQLAHacks::[\w]+ .+? called \s at/x) { __PACKAGE__->can($f)->(@_); @@ -115,7 +117,7 @@ sub _subqueried_limit_attrs { # for possible further chaining) my (@in_sel, @out_sel, %renamed); for my $node (@sel) { - if (List::Util::first { $_ =~ / (?{as}, $node->{unquoted_sql}) ) { + if (first { $_ =~ / (?{as}, $node->{unquoted_sql}) ) { $node->{as} =~ s/ $re_sep /__/xg; my $quoted_as = $self->_quote($node->{as}); push @in_sel, sprintf '%s AS %s', $node->{sql}, $quoted_as; diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index b493d6c..8046903 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -6,10 +6,11 @@ use warnings; use DBIx::Class::Exception; use Carp::Clan qw/^DBIx::Class/; use Try::Tiny; -use Scalar::Util (); +use Scalar::Util 'weaken'; use File::Spec; -use Sub::Name (); +use Sub::Name 'subname'; use Module::Find(); +use Storable(); use namespace::clean; use base qw/DBIx::Class/; @@ -919,7 +920,7 @@ sub compose_namespace { no strict 'refs'; no warnings 'redefine'; foreach my $meth (qw/class source resultset/) { - *{"${target}::${meth}"} = Sub::Name::subname "${target}::${meth}" => + *{"${target}::${meth}"} = subname "${target}::${meth}" => sub { shift->schema->$meth(@_) }; } } @@ -1323,7 +1324,7 @@ sub _register_source { $source = $source->new({ %$source, source_name => $moniker }); $source->schema($self); - Scalar::Util::weaken($source->{schema}) if ref($self); + weaken $source->{schema} if ref($self); my $rs_class = $source->result_class; @@ -1431,7 +1432,7 @@ more information. { no strict 'refs'; my $name = join '::', $target, 'schema'; - *$name = Sub::Name::subname $name, sub { $schema }; + *$name = subname $name, sub { $schema }; } $schema->connection(@info); diff --git a/lib/DBIx/Class/Storage.pm b/lib/DBIx/Class/Storage.pm index e8bc77b..bec0133 100644 --- a/lib/DBIx/Class/Storage.pm +++ b/lib/DBIx/Class/Storage.pm @@ -7,7 +7,7 @@ use base qw/DBIx::Class/; use mro 'c3'; use DBIx::Class::Exception; -use Scalar::Util(); +use Scalar::Util 'weaken'; use IO::File; use DBIx::Class::Storage::TxnScopeGuard; use Try::Tiny; @@ -85,7 +85,7 @@ storage object, such as during L. sub set_schema { my ($self, $schema) = @_; $self->schema($schema); - Scalar::Util::weaken($self->{schema}) if ref $self->{schema}; + weaken $self->{schema} if ref $self->{schema}; } =head2 connected diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 3dbfd39..1630180 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -11,12 +11,11 @@ use Carp::Clan qw/^DBIx::Class/; use DBI; use DBIx::Class::Storage::DBI::Cursor; use DBIx::Class::Storage::Statistics; -use Scalar::Util(); -use List::Util(); -use Data::Dumper::Concise(); -use Sub::Name (); +use Scalar::Util qw/refaddr weaken reftype blessed/; +use Data::Dumper::Concise 'Dumper'; +use Sub::Name 'subname'; use Try::Tiny; -use File::Path (); +use File::Path 'mkpath'; use namespace::clean; __PACKAGE__->mk_group_accessors('simple' => qw/ @@ -67,7 +66,7 @@ for my $meth (@rdbms_specific_methods) { no strict qw/refs/; no warnings qw/redefine/; - *{__PACKAGE__ ."::$meth"} = Sub::Name::subname $meth => sub { + *{__PACKAGE__ ."::$meth"} = subname $meth => sub { if (not $_[0]->_driver_determined) { $_[0]->_determine_driver; goto $_[0]->can($meth); @@ -1056,7 +1055,7 @@ sub _determine_driver { } else { # if connect_info is a CODEREF, we have no choice but to connect if (ref $self->_dbi_connect_info->[0] && - Scalar::Util::reftype($self->_dbi_connect_info->[0]) eq 'CODE') { + reftype $self->_dbi_connect_info->[0] eq 'CODE') { $self->_populate_dbh; $driver = $self->_dbh->{Driver}{Name}; } @@ -1177,7 +1176,7 @@ sub _connect { unless ($self->unsafe) { my $weak_self = $self; - Scalar::Util::weaken($weak_self); + weaken $weak_self; $dbh->{HandleError} = sub { if ($weak_self) { $weak_self->throw_exception("DBI Exception: $_[0]"); @@ -1392,7 +1391,7 @@ sub _dbh_rollback { sub _prep_for_execute { my ($self, $op, $extra_bind, $ident, $args) = @_; - if( Scalar::Util::blessed($ident) && $ident->isa("DBIx::Class::ResultSource") ) { + if( blessed $ident && $ident->isa("DBIx::Class::ResultSource") ) { $ident = $ident->from(); } @@ -1563,9 +1562,9 @@ sub insert_bulk { $cols->[$col_idx], do { local $Data::Dumper::Maxdepth = 1; # don't dump objects, if any - Data::Dumper::Concise::Dumper({ + Dumper { map { $cols->[$_] => $data->[$slice_idx][$_] } (0 .. $#$cols) - }), + }, } ); }; @@ -1704,9 +1703,7 @@ sub _execute_array { $self->throw_exception(sprintf "%s for populate slice:\n%s", ($tuple_status->[$i][1] || $err), - Data::Dumper::Concise::Dumper({ - map { $cols->[$_] => $data->[$i][$_] } (0 .. $#$cols) - }), + Dumper { map { $cols->[$_] => $data->[$i][$_] } (0 .. $#$cols) }, ); } @@ -2330,7 +2327,7 @@ sub create_ddl_dir { carp "No directory given, using ./\n"; $dir = './'; } else { - -d $dir or File::Path::mkpath($dir) + -d $dir or mkpath $dir or $self->throw_exception("create_ddl_dir: $! creating dir '$dir'"); } diff --git a/lib/DBIx/Class/Storage/DBI/Informix.pm b/lib/DBIx/Class/Storage/DBI/Informix.pm index 8f23077..414c391 100644 --- a/lib/DBIx/Class/Storage/DBI/Informix.pm +++ b/lib/DBIx/Class/Storage/DBI/Informix.pm @@ -6,7 +6,8 @@ use base qw/DBIx::Class::Storage::DBI/; use mro 'c3'; use Scope::Guard (); -use Context::Preserve (); +use Context::Preserve 'preserve_context'; +use namespace::clean; __PACKAGE__->mk_group_accessors('simple' => '__last_insert_id'); @@ -72,8 +73,7 @@ sub with_deferred_fk_checks { $self->_do_query('SET CONSTRAINTS ALL IMMEDIATE'); }); - return Context::Preserve::preserve_context(sub { $sub->() }, - after => sub { $txn_scope_guard->commit }); + return preserve_context { $sub->() } after => sub { $txn_scope_guard->commit }; } =head2 connect_call_datetime_setup diff --git a/lib/DBIx/Class/Storage/DBI/InterBase.pm b/lib/DBIx/Class/Storage/DBI/InterBase.pm index 4af0ddd..3bce156 100644 --- a/lib/DBIx/Class/Storage/DBI/InterBase.pm +++ b/lib/DBIx/Class/Storage/DBI/InterBase.pm @@ -4,7 +4,7 @@ use strict; use warnings; use base qw/DBIx::Class::Storage::DBI/; use mro 'c3'; -use List::Util(); +use List::Util 'first'; use Try::Tiny; use namespace::clean; @@ -80,7 +80,7 @@ EOF $generator = uc $generator unless $quoted; return $generator - if List::Util::first { + if first { $self->sql_maker->quote_char ? ($_ eq $col) : (uc($_) eq uc($col)) } @trig_cols; } diff --git a/lib/DBIx/Class/Storage/DBI/MSSQL.pm b/lib/DBIx/Class/Storage/DBI/MSSQL.pm index ea4b079..13ea644 100644 --- a/lib/DBIx/Class/Storage/DBI/MSSQL.pm +++ b/lib/DBIx/Class/Storage/DBI/MSSQL.pm @@ -6,10 +6,9 @@ use warnings; use base qw/DBIx::Class::Storage::DBI::UniqueIdentifier/; use mro 'c3'; use Try::Tiny; +use List::Util 'first'; use namespace::clean; -use List::Util(); - __PACKAGE__->mk_group_accessors(simple => qw/ _identity _identity_method /); @@ -50,12 +49,8 @@ sub insert_bulk { my $self = shift; my ($source, $cols, $data) = @_; - my $is_identity_insert = (List::Util::first - { $source->column_info ($_)->{is_auto_increment} } - (@{$cols}) - ) - ? 1 - : 0; + my $is_identity_insert = + (first { $source->column_info ($_)->{is_auto_increment} } @{$cols}) ? 1 : 0; if ($is_identity_insert) { $self->_set_identity_insert ($source->name); @@ -74,9 +69,8 @@ sub insert { my $supplied_col_info = $self->_resolve_column_info($source, [keys %$to_insert] ); - my $is_identity_insert = (List::Util::first { $_->{is_auto_increment} } (values %$supplied_col_info) ) - ? 1 - : 0; + my $is_identity_insert = + (first { $_->{is_auto_increment} } values %$supplied_col_info) ? 1 : 0; if ($is_identity_insert) { $self->_set_identity_insert ($source->name); diff --git a/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm b/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm index 694520f..b2db13f 100644 --- a/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm +++ b/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm @@ -4,9 +4,7 @@ use warnings; use base qw/DBIx::Class::Storage::DBI::MSSQL/; use mro 'c3'; - -use List::Util(); -use Scalar::Util (); +use Scalar::Util 'reftype'; use Try::Tiny; use namespace::clean; @@ -68,7 +66,7 @@ sub connect_call_use_dynamic_cursors { my $dbi_attrs = $self->_dbi_connect_info->[-1]; - unless (ref($dbi_attrs) && Scalar::Util::reftype($dbi_attrs) eq 'HASH') { + unless (ref($dbi_attrs) && reftype $dbi_attrs eq 'HASH') { $dbi_attrs = {}; push @{ $self->_dbi_connect_info }, $dbi_attrs; } diff --git a/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm b/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm index 933de9d..368ef42 100644 --- a/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm +++ b/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm @@ -3,7 +3,7 @@ package DBIx::Class::Storage::DBI::Oracle::Generic; use strict; use warnings; use Scope::Guard (); -use Context::Preserve (); +use Context::Preserve 'preserve_context'; use Try::Tiny; use namespace::clean; @@ -361,8 +361,8 @@ sub with_deferred_fk_checks { $self->_do_query('alter session set constraints = immediate'); }); - return Context::Preserve::preserve_context(sub { $sub->() }, - after => sub { $txn_scope_guard->commit }); + return + preserve_context { $sub->() } after => sub { $txn_scope_guard->commit }; } =head1 AUTHOR diff --git a/lib/DBIx/Class/Storage/DBI/Pg.pm b/lib/DBIx/Class/Storage/DBI/Pg.pm index 4428b1f..5814b71 100644 --- a/lib/DBIx/Class/Storage/DBI/Pg.pm +++ b/lib/DBIx/Class/Storage/DBI/Pg.pm @@ -10,7 +10,8 @@ use mro 'c3'; use DBD::Pg qw(:pg_types); use Scope::Guard (); -use Context::Preserve (); +use Context::Preserve 'preserve_context'; +use namespace::clean; # Ask for a DBD::Pg with array support warn __PACKAGE__.": DBD::Pg 2.9.2 or greater is strongly recommended\n" @@ -36,8 +37,7 @@ sub with_deferred_fk_checks { $self->_do_query('SET CONSTRAINTS ALL IMMEDIATE'); }); - return Context::Preserve::preserve_context(sub { $sub->() }, - after => sub { $txn_scope_guard->commit }); + return preserve_context { $sub->() } after => sub { $txn_scope_guard->commit }; } # only used when INSERT ... RETURNING is disabled diff --git a/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm b/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm index 5d9170d..85b5614 100644 --- a/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm +++ b/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm @@ -4,7 +4,7 @@ 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; @@ -43,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) { diff --git a/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm b/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm index 1c5bccf..80d7913 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm @@ -9,10 +9,10 @@ use base qw/ /; use mro 'c3'; use Carp::Clan qw/^DBIx::Class/; -use Scalar::Util(); -use List::Util(); +use Scalar::Util 'blessed'; +use List::Util 'first'; use Sub::Name(); -use Data::Dumper::Concise(); +use Data::Dumper::Concise 'Dumper'; use Try::Tiny; use namespace::clean; @@ -249,19 +249,18 @@ sub _prep_for_execute { my ($sql, $bind) = $self->next::method (@_); - my $table = Scalar::Util::blessed($ident) ? $ident->from : $ident; + my $table = blessed $ident ? $ident->from : $ident; my $bind_info = $self->_resolve_column_info( $ident, [map $_->[0], @{$bind}] ); - my $bound_identity_col = List::Util::first - { $bind_info->{$_}{is_auto_increment} } - (keys %$bind_info) + my $bound_identity_col = + first { $bind_info->{$_}{is_auto_increment} } + keys %$bind_info ; - my $identity_col = Scalar::Util::blessed($ident) && - List::Util::first - { $ident->column_info($_)->{is_auto_increment} } - $ident->columns + my $identity_col = + blessed $ident && + first { $ident->column_info($_)->{is_auto_increment} } $ident->columns ; if (($op eq 'insert' && $bound_identity_col) || @@ -349,9 +348,9 @@ 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) + || ''; # check for empty insert # INSERT INTO foo DEFAULT VALUES -- does not work with Sybase @@ -434,9 +433,8 @@ sub update { my $table = $source->name; - 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; my $is_identity_update = $identity_col && defined $fields->{$identity_col}; @@ -485,14 +483,10 @@ sub insert_bulk { my $self = shift; my ($source, $cols, $data) = @_; - 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; - my $is_identity_insert = (List::Util::first - { $_ eq $identity_col } - @{$cols} - ) ? 1 : 0; + my $is_identity_insert = (first { $_ eq $identity_col } @{$cols}) ? 1 : 0; my @source_columns = $source->columns; @@ -789,7 +783,7 @@ sub _insert_blobs { if (not $sth) { $self->throw_exception( "Could not find row in table '$table' for blob update:\n" - . Data::Dumper::Concise::Dumper (\%where) + . (Dumper \%where) ); } diff --git a/lib/DBIx/Class/Storage/DBI/Sybase/ASE/NoBindVars.pm b/lib/DBIx/Class/Storage/DBI/Sybase/ASE/NoBindVars.pm index 3dee4c3..8eeee49 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase/ASE/NoBindVars.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase/ASE/NoBindVars.pm @@ -5,8 +5,9 @@ use base qw/ DBIx::Class::Storage::DBI::Sybase::ASE /; use mro 'c3'; -use List::Util (); -use Scalar::Util (); +use List::Util 'first'; +use Scalar::Util 'looks_like_number'; +use namespace::clean; sub _init { my $self = shift; @@ -17,7 +18,7 @@ sub _init { sub _fetch_identity_sql { 'SELECT ' . $_[0]->_identity_method } -my $number = sub { Scalar::Util::looks_like_number($_[0]) }; +my $number = sub { looks_like_number $_[0] }; my $decimal = sub { $_[0] =~ /^ [-+]? \d+ (?:\.\d*)? \z/x }; @@ -38,7 +39,7 @@ sub interpolate_unquoted { return $self->next::method(@_) if not defined $value or not defined $type; - if (my $key = List::Util::first { $type =~ /$_/i } keys %noquote) { + if (my $key = first { $type =~ /$_/i } keys %noquote) { return 1 if $noquote{$key}->($value); } elsif ($self->is_datatype_numeric($type) && $number->($value)) { diff --git a/lib/DBIx/Class/Storage/DBIHacks.pm b/lib/DBIx/Class/Storage/DBIHacks.pm index f16c935..10be912 100644 --- a/lib/DBIx/Class/Storage/DBIHacks.pm +++ b/lib/DBIx/Class/Storage/DBIHacks.pm @@ -14,6 +14,9 @@ use base 'DBIx::Class::Storage'; use mro 'c3'; use Carp::Clan qw/^DBIx::Class/; +use List::Util 'first'; +use Scalar::Util 'blessed'; +use namespace::clean; # # This code will remove non-selecting/non-restricting joins from @@ -105,10 +108,7 @@ sub _adjust_select_args_for_complex_prefetch { # if a multi-type join was needed in the subquery - add a group_by to simulate the # collapse in the subq $inner_attrs->{group_by} ||= $inner_select - if List::Util::first - { ! $_->[0]{-is_single} } - (@{$inner_from}[1 .. $#$inner_from]) - ; + if first { ! $_->[0]{-is_single} } (@{$inner_from}[1 .. $#$inner_from]); # generate the subquery my $subq = $self->_select_args_to_query ( @@ -324,7 +324,7 @@ sub _resolve_ident_sources { # the reason this is so contrived is that $ident may be a {from} # structure, specifying multiple tables to join - if ( Scalar::Util::blessed($ident) && $ident->isa("DBIx::Class::ResultSource") ) { + if ( blessed $ident && $ident->isa("DBIx::Class::ResultSource") ) { # this is compat mode for insert/update/delete which do not deal with aliases $alias2source->{me} = $ident; $rs_alias = 'me'; diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index e4e480a..ad5998d 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -15,7 +15,7 @@ $DEBUG = 0 unless defined $DEBUG; use Exporter; use SQL::Translator::Utils qw(debug normalize_name); use Carp::Clan qw/^SQL::Translator|^DBIx::Class|^Try::Tiny/; -use Scalar::Util (); +use Scalar::Util 'weaken'; use Try::Tiny; use namespace::clean; @@ -35,7 +35,7 @@ use base qw(Exporter); sub parse { # this is a hack to prevent schema leaks due to a retarded SQLT implementation # DO NOT REMOVE (until SQLT2 is out, the all of this will be rewritten anyway) - Scalar::Util::weaken ($_[1]) if ref ($_[1]); + weaken $_[1] if ref ($_[1]); my ($tr, $data) = @_; my $args = $tr->parser_args; diff --git a/t/03podcoverage.t b/t/03podcoverage.t index eb08157..18df9cf 100644 --- a/t/03podcoverage.t +++ b/t/03podcoverage.t @@ -2,9 +2,10 @@ use warnings; use strict; use Test::More; -use List::Util (); +use List::Util 'first'; use lib qw(t/lib); use DBICTest; +use namespace::clean; # Don't run tests for installs unless ( DBICTest::AuthorCheck->is_author || $ENV{AUTOMATED_TESTING} || $ENV{RELEASE_TESTING} ) { @@ -140,8 +141,8 @@ my @modules = sort { $a cmp $b } (Test::Pod::Coverage::all_modules()); foreach my $module (@modules) { SKIP: { - my ($match) = List::Util::first - { $module =~ $_ } + my ($match) = + first { $module =~ $_ } (sort { length $b <=> length $a || $b cmp $a } (keys %$ex_lookup) ) ; diff --git a/t/52cycle.t b/t/52cycle.t index dc5f326..ba7fdd8 100644 --- a/t/52cycle.t +++ b/t/52cycle.t @@ -12,7 +12,8 @@ BEGIN { use DBICTest; use DBICTest::Schema; -use Scalar::Util (); +use Scalar::Util 'weaken'; +use namespace::clean; import Test::Memory::Cycle; @@ -31,7 +32,7 @@ my $weak; my $row = $weak->{row} = $rs->first; memory_cycle_ok($row, 'No cycles in row'); - Scalar::Util::weaken ($_) for values %$weak; + weaken $_ for values %$weak; memory_cycle_ok($weak, 'No cycles in weak object collection'); } diff --git a/t/cdbi/02-Film.t b/t/cdbi/02-Film.t index 3a4d70a..f1477cc 100644 --- a/t/cdbi/02-Film.t +++ b/t/cdbi/02-Film.t @@ -1,5 +1,7 @@ use strict; use Test::More; +use Scalar::Util 'refaddr'; +use namespace::clean; $| = 1; BEGIN { @@ -383,21 +385,21 @@ SKIP: { # my bad taste is your bad taste my $btaste = Film->retrieve('Bad Taste'); my $btaste2 = Film->retrieve('Bad Taste'); - is Scalar::Util::refaddr($btaste), Scalar::Util::refaddr($btaste2), + is refaddr $btaste, refaddr $btaste2, "Retrieving twice gives ref to same object"; my ($btaste5) = Film->search(title=>'Bad Taste'); - is Scalar::Util::refaddr($btaste), Scalar::Util::refaddr($btaste5), + is refaddr $btaste, refaddr $btaste5, "Searching also gives ref to same object"; $btaste2->remove_from_object_index; my $btaste3 = Film->retrieve('Bad Taste'); - isnt Scalar::Util::refaddr($btaste2), Scalar::Util::refaddr($btaste3), + isnt refaddr $btaste2, refaddr $btaste3, "Removing from object_index and retrieving again gives new object"; $btaste3->clear_object_index; my $btaste4 = Film->retrieve('Bad Taste'); - isnt Scalar::Util::refaddr($btaste2), Scalar::Util::refaddr($btaste4), + isnt refaddr $btaste2, refaddr $btaste4, "Clearing cache and retrieving again gives new object"; $btaste=Film->insert({ @@ -407,7 +409,7 @@ SKIP: { NumExplodingSheep => 2, }); $btaste2 = Film->retrieve('Bad Taste 2'); - is Scalar::Util::refaddr($btaste), Scalar::Util::refaddr($btaste2), + is refaddr $btaste, refaddr $btaste2, "Creating and retrieving gives ref to same object"; }