"David Whipp" <[EMAIL PROTECTED]> writes: > Piers Cawley >> > This may be a case of keep up at the back, but if that is a >> method call, >> > how do I call a subroutine from within a method ? >> >> [...] >> >> Yes, I know there's several different ways I could do it, but this >> approach feels right. > > I think this comes does to huffmann encoding: which things are > common, and which are less common. This probably depends on > what you are doing (what paradigm you are following), so its > really a question about the nature of perl. > > The things I've heard people wanting to do are: > > call method on current topic > call method on current invocant > call class method on invocant's class > call private subroutine defined in current class > call global subroutine > > The following syntaxes have been seen: > > foo() > .foo() > ..foo() ## rejected because ".." is different binary op > class.foo() > FooClass.foo() > ::foo() > Package::foo() > $foo() > $_.foo() > > I see 2 partionings: > > * by scope: topic, self, named package, global > * by invocant: instance, class, none > > My suggested resolutions: > > By Scope: global/ named package use the existing > Foo::bar syntax; Topic uses unary . syntax; self > uses nothing > > By invocant: infer from current invocant/topic; use > &foo() for no invocant > > Thus, the perl5 transalations would be: > > foo() => $self->foo() > .foo() => $_->foo() > &foo() => foo() > ::foo() => ::foo() > Bar::bar() => Bar::bar() > > class.foo() => ref($self)->foo() > .class.foo() => ref($_)->foo() > > &foo(self) => foo($self->self) > => $self->self->foo() > > This assumes that C<class> and C<self> are defined in > UNIVERSAL
For reasons that I can't quite put my finger on at the moment, I really, really don't like that approach. One of the really nice things about perl 4 was that we didn't have to use & any more. Making it essential seems like a horribly retrograde step. I suppose you could require the & only when calling subroutines from within a method/class definitions, but I still don't like it. -- Piers "It is a truth universally acknowledged that a language in possession of a rich syntax must be in need of a rewrite." -- Jane Austen?