Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: object oriented Perl advice / constructor creation in child class

by smarthacker67 (Beadle)
on Jul 11, 2018 at 06:45 UTC ( [id://1218280] : note . print w/replies, xml ) Need Help??


in reply to Re: object oriented Perl advice / constructor creation in child class
in thread object oriented Perl advice / constructor creation in child class

Hi Sir,

Thanks for this brief explanation I would definitely give a try.

dir structure looks like
lib/A.pm lib/B.pm lib/C.pm lib/C/C1.pm lib/D.pm
Wanted to achieve deep inheritance where object of C1 should inherit methods of A,B,C, & D
  • Comment on Re^2: object oriented Perl advice / constructor creation in child class
  • Download Code

Replies are listed 'Best First'.
Re^3: object oriented Perl advice / constructor creation in child class
by kcott (Archbishop) on Jul 11, 2018 at 07:15 UTC

    dir structure looks like

    ... lib/B.pm ... lib/C/C1.pm ...
    lib/B.pm

    As previously stated, B.pm will already exist on your system. Attempting to write new code with "package B;" will cause you all sorts of problems. You should avoid this name.

    lib/C/C1.pm

    That's fine. The class name will become "C::C1". My previously posted "lib/C1.pm" should be moved to "lib/C/C1.pm", and the first line should be changed to:

    package C::C1;

    In my "./acd.pl", you should change

    use C1; my $c1 = C1::->new();

    to

    use C::C1; my $c1 = C::C1::->new();

    After making those changes, note the difference in the last line:

    $ ./acd.pl A=HASH(0x9897d0) A-bar D=HASH(0x989890) D-bar whos_who() is in package: C $self is in package: C::C1

    The hexadecimal values in "X=HASH(0xhhhhhh)" will likely be different: that's not significant; you could get different values on separate runs using the same code.

    — Ken