my $error = 3.1415927->minus( 22->divide( 7 ) )->abs();
But rather, if I write a function that deals with $href entirely though method calls rather than the built-in keywords, and document that I have done so, then somebody calling that function is now able to pass it, instead of a hashref, a blessed object providing the same interface; i.e. polymorphism.
This can be achieved somewhat using tied variables, but the interface is very low-level - it's not easy to, say, quickly override the order a foreach loop will traverse an array.
Besides which, in the former example you are hideously breaking encapsulation by using the assignment operator! ;-)
(my $error)->set_value( 3.1415927->minus( 22->divide( 7 ) )->abs() );
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
|