ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl6-language
perl6-language
Re: proposal: 404 method
by Fagyal Csongor other posts by this author
Jun 20 2005 8:29AM messages near this date
proposal: 404 method | Re: proposal: 404 method
András,

I think you have just discovered AUTOLOAD :-)

OTOH I don't know how the AUTOLOAD mechanism will work in Perl6 compared 
to Perl5, or if it has been imlemented in Pugs (yet), but as far as I 
remember, in Apocalypse 12 somewhere it says it will work the same(?) as 
in Perl5, and what you have described works in Perl5 (if I understood 
you correctly, which might not be the case).

- Fagzal

>  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:
B?RTH?ZI Andr?s
Fagyal Csongor
Juerd
BÁRTHÁZI András
Abhijit Mahabal
Juerd

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved