Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Can't locate object method- Issue

by Loops (Curate)
on Aug 02, 2013 at 06:56 UTC ( #1047558=note: print w/replies, xml ) Need Help??

in reply to Can't locate object method- Issue

The Employee class is a subclass of Person which does not export a sayHi() method. If you make Employee a subclass of Person::Adult, the sayHi() method will be found. Alternatively you could just add a sayHi() method to Person.

Replies are listed 'Best First'.
Re^2: Can't locate object method- Issue
by perl_noobie (Initiate) on Aug 02, 2013 at 07:06 UTC
    Employee is already a subclass of Person (by virtue of use base ("Person") in Employee module), and the actual subclass of Person( Adult or Baby) is imported via dynamic check condition. Can you pls point out in the code what changes is to be made?

      You want to use

      use Exporter 'import';

      ... if you really want to export methods into other parts of base classes.

      Honestly, I do not think that mixing multiple inheritance, reblessing and exporting of subroutines in the way you are doing it will lead to a sane object/class structure. Maybe you can tell us more about the problem you are trying to solve with this conoction?

      Importing (require) does not establish inheritance.
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      On top of everything said by those more experienced monks above, you need to be careful when blessing an object that it actually matches one of your package names...
      bless($self, "Adult"); should be... bless($self, "Person::Adult");
      or even simple code that is not relying on your dynamic typing will fail:
      my $a = Person::Adult->new(NAME => 'the hard way'); $a->sayHi();

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1047558]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2018-06-20 23:54 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.