Pre-release of pragmatic module base::hasa

A

Anno Siegel

I am preparing a pragmatic module "base::hasa" for release on CPAN. As
usual at this stage, there is an urge to get some feedback before casting
things in stone. ("Cast in stone"? Hmmm.) So I have put up a pre-release
under

http://www.tu-berlin.de/~siegel/clpm/base-hasa/

From the doc:

NAME
base::hasa - 'Turn has-a relation into is-a (experimental)'

SYNOPSIS
package My::Class;

# My::Class wants to inherit from Base::Class.
# There is a has-a relation to Base::Class in the sense that
# there is a method "hasa_method" in My::Class that returns
# a Base::Class object.
# To establish inheritance:

use base::hasa ( 'Base::Class' => 'hasa_method');

DESCRIPTION
"base::hasa" establishes an "is-a" relationship with the base class
"Base::Class". In addition, inherited methods are channeled through
the "has_a" method.

Thus, if "foo" is a method of "Base::Class", it is now immediately
applicable to an object $mine in your inheriting class "My::Class":

$mine->foo( ...);

is equivalent to

$mine->hasa_method->foo( ...);

[...]

Note that with has-a inheritance, knowledge about the base class is
entirely encapsulated in the has-a relationship. This is no matter of
course in Perl OO.

[see full text at the URL above]

I'd be thankful if anyone could find the time and interest to take a look.

The module is functional, but it is barely debugged and I would not be
surprised if it broke easily. Bug reports will be gratefully accepted,
but that is not my main reason for posting. I'll be writing tests for the
next few days anyway...

I have the feeling that base::hasa proves something about Perl OO that
might have been doubted, but I can't quite put my finger on it. "You
never could inherit with knowing less about your base class" is a
short way of putting it. I call this, somewhat clumsily, "has-a
inheritance". The (preliminary) section COGITATIONS in
the doc contains more on this. I'd be particularly grateful for
thoughts about what role "has-a inheritance" plays in the greater scheme
of things OO.

Oh, something else... I wrongly thought that Time::piece was a standard
module, and the documentation and examples (in examples/ex_*) freely use
it. You may want to get it from CPAN if you want to play with base::hasa.
Sorry about that.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top