-
-
31 Aug 2003 11:06:08 UTC
- Distribution: Heritable-Types
- Module version: 1.00
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues
- Testers (420 / 7 / 0)
- Kwalitee
Bus factor: 0- 91.84% Coverage
- License: unknown
- Activity
24 month- Tools
- Download (10.16KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
- Dependencies
- unknown
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Heritable::Types - Make object dispatch look at an object's type
SYNOPSIS
use Heritable::Types sub Object::as_string { my($self) = @_; join " ", 'a', ref($self), $self->content_string; } sub HASH::content_string { my($self) = @_; my $str = join ', ', map {"$_ => $self->{$_}", keys %$self; return "{ $str }" } sub ARRAY::content_string { my($self) = @_; return '[ ', join(', ', @$self), ' ]' }
DESCRIPTION
Heritable::Types sets about making Perl's method dispatch system consistent with the way
isa
works. Right now, if you have an object which you represent as, say, a blessed Hash, then, according toUNIVERSAL::isa
, that object is a HASH. But if you implement, sayHASH::foo
, a method that only exists in the HASH namespace, thenUNIVERSAL:can
will not see it, nor will it get called if you do$obj->foo
. This strikes me as an unsatisfactory state of affairs, hence Heritable::Types.USAGE
There's nothing to it, see the synopsis for how it works. Note that, if once one module uses Heritable::Types then *all* objects will do method lookup via their types.
If you want to have a method which all types can inherit from, but which will ensure that individual types can override that method, then you should implement it in the Object class, rather than in UNIVERSAL (if you implement a method in UNIVERSAL there's a good chance that the specific type's methods will never get called, which isn't what anyone wants.
BUGS
None sighted so far. There are bound to be some though.
SUPPORT
What support there is for this module is provided on a "When the author has time" basis. If you do have problems with it, please, drop me a line. Support requests that come with a failing test are greatly appreciated. Bug reports that come with a new test and a patch to fix it will earn my undying gratitude.
AUTHOR
Piers Cawley CPAN ID: PDCAWLEY pdcawley@bofh.org.uk http://pc1.bofhadsl.ftech.co.uk:8080/
COPYRIGHT
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
SEE ALSO
perl(1).
Module Install Instructions
To install Heritable::Types, copy and paste the appropriate command in to your terminal.
cpanm Heritable::Types
perl -MCPAN -e shell install Heritable::Types
For more information on module installation, please visit the detailed CPAN module installation guide.