Hi!
I'm trying to answering my questions. Still interested in some official
answer. :)
--- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< ---
class MyMethod {
method fun1() {
fun2();
}
method fun2() {
say "fun2!";
}
}
class Child is MyMethod {
}
Child.fun1();
--- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< ---
*** No compatible subroutine found: "&fun2"
I'm wondering why, but maybe, it's OK.
--- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< ---
class MyMethod {
method fun1() {
fun2();
}
sub fun2() {
say "fun2!";
}
}
class Child is MyMethod {
}
Child.fun1();
--- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< ---
fun2!
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. :(
--- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< ---
class MyMethod {
method fun1() {
fun2();
}
sub fun2() {
say "fun2!";
}
}
class Child is MyMethod {
fun2();
}
Child.fun1();
--- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< ---
*** No compatible subroutine found: "&fun2"
The problem is calling fun2() from Child's declaration. As I think, the
calling just happens at when interpreting the declaration of Child, but
the scope is not Child's scope. Why?
Let's try Child.fun2()!
--- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< ---
class MyMethod {
method fun1() {
fun2();
}
sub fun2() {
say "fun2!";
}
}
class Child is MyMethod {
Child.fun2();
}
Child.fun1();
--- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< ---
fun2!
Works well. Is it a not yet implemented feature in Pugs, or is by design?
Still don't know, how can a method/sub automagically called, when I
inherite a class.
I would like to use the syntax you can see in my example #1, but the
syntax of example #2 is still OK. I would like to use calling the
classes own methods/subs when declaring a child, and calling a
method/sub automatically, when I'm declaring a child.
Bye,
Andras