[Dbix-class] method as accessor?

Jess Robinson castaway at desert-island.me.uk
Wed Jul 4 13:07:41 GMT 2007


On Tue, 3 Jul 2007, Steve Francia wrote:

> I am trying to write a function for a result set that will be available
> like an accessor...
>
> Here is the scenario and goal:
> I have a object of which there are two columns in the table, full_name
> and alias.
> I want to use $obj->name to access the name for which there would be
> logic saying return full_name unless alias has a value, then return alias.
>
> What is the best way to go about doing this? Am I on the right track?
>


Your class is just a perl class, nothing fancy. So just create:
sub name
{
  my ($self) = @_;

   .. check $self->full_name || $self->alias as appropriate, and return ..
}



More information about the Dbix-class mailing list