There's more than one way to do things | |
PerlMonks |
Re: Daft text adventure projectby bikeNomad (Priest) |
on May 30, 2001 at 00:05 UTC ( [id://84061]=note: print w/replies, xml ) | Need Help?? |
Sounds like a fun (and educational) project. A couple of things you may want to look further into:<bl>
Perl will first look in the Sword package for a subroutine called "damage". Failing this, it will search each of the packages named in the @Sword::ISA list for a subroutine called "damage". If it still doesn't find damage(), then it will call AUTOLOAD with the name of the missing method ("damage") as well as the arguments to that method. How can you do prototype based programming with this? Simple: by exclusively using AUTOLOAD to call whatever functions need to be overridden on a fine-grained basis (that is, anything you didn't define in the package of the object itself or one of the packages named in its class's @ISA array). You can do this by maintaining named slots for overridable methods, putting subroutine references into these slots, and then calling them from your AUTOLOAD method. Where the "prototype" comes in is that an object could refer to another object whose behavior it can share. Of course, being lazy, one could look at CPAN and find the modules Class::SelfMethods or Class::Classless, which provide for a couple of different kinds of prototype-based programming support. Best of luck with this project! updated: clarified use of prototype
In Section
Seekers of Perl Wisdom
|
|