Heritable::Types

Heritable::Types is a Perl module to make object dispatch look at an object's type.
Download

Heritable::Types Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Piers Cawley
  • Publisher web site:
  • http://search.cpan.org/~pdcawley/

Heritable::Types Tags


Heritable::Types Description

Heritable::Types is a Perl module to make object dispatch look at an object's type. Heritable::Types is a Perl module to 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 '' }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 to UNIVERSAL::isa, that object is a HASH. But if you implement, say HASH::foo, a method that only exists in the HASH namespace, then UNIVERSAL: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.USAGEThere'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. Requirements: · Perl


Heritable::Types Related Software