Maybe data_normalization using cees's multi-format parser + an overriden accessor (but unchanged mutator)
I guess that would probably work as well. I think if I were to take this approach, I would try to be consistent about the functionality change and override the accessor for every has_a relationship (ones that don't relate to another Class::DBI table object). The easiest place to do this is probably in the 'get' method. All accessors appearantly call 'get' to fetch the value (ie $self->date() gets turned into $self->get('date'); ). Also note that 'get' can accept multiple keys to fetch at once.
sub get {
my ($self, @keys) = @_;
my @values = $self->SUPER::get(@keys);
foreach (@values) {
# if $_ is an object,
# and it is not a Class::DBI object
# and it overloads ""
if (UNIVERSAL::isa($_, 'UNIVERSAL') &&
!UNIVERSAL::isa($_, 'Class::DBI') &&
overload::Method($_,'""')) {
$_ = "$_"; # stringify the object
}
}
return shift @values if @keys == 1;
return @values;
}
I did a quick test, and it seems to work. Effectively it will check to see if the value is an object, and stringify it if "" has been overloaded in the object. So it shouldn't care what object you use in a has_a reloationship. As long as it overrides "" it will get stringified before it gets returned.
Personally I am happy with the way has_a lets you work with objects instead of just plain strings, so I wouldn't go this route myself. But everyone has their own style...
Cheers,
Cees
|