develooper Front page | perl.perl6.language | Postings from June 2005

Re: OO magic (at least for me)

Thread Previous | Thread Next
June 26, 2005 10:45
Re: OO magic (at least for me)
Message ID:
BÁRTHÁZI András skribis 2005-06-26 19:35 (+0200):
>     method fun1() { fun2(); }
>     method fun2() { say "fun2!"; }
> *** No compatible subroutine found: "&fun2"

fun2 is a method, not a sub. You need method syntax to call it:


> class MyMethod { method fun1() { fun2(); } sub fun2() { say "fun2!"; }
> } class Child is MyMethod { }
> Child.fun1();
> Sounds good. It seems to me, that I can call fun2() from inside 
> MyMethod, from everywhere. OK, Child is MyMethod, so can I do it there 
> too? No. :(

IIRC, that's what submethods are for. Submethods aren't inherited. It is
unclear to me whether subs are.

Two requests:

1. Please indent code and don't use cutting lines.

2. Please use visually more different names, fun1 and fun2 look a lot
alike. Consider foo and bar.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About