This queue is for tickets about the Class-DBI CPAN distribution.

Report information
The Basics
Id:
17453
Status:
resolved
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
ask [...] develooper.com
Cc:
AdminCc:

BugTracker
Severity:
Important
Broken in:
  • v3.0.7
  • v3.0.8
  • v3.0.9
Fixed in:
(no value)

Attachments
Class-DBI-v3.0.14-accessor_name.patch



Subject: old accessor_name/mutator_name methods not working (rather than just being deprecated as announced)
Since 3.0.7 (I think) accessor_name and mutator_name has simple been ignored. This patch fixes it. I left the deprecation warnings commented out for now. diff -rbupN Class-DBI-v3.0.14/lib/Class/DBI.pm Class-DBI-v3.0.14-ask/lib/Class/DBI.pm --- Class-DBI-v3.0.14/lib/Class/DBI.pm 2006-01-16 02:25:27.000000000 -0800 +++ Class-DBI-v3.0.14-ask/lib/Class/DBI.pm 2006-02-02 23:07:37.000000000 -0800 @@ -59,10 +59,7 @@ sub _undefined_primary { __PACKAGE__->mk_classdata('__hasa_rels' => {}); { - my %deprecated = ( - accessor_name => 'accessor_name_for', # 3.0.7 - mutator_name => 'mutator_name_for', # 3.0.7 - ); + my %deprecated = (); no strict 'refs'; while (my ($old, $new) = each %deprecated) { @@ -375,11 +372,17 @@ sub _make_method { sub accessor_name_for { my ($class, $column) = @_; + if ($class->can('accessor_name')) { + return $class->accessor_name($column); + } return $column->accessor; } sub mutator_name_for { my ($class, $column) = @_; + if ($class->can('mutator_name')) { + return $class->mutator_name($column); + } return $column->mutator; } diff -rbupN Class-DBI-v3.0.14/t/27-mutator-old.t Class-DBI-v3.0.14-ask/t/27-mutator- old.t --- Class-DBI-v3.0.14/t/27-mutator-old.t 1969-12-31 16:00:00.000000000 -0800 +++ Class-DBI-v3.0.14-ask/t/27-mutator-old.t 2006-02-02 23:01:15.000000000 -0800 @@ -0,0 +1,45 @@ +use strict; +use Test::More; + +BEGIN { + eval "use DBD::SQLite"; + plan $@ + ? (skip_all => 'needs DBD::SQLite for testing') + : (tests => 6); +} + +INIT { + local $SIG{__WARN__} = sub { + like $_[0], qr/clashes with built-in method/, $_[0]; + }; + use lib 't/testlib'; + require Film; +} + +sub Film::accessor_name { + my ($class, $col) = @_; + return "sheep" if lc $col eq "numexplodingsheep"; + return $col; +} + +my $data = { + Title => 'Bad Taste', + Director => 'Peter Jackson', + Rating => 'R', +}; + +my $bt; +eval { + my $data = $data; + $data->{sheep} = 1; + ok $bt = Film->insert($data), "Modified accessor - with +accessor"; + isa_ok $bt, "Film"; +}; +is $@, '', "No errors"; + +eval { + ok $bt->sheep(2), 'Modified accessor, set'; + ok $bt->update, 'Update'; +}; +is $@, '', "No errors";
Here's the patch attached (a bit more likely to apply that way :-) ) I noticed that I left the warnings out entirely; doh. I meant to leave them in, but commented out. (Something like if ($class->can(...)) { # my @caller = caller; # warn ".... deprecated blah blah blah\n"; $class->accessor_name($column) }
diff -rbupN Class-DBI-v3.0.14/lib/Class/DBI.pm Class-DBI-v3.0.14-ask/lib/Class/DBI.pm --- Class-DBI-v3.0.14/lib/Class/DBI.pm 2006-01-16 02:25:27.000000000 -0800 +++ Class-DBI-v3.0.14-ask/lib/Class/DBI.pm 2006-02-02 23:07:37.000000000 -0800 @@ -59,10 +59,7 @@ sub _undefined_primary { __PACKAGE__->mk_classdata('__hasa_rels' => {}); { - my %deprecated = ( - accessor_name => 'accessor_name_for', # 3.0.7 - mutator_name => 'mutator_name_for', # 3.0.7 - ); + my %deprecated = (); no strict 'refs'; while (my ($old, $new) = each %deprecated) { @@ -375,11 +372,17 @@ sub _make_method { sub accessor_name_for { my ($class, $column) = @_; + if ($class->can('accessor_name')) { + return $class->accessor_name($column); + } return $column->accessor; } sub mutator_name_for { my ($class, $column) = @_; + if ($class->can('mutator_name')) { + return $class->mutator_name($column); + } return $column->mutator; } diff -rbupN Class-DBI-v3.0.14/t/27-mutator-old.t Class-DBI-v3.0.14-ask/t/27-mutator-old.t --- Class-DBI-v3.0.14/t/27-mutator-old.t 1969-12-31 16:00:00.000000000 -0800 +++ Class-DBI-v3.0.14-ask/t/27-mutator-old.t 2006-02-02 23:01:15.000000000 -0800 @@ -0,0 +1,45 @@ +use strict; +use Test::More; + +BEGIN { + eval "use DBD::SQLite"; + plan $@ + ? (skip_all => 'needs DBD::SQLite for testing') + : (tests => 6); +} + +INIT { + local $SIG{__WARN__} = sub { + like $_[0], qr/clashes with built-in method/, $_[0]; + }; + use lib 't/testlib'; + require Film; +} + +sub Film::accessor_name { + my ($class, $col) = @_; + return "sheep" if lc $col eq "numexplodingsheep"; + return $col; +} + +my $data = { + Title => 'Bad Taste', + Director => 'Peter Jackson', + Rating => 'R', +}; + +my $bt; +eval { + my $data = $data; + $data->{sheep} = 1; + ok $bt = Film->insert($data), "Modified accessor - with +accessor"; + isa_ok $bt, "Film"; +}; +is $@, '', "No errors"; + +eval { + ok $bt->sheep(2), 'Modified accessor, set'; + ok $bt->update, 'Update'; +}; +is $@, '', "No errors";
From: ask@develooper.com
Any reason this wasn't applied?
Subject: Re: [rt.cpan.org #17453] old accessor_name/mutator_name methods not working (rather than just being deprecated as announced)
Date: Thu, 6 Jul 2006 13:27:02 +0100
To: Guest via RT <bug-Class-DBI@rt.cpan.org>
From: Tony Bowden <tony@kasei.com>
On Thu, Jul 06, 2006 at 07:52:32AM -0400, Guest via RT wrote:
Show quoted text
> Any reason this wasn't applied?
I thought it had been. Now I need to find out if there's a version lying around somewhere that I thought I had released but for some reason hadn't ... Tony
On Thu Jul 06 08:27:41 2006, tony@kasei.com wrote:
Show quoted text
> On Thu, Jul 06, 2006 at 07:52:32AM -0400, Guest via RT wrote:
> > Any reason this wasn't applied?
> I thought it had been. Now I need to find out if there's a version lying > around somewhere that I thought I had released but for some reason > hadn't ...
Looks like I was confusing it with your previous patch that went into 3.0.14. I'm happy enough with this, but I'm not sure why you've undeprecated the methods. I'd prefer to keep the deprecation warnings. I've changed your SIG{WARN} test to fail $_[0] unless $_[0] =~ /deprecated/; I'll hold off on releasing this for a day or two in case you need to persuade me this is a bad idea! Thanks, Tony
Subject: Re: [rt.cpan.org #17453] old accessor_name/mutator_name methods not working (rather than just being deprecated as announced)
Date: Sun, 20 Aug 2006 00:45:07 +0200
To: bug-Class-DBI@rt.cpan.org
From: Ask Bjørn Hansen <ask@develooper.com>
On Aug 19, 2006, at 23:55, via RT wrote:
Show quoted text
> I'll hold off on releasing this for a day or two in case you need to > persuade me this is a bad idea!
No, that sounds good! :)


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.