Front page | perl.perl6.language |
Postings from June 2005
proposal: 404 method
Thread Next
From:
=?ISO-8859-2?Q?B=C1RTH=C1ZI_Andr=E1s?=
Date:
June 20, 2005 08:20
Subject:
proposal: 404 method
Message ID:
42B6DE49.8060008@barthazi.hu
Hi,
Is there a way, to catch, if I call a method, that doesn't exists, to
run a default one? I'm thinking about an "error handler" method. If not,
I would like to propose this:
class MyClass {
method example ($self: $var) {
say "HELLO";
}
method default ($self: $method_name, %parameters)
is method_not_found {
say "$method_name called";
}
}
$mc = new MyClass;
$mc.example("var")
$mc.helloworld("var", "var");
----------------------
and it outputs:
HELLO
helloworld called
The above is maybe not the best (and not the most valid) syntax for my
proposal, but I think you can get the idea. It would be very useful the
hide parameters into the method name, like this:
save_the_world();
save_the_captain();
And the default method will match the method name with
/^save_the_(.*)$/, and saves $1.
I hope, you will like it. As I know, it's not possible currently.
Bye,
Andras
Thread Next
-
proposal: 404 method
by =?ISO-8859-2?Q?B=C1RTH=C1ZI_Andr=E1s?=