Skip Menu |

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

Report information
The Basics
Id: 25504
Status: resolved
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: mschwern [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: [PATCH] CDBICompat, changing just the accessor name should also change the mutator
In CDBI if you change the accessor name with an accessor_name_for() method but not the mutator name the mutator should get the accessor's new name. In effect, they remain one method. The attached patch fixes the CDBICompat layer to honor this.
Subject: accessor_name_only.patch
---------------------------------------------------------------------- r27709: schwern | 2007-03-16 19:57:11 -0700 In CDBI if you change the accessor name but not the mutator name the mutator gets the accessor's name. ---------------------------------------------------------------------- === local/DBIx-Class/t/cdbi-t/15-accessor.t ================================================================== --- local/DBIx-Class/t/cdbi-t/15-accessor.t (revision 27708) +++ local/DBIx-Class/t/cdbi-t/15-accessor.t (revision 27709) @@ -9,7 +9,7 @@ next; } eval "use DBD::SQLite"; - plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 53); + plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 54); } INIT { @@ -18,7 +18,9 @@ use lib 't/testlib'; require Film; require Actor; + require Director; Actor->has_a(film => 'Film'); + Film->has_a(director => 'Director'); sub Class::DBI::sheep { ok 0; } } @@ -40,6 +42,13 @@ return $col; } +# This is a class with accessor_name_for() but no corresponding mutatori_name_for() +sub Director::accessor_name_for { + my($class, $col) = @_; + return "nutty_as_a_fruitcake" if lc $col eq "isinsane"; + return $col; +} + my $data = { Title => 'Bad Taste', Director => 'Peter Jackson', @@ -132,6 +141,20 @@ } + +# Make sure a class with an accessor_name() method has a similar mutator. +{ + my $aki = Director->create({ + name => "Aki Kaurismaki", + }); + + $aki->nutty_as_a_fruitcake(1); + is $aki->nutty_as_a_fruitcake, 1, + "a custom accessor without a custom mutator is setable"; + $aki->update; +} + + SKIP: { # have non persistent accessor? #skip "Compat layer doesn't handle TEMP columns yet", 11; Film->columns(TEMP => qw/nonpersistent/); === local/DBIx-Class/lib/DBIx/Class/CDBICompat/AccessorMapping.pm ================================================================== --- local/DBIx-Class/lib/DBIx/Class/CDBICompat/AccessorMapping.pm (revision 27708) +++ local/DBIx-Class/lib/DBIx/Class/CDBICompat/AccessorMapping.pm (revision 27709) @@ -13,8 +13,10 @@ my $ro_meth = $class->_try_accessor_name_for($col); my $wo_meth = $class->_try_mutator_name_for($col); - #warn "$col $ro_meth $wo_meth"; - if ($ro_meth eq $wo_meth) { + # warn "class: $class / col: $col / ro: $ro_meth / wo: $wo_meth\n"; + if ($ro_meth eq $wo_meth or # they're the same + $wo_meth eq $col) # or only the accessor is custom + { $class->next::method($group => [ $ro_meth => $col ]); } else { $class->mk_group_ro_accessors($group => [ $ro_meth => $col ]);
"resolved", at least once your patch set hits