in reply to Re^2: One line accessor method style.
in thread One line accessor method style.
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:
This may be written in perlish pseudo-code, but it applies the same to any other language.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); }
|
|---|