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.

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.


-- 
Don't stop where the ink does.

        Shawn H Corey

-- 
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