From: Peter Rabbitson Date: Thu, 29 Sep 2016 10:59:27 +0000 (+0200) Subject: Mark forgotten ::Row::id() method as indirect_sugar X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=97940e368df996e1fe6111fb14f560594dc4c0b2;p=dbsrgits%2FDBIx-Class.git Mark forgotten ::Row::id() method as indirect_sugar Discouraged legacy sugar, which does not even work properly with multicolumn keys in scalar context. Mark properly as INDIRECT to ensure DBIC does not rely on it anywhere Also adjust the SanityChecker to not complain about shadowing of sugar methods with generated ones (i.e. column accessors) - while unfortunate, this kind of thing happens quite often (especially with such a generic name as 'id') and warning about it would make no sense (left alone that methods which are ..._generated_from_resultsource_metadata generally do not invoke next::method anyway) --- diff --git a/lib/DBIx/Class/PK.pm b/lib/DBIx/Class/PK.pm index 9bda5ca..0ef470b 100644 --- a/lib/DBIx/Class/PK.pm +++ b/lib/DBIx/Class/PK.pm @@ -5,6 +5,9 @@ use warnings; use base qw/DBIx::Class::Row/; +use DBIx::Class::_Util 'fail_on_internal_call'; +use namespace::clean; + =head1 NAME DBIx::Class::PK - Primary Key class @@ -27,12 +30,16 @@ a class method. =cut -sub id { - my ($self) = @_; - $self->throw_exception( "Can't call id() as a class method" ) - unless ref $self; - my @id_vals = $self->_ident_values; - return (wantarray ? @id_vals : $id_vals[0]); +sub id :DBIC_method_is_indirect_sugar { + DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_INDIRECT_CALLS and fail_on_internal_call; + + $_[0]->throw_exception( "Can't call id() as a class method" ) + unless ref $_[0]; + + wantarray + ? $_[0]->_ident_values + : ($_[0]->_ident_values)[0] # FIXME - horrible horrible legacy crap + ; } sub _ident_values { diff --git a/lib/DBIx/Class/Schema/SanityChecker.pm b/lib/DBIx/Class/Schema/SanityChecker.pm index 4cc7958..ccfc0f3 100644 --- a/lib/DBIx/Class/Schema/SanityChecker.pm +++ b/lib/DBIx/Class/Schema/SanityChecker.pm @@ -360,7 +360,11 @@ sub check_no_indirect_method_overrides { for (@$method_stack) { push @$nonsugar_methods, $_ and next - unless $_->{attributes}{DBIC_method_is_indirect_sugar}; + unless( + $_->{attributes}{DBIC_method_is_indirect_sugar} + or + $_->{attributes}{DBIC_method_is_generated_from_resultsource_metadata} + ); push @err, { overridden => { diff --git a/lib/DBIx/Class/_Util.pm b/lib/DBIx/Class/_Util.pm index 73f41e9..2d2caaa 100644 --- a/lib/DBIx/Class/_Util.pm +++ b/lib/DBIx/Class/_Util.pm @@ -1130,6 +1130,10 @@ sub fail_on_internal_call { { package DB; $fr = [ CORE::caller(1) ]; + + # screwing with $DB::args is rather volatile - be extra careful + no warnings 'uninitialized'; + $argdesc = ( not defined $DB::args[0] ) ? 'UNAVAILABLE' : ( length ref $DB::args[0] ) ? DBIx::Class::_Util::refdesc($DB::args[0])