If one isn't too keen of inheritance and one is not afraid to add dependencies to ones script / module, there also is Class::Delegation, that faciliates containment relationshipts by autocreating the methods that your class delegates to one of its contained elements.
For a nice example, see CGI::Wiki, which delegates calls to the database backend via this module.
A reason not to use Class::Delegation is, that it does not work below Perl 5.005 - and my ISP has a borked Perl 5.4.3 (Solaris/gcc), which knows nothing of INIT blocks. If someone knows a nice and transparent way to work around the INIT {} block (or rather, how to have Perl 5.004 not throw a syntax error and to have the module still work / compile under Perl 5.4 and 5.5+ as expected), this would be nice :-) - I've thought about some version dependant eval()s, but haven't come to a conclusion.
Other than this one-paragraph nit, Class::Delegation helps you avoiding mechanical code that maps method names between your class and the contained object.
perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
In reply to Re: Class::Interface -- isa() Considered Harmful
by Corion
in thread Class::Interface -- isa() Considered Harmful
by chromatic
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |