From: Peter Rabbitson Date: Thu, 17 Jul 2014 09:20:30 +0000 (+0200) Subject: is_X_value functions introduced in 3705e3b28 migrated to SQLA with fixups X-Git-Tag: v0.082800~133 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b5ce6748;p=dbsrgits%2FDBIx-Class.git is_X_value functions introduced in 3705e3b28 migrated to SQLA with fixups --- diff --git a/Makefile.PL b/Makefile.PL index 531f3f8..5a952e2 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -85,7 +85,7 @@ my $runtime_requires = { 'namespace::clean' => '0.24', 'Path::Class' => '0.18', 'Scope::Guard' => '0.03', - 'SQL::Abstract' => '1.78', + 'SQL::Abstract' => '1.78_02', # TEMPORARY 'Try::Tiny' => '0.07', # Technically this is not a core dependency - it is only required diff --git a/lib/DBIx/Class/FilterColumn.pm b/lib/DBIx/Class/FilterColumn.pm index eb46664..222dabd 100644 --- a/lib/DBIx/Class/FilterColumn.pm +++ b/lib/DBIx/Class/FilterColumn.pm @@ -3,7 +3,7 @@ use strict; use warnings; use base 'DBIx::Class::Row'; -use DBIx::Class::_Util 'is_literal_value'; +use SQL::Abstract 'is_literal_value'; use namespace::clean; sub filter_column { diff --git a/lib/DBIx/Class/InflateColumn.pm b/lib/DBIx/Class/InflateColumn.pm index 3236b1c..e10af30 100644 --- a/lib/DBIx/Class/InflateColumn.pm +++ b/lib/DBIx/Class/InflateColumn.pm @@ -4,7 +4,7 @@ use strict; use warnings; use base 'DBIx::Class::Row'; -use DBIx::Class::_Util 'is_literal_value'; +use SQL::Abstract 'is_literal_value'; use namespace::clean; =head1 NAME diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 7277ee2..d856ab5 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -9,7 +9,7 @@ use Scalar::Util 'blessed'; use List::Util 'first'; use Try::Tiny; use DBIx::Class::Carp; -use DBIx::Class::_Util 'is_literal_value'; +use SQL::Abstract 'is_literal_value'; ### ### Internal method diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 0e579e9..230a849 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -14,7 +14,7 @@ use Sub::Name 'subname'; use Context::Preserve 'preserve_context'; use Try::Tiny; use Data::Compare (); # no imports!!! guard against insane architecture -use DBIx::Class::_Util qw(is_plain_value is_literal_value); +use SQL::Abstract qw(is_plain_value is_literal_value); use namespace::clean; # default cursor class, overridable in connect_info attributes diff --git a/lib/DBIx/Class/Storage/DBI/SQLite.pm b/lib/DBIx/Class/Storage/DBI/SQLite.pm index 3024e89..fa6f806 100644 --- a/lib/DBIx/Class/Storage/DBI/SQLite.pm +++ b/lib/DBIx/Class/Storage/DBI/SQLite.pm @@ -6,7 +6,8 @@ use warnings; use base qw/DBIx::Class::Storage::DBI/; use mro 'c3'; -use DBIx::Class::_Util qw(modver_gt_or_eq sigwarn_silencer is_plain_value); +use SQL::Abstract 'is_plain_value'; +use DBIx::Class::_Util qw(modver_gt_or_eq sigwarn_silencer); use DBIx::Class::Carp; use Try::Tiny; use namespace::clean; diff --git a/lib/DBIx/Class/Storage/DBIHacks.pm b/lib/DBIx/Class/Storage/DBIHacks.pm index 7d974cf..ef89092 100644 --- a/lib/DBIx/Class/Storage/DBIHacks.pm +++ b/lib/DBIx/Class/Storage/DBIHacks.pm @@ -16,7 +16,8 @@ use mro 'c3'; use List::Util 'first'; use Scalar::Util 'blessed'; use Sub::Name 'subname'; -use DBIx::Class::_Util qw(is_plain_value is_literal_value UNRESOLVABLE_CONDITION); +use DBIx::Class::_Util 'UNRESOLVABLE_CONDITION'; +use SQL::Abstract qw(is_plain_value is_literal_value); use namespace::clean; # diff --git a/lib/DBIx/Class/_Util.pm b/lib/DBIx/Class/_Util.pm index a77f8a3..02de9a6 100644 --- a/lib/DBIx/Class/_Util.pm +++ b/lib/DBIx/Class/_Util.pm @@ -52,13 +52,11 @@ use DBIx::Class::Carp '^DBIx::Class|^DBICTest'; use Carp 'croak'; use Scalar::Util qw(weaken blessed reftype); use List::Util qw(first); -use overload (); use base 'Exporter'; our @EXPORT_OK = qw( sigwarn_silencer modver_gt_or_eq fail_on_internal_wantarray refdesc refcount hrefaddr is_exception - is_plain_value is_literal_value UNRESOLVABLE_CONDITION ); @@ -168,47 +166,6 @@ sub modver_gt_or_eq ($$) { eval { $mod->VERSION($ver) } ? 1 : 0; } -sub is_literal_value ($) { - ( - ref $_[0] eq 'SCALAR' - or - ( ref $_[0] eq 'HASH' and keys %{$_[0]} == 1 and defined $_[0]->{-ident} and ! length ref $_[0]->{-ident} ) - or - ( ref $_[0] eq 'REF' and ref ${$_[0]} eq 'ARRAY' ) - ) ? 1 : 0; -} - -# FIXME XSify - this can be done so much more efficiently -sub is_plain_value ($) { - no strict 'refs'; - ( - # plain scalar - (! length ref $_[0]) - or - ( - blessed $_[0] - and - # deliberately not using Devel::OverloadInfo - the checks we are - # intersted in are much more limited than the fullblown thing, and - # this is a relatively hot piece of code - ( - # FIXME - DBI needs fixing to stringify regardless of DBD - # - # either has stringification which DBI SHOULD prefer out of the box - #first { *{$_ . '::(""'}{CODE} } @{ mro::get_linear_isa( ref $_[0] ) } - overload::Method($_[0], '""') - or - # has nummification and fallback is *not* disabled - ( - $_[1] = first { *{"${_}::(0+"}{CODE} } @{ mro::get_linear_isa( ref $_[0] ) } - and - ( ! defined ${"$_[1]::()"} or ${"$_[1]::()"} ) - ) - ) - ) - ) ? 1 : 0; -} - { my $list_ctx_ok_stack_marker; diff --git a/t/53lean_startup.t b/t/53lean_startup.t index 311fa24..6868191 100644 --- a/t/53lean_startup.t +++ b/t/53lean_startup.t @@ -106,6 +106,7 @@ BEGIN { Class::Accessor::Grouped Class::C3::Componentised + SQL::Abstract )); require DBICTest::Schema; @@ -129,7 +130,6 @@ BEGIN { { register_lazy_loadable_requires(qw( DBI - SQL::Abstract Hash::Merge )); diff --git a/t/55namespaces_cleaned.t b/t/55namespaces_cleaned.t index 875a77d..0428069 100644 --- a/t/55namespaces_cleaned.t +++ b/t/55namespaces_cleaned.t @@ -149,9 +149,18 @@ for my $mod (@modules) { last; } } - fail ("${mod}::${name} appears to have entered inheritance chain by import into " - . ($via || 'UNKNOWN') - ); + + # exception time + if ( + ( $name eq 'import' and $via = 'Exporter' ) + ) { + pass("${mod}::${name} is a valid uncleaned import from ${name}"); + } + else { + fail ("${mod}::${name} appears to have entered inheritance chain by import into " + . ($via || 'UNKNOWN') + ); + } } } diff --git a/t/72pg.t b/t/72pg.t index c02a5e3..8e4b142 100644 --- a/t/72pg.t +++ b/t/72pg.t @@ -7,7 +7,7 @@ use Sub::Name; use DBIx::Class::Optional::Dependencies (); use lib qw(t/lib); use DBICTest; -use DBIx::Class::_Util 'is_literal_value'; +use SQL::Abstract 'is_literal_value'; plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_pg') unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_pg'); diff --git a/t/internals/is_plain_value.t b/t/internals/is_plain_value.t deleted file mode 100644 index 81fe902..0000000 --- a/t/internals/is_plain_value.t +++ /dev/null @@ -1,60 +0,0 @@ -use warnings; -use strict; - -use Test::More; -use Test::Warn; - -use lib qw(t/lib); -use DBICTest; - -use DBIx::Class::_Util 'is_plain_value'; - -{ - package # hideee - DBICTest::SillyInt; - - use overload - # *DELIBERATELY* unspecified - #fallback => 1, - '0+' => sub { ${$_[0]} }, - ; - - - package # hideee - DBICTest::SillyInt::Subclass; - - our @ISA = 'DBICTest::SillyInt'; - - - package # hideee - DBICTest::CrazyInt; - - use overload - '0+' => sub { 666 }, - '""' => sub { 999 }, - fallback => 1, - ; -} - -# check DBI behavior when fed a stringifiable/nummifiable value -{ - my $crazynum = bless {}, 'DBICTest::CrazyInt'; - cmp_ok( $crazynum, '==', 666 ); - cmp_ok( $crazynum, 'eq', 999 ); - - my $schema = DBICTest->init_schema( no_populate => 1 ); - $schema->storage->dbh_do(sub { - $_[1]->do('INSERT INTO artist (name) VALUES (?)', {}, $crazynum ); - }); - - is( $schema->resultset('Artist')->next->name, 999, 'DBI preferred stringified version' ); -} - -# make sure we recognize overloaded stuff properly -{ - my $num = bless( \do { my $foo = 69 }, 'DBICTest::SillyInt::Subclass' ); - ok( is_plain_value $num, 'parent-fallback-provided stringification detected' ); - is("$num", 69, 'test overloaded object stringifies, without specified fallback'); -} - -done_testing; diff --git a/t/sqlmaker/dbihacks_internals.t b/t/sqlmaker/dbihacks_internals.t index 84abaf1..1f555fc 100644 --- a/t/sqlmaker/dbihacks_internals.t +++ b/t/sqlmaker/dbihacks_internals.t @@ -5,7 +5,7 @@ use Test::Warn; use lib qw(t/lib); use DBICTest ':DiffSQL'; -use DBIx::Class::_Util qw(UNRESOLVABLE_CONDITION modver_gt_or_eq); +use DBIx::Class::_Util 'UNRESOLVABLE_CONDITION'; use Data::Dumper; @@ -132,9 +132,7 @@ for my $t ( efcc_result => { 'group.is_active' => 1, 'me.is_active' => 1 }, }, - # need fixed SQLA to correctly work with this - # - ( modver_gt_or_eq('SQL::Abstract', '1.78_01') ? { + { where => { -and => [ artistid => { -value => [1] }, charfield => { -ident => 'foo' }, @@ -159,7 +157,7 @@ for my $t ( charfield => { -ident => 'foo' }, rank => { -ident => 'bar' }, }, - } : () ), + }, { where => { artistid => [] }, diff --git a/t/storage/prefer_stringification.t b/t/storage/prefer_stringification.t new file mode 100644 index 0000000..ffb292a --- /dev/null +++ b/t/storage/prefer_stringification.t @@ -0,0 +1,33 @@ +use warnings; +use strict; + +use Test::More; + +use lib qw(t/lib); +use DBICTest; + +{ + package # hideee + DBICTest::CrazyInt; + + use overload + '0+' => sub { 666 }, + '""' => sub { 999 }, + fallback => 1, + ; +} + +# check DBI behavior when fed a stringifiable/nummifiable value +{ + my $crazynum = bless {}, 'DBICTest::CrazyInt'; + cmp_ok( $crazynum, '==', 666 ); + cmp_ok( $crazynum, 'eq', 999 ); + + my $schema = DBICTest->init_schema( no_populate => 1 ); + $schema->storage->dbh_do(sub { + $_[1]->do('INSERT INTO artist (name) VALUES (?)', {}, $crazynum ); + }); + + is( $schema->resultset('Artist')->next->name, 999, 'DBI preferred stringified version' ); +} +done_testing;