in reply to Re: Overloading operators: -> to .
in thread Overloading operators: -> to .
You may not be able to pass arguments to your methods, since '.' only takes two arguments.
Oh, sure you can. You just have to use a trick:
#!/usr/bin/perl use strict; no warnings; package UNIVERSAL; sub AUTOLOAD { my $method = $UNIVERSAL::AUTOLOAD; $method =~ s/.*:://; return if $method eq "DESTROY"; [$method => @_]; } package DotDotDot; use overload "." => \˙ sub new { bless [] => shift; } sub method { my $self = shift; print "method: @_\n"; } sub dot { my $self = shift; my ($method, @args) = @{+shift}; $self -> $method (@args); } package main; my $obj = DotDotDot -> new; $obj . method (1, 2, 3); __END__ method: 1 2 3
You may have to fiddle a bit to get inheritance working properly though.
Abigail
|
|---|