in reply to Class::Interface -- isa() Considered Harmful

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

Replies are listed 'Best First'.
Re^2: Class::Interface -- isa() Considered Harmful
by Aristotle (Chancellor) on Jan 18, 2003 at 12:39 UTC

    You can write INIT { } as sub INIT { } - that would be the easiest fix. Such INIT blocks will then work as INIT blocks in newer Perls and fulfill the syntax constraints of earlier ones. Alternatively, if you have several INIT blocks, you could define a sub INIT (&) { ... } or similar - however, that should be done depending on version since it will change the semantics of INIT { } for newer Perls as well.

    The question is inhowfar these can be considered to compile "as expected", since the compilation stage specific behaviour is lost. It's in the nature of modules such as this one to require finer control of execution time than what the "blunt" BEGIN block offers, and in that case you're out of luck since old Perls just don't offer that no matter what.

    Makeshifts last the longest.