in reply to Re: One line accessor method style.
in thread One line accessor method style.

Thanks.

What I was really more curious about is how idiomatic the construct is. I think it's perfect for simple delegation, like this:

sub find_text { return shift->text_control->search_for(@_) }

where you have one object containing another and you wish to delegate certain responsibilities to the contained object.

Replies are listed 'Best First'.
Re^3: One line accessor method style.
by Tanktalus (Canon) on Feb 23, 2005 at 23:01 UTC

    Idiomatic? I think pretty much all of the above are idiomatic to some degree. However, the simple case in the OP is idiomatic to any API, whether Perl, C, Java, or other. The concept is simple: we're renaming a function, but we don't want to break old code, so we'll provide a forwarding function which will call the new function automatically. In Java, this is often combined with some Javadoc that says it's @deprecated - code that is already compiled against the deprecated function will continue to work, new code trying to be compiled against it will get a warning during compilation.

    The exact syntax to get this behaviour is quite idiomatic to Perl, but what it's trying to do is common across many languages.

    As to your new example, that, too, is idiomatic to OO languages. The precise syntax, of course, is again Perlish. But the concept (the idiom) is common to OO languages everywhere - one object "HASA" second object. When I myfoot->press( mycar->get_accelerator() ) ... then a series of actions happen:

    sub Foot::press { shift; shift->press(@_); } sub Accelerator::press { my $self = shift; my $fuel_amount = $self->convert_pressure_to_liters(@_); $self->get_car()->get_engineblock()->burn_more_fuel($fuel_amount); }
    This may be written in perlish pseudo-code, but it applies the same to any other language.