Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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.


Comment on Re: Can't locate object method- Issue
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?
      Importing (require) does not establish inheritance.
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      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?

      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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1047558]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-12-21 19:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (107 votes), past polls