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

Anonymous classes

Thread Next
Simon Cozens
May 29, 2005 02:02
Anonymous classes
Message ID:

    I'm having a seriously good time porting Maypole to Perl 6. If you
still have reservations about how Perl 6 is going to be to program in,
I urge you to try programming in it.
    Now, commercial over, I have some questions.

    What's the syntax for declaring inherited anonymous classes, and
then adding methods to them? 
    I've realised that anonymous classes are an excellent solution to
subclassing *related* classes - for instance, you have a Foo class which
creates Foo::Request and Foo::Response objects, and when you subclass
Foo, you may want to specialise things in Foo::Request and Foo::Response
as well. So instead you go:

    class Foo {
      has Class $.request_class is rw; 
      method BUILD { 
         $.request_class = class is Foo::Request; # Or whatever

And then you have a request class that is a singleton class to each
Foo instantiation, which can be specialized however your particular
Foo subclass needs.

>Almost any animal is capable learning a stimulus/response association,
>given enough repetition.
Experimental observation suggests that this isn't true if double-clicking
is involved. - Lionel, Malcolm Ray, asr.

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