in reply to Re^3: Inheritance without defining the object on inherited module
in thread Inheritance without defining the object on inherited module

Hello again Corion,

That is true the sample code that I have provided it does not explain exactly so I will try to explain in English.

I want to use a subroutine from Person to Employees. More precisely I want to invoke a subroutine input main.pl</p> that calls a method from <code>Person and replies back with a hash. I want to invoke the same subroutine from Employees without the need to use the object.

My goal the whole time was to get a hash with the directories where all my %WARNS will be stored in different folders in case of an error.

I hope now that I explained everything in English that it makes a bit more sense why I wanted to use both Perl Modules.

Again thank you for your time and effort.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^5: Inheritance without defining the object on inherited module
by Corion (Patriarch) on May 19, 2015 at 06:54 UTC

    You cannot (or rather, should not) use code as both, a function and a method. Using inheritance is the bad approach in any way.

    If you want to call the subroutine in Person from Employee, just call it directly:

    package Person; my %WARN; sub get_warnings { return \%WARN; };
    package Employee; use Data::Dumper; sub frobnicate { my $warnings_by_person = Person::get_warnings; warn Dumper $warnings_by_person; };