Shawn H Corey wrote:
On Thu, 3 Aug 2017 20:44:45 +0200
hw <h...@gc-24.de> wrote:


Hi,

suppose I have a class FOO and a class BAR.  The parent of BAR is FOO.

I would like FOO to /use/ BAR because BAR has some methods needed by
FOO. BAR is /decended/ from FOO because FOO has many methods needed
by BAR.

Is this possible, or does it lead to some endless recursion when
compiling?


Files and packages are two different things in Perl. `use Foo;` mean
load the module from the file Foo.pm and execute it. Perl keeps a list
of all the modules (files) it loads so that no it never loads a module
twice.

`package Foo;` means what follows is in the name-space Foo. Their
fully-qualified names would start with `Foo::`

The convention is that there should be only one package per
module-file. But Perl doesn't care. You can mixed packages and modules
any which way you can imagine. You can have a package spread out in
several modules and you can have a module contains many packages, or
any combination of the two. But to keep you code understandable, please
keep to one and only one package per module.

Now I´m confused as to what is a module and a package.  Both are files.

In any case, it is my intention to keep everything that one class requires
within one file which starts with 'package FOO'.  Due to increasing
complexity, I´m using POD sections or I wouldn´t know anymore what I´m
doing ...

The way I would do it would be to separate out what is common in both
Foo and Bar and put them in a separate module. Then Foo and Bar can
`use` it as their parent.

I think that might be the best solution.  I could make a metaclass that
contains the methods common to both FOO and BAR and have both of them
descend from it.

However, that feels like using inheritance in an upside down manner.  But
perhaps it´s supposed to be used like that?

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to