Re: AsForm and accessor names
[prev]
[thread]
[next]
[Date index for 2004/12/30]
--- Dave Howorth <dhoworth@xxxxxxx.xxx.xx.xx> wrote:
> Class::DBI::AsForm assumes that every column has an accessor with the
> same name. This is not true if accessors have been renamed using
> Class::DBI's accessor_name method. The result is an ugly death in the
> _to_*** functions when they invoke $self->$col.
>
> To fix this, I believe code is needed in to_field along these lines:
>
> my $accessor = $class->can('accessor_name')
> ? $class->accessor_name($field)
> : $field;
>
> $accessor then needs to be passed to each _to_*** function and
> $self->$col needs changing to $self->$accessor everywhere.
>
Hi, Dave. This is interesting. Thanks.
> This breaks backward compatibility in the _to_*** call interfaces (why
> are they exported into my namespace anyway?) so I imagine there might be
> other opinions.
>
The _to_*** methods are exported because they are called by your class within
AsForm . This is so current values for fields can be retrieved. So if they
aren't exported AsForm won't work.
When you say it breaks backward compat.. are you talking about breaking things
like "$customer->_to_select('address')? I've been wondering about the privacy
of the _to**. I treat them as private to AsForm even though they are exported.
However, I like the idea of some of them being not private to classes that
inherit them. Some code could be reworked and you could use them more
generally. For example, say I just want a select box of customers for a form
completely unrelated to a customer as far as CDBI is concerned. I could just
say Customer::_to_select();
> Cheers, Dave
>
>
=====
pjs
__________________________________
Do you Yahoo!?
Meet the all-new My Yahoo! - Try it today!
http://my.yahoo.com
|
|
Re: AsForm and accessor names
Peter Speltz 21:17 on 30 Dec 2004
|