[Dbix-class] Deprecating a relationship

Peter Rabbitson rabbit+dbic at rabbit.us
Tue Jan 5 11:32:17 GMT 2010


Jose Luis Martinez wrote:
> Hi,
> 
>     Is there any way to mark a relationship as "deprecated"?
> 
>     I have some code with relationships that are not named to well, and
> want to gradually rename them (while writing new code with the new
> relations). Search and replace is not an acceptable strategy, as there
> are lots of strings in the code with the same name that sould not be
> replaced.
> 
>     The goal is to mark relationships as "deprecated" (output something
> via STDERR so I can notice that they are being called while testing, for
> example), but I want them to keep on working as usually.
> 
>     Do the DBIx::Class-masters have any suggestions for doing this cleanly?
> 

All you need to do is override related_resultset() in a base/component class
like so:

use Carp::Clan qw/^DBIx::Class/;
sub related_resultset {
  my $self = shift;
  if ($_[0] eq 'misnamed relname') {
    carp 'you are using such and such - rename';
  }
  $self->next::method (@_);
}



More information about the DBIx-Class mailing list