-
Notifications
You must be signed in to change notification settings - Fork 601
Description
Although perl conventionally has relied on naming for its privacy protections rather than having them enforced, many people still desire fully private methods. Perl can provide private subs, but the syntax for using them as methods is not very nice:
my $coderef = sub {
my $self = shift;
...
};
$object->$coderef;
my sub lexmethod {
my $self = shift;
}
$object->${\\&lexmethod};
# a private method is really no different from a direct sub call
lexmethod($object);
Perl could support the syntax $object->&method(...) as an equivalent to &method($object, ...). This would provide a better syntax to indicate the intent of something as method, but not following traditional method lookup. It would work the same as a normal sub call, using either a sub in the current package, or a lexical sub. Keeping this at the call site means any future potential object system wouldn't need to implement complicated visibility rules in its method dispatch.
Currently, $object->&method is invalid syntax, so it shouldn't present backwards compatibility issues.