Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Multiple inheritance with multiple contructors?

by Anonymous Monk
on Mar 16, 2012 at 18:23 UTC ( #960036=note: print w/replies, xml ) Need Help??


in reply to Multiple inheritance with multiple contructors?

Alternate solution for reference:
package PClass1; use strict; use Carp; sub new { my $proto = shift; my $class = ref($proto) || $proto; my (%args) = @_; my $this = { _fs => $args{fs} || croak("You must supply a filesystem"), }; bless $this, $class; return $this; } ... package PClass2; use strict; sub new { my $proto = shift; my $class = ref($proto) || $proto; my (%args) = @_; my $this = { _hosts => $args{hosts}, }; bless $this, $class; return $this; } ...... package Subclass; use strict; use PClass1; use PClass2; our @ISA=qw(PClass1 PClass2); sub new { my ($class, %args) = @_; #################### Start of changes #################### my $obj1 = $class->PClass1::new(%args); my $obj2 = $class->PClass2::new(%args); $this = $class->PClass1::new(%args); my $this = {( %{$obj1}, %{$obj2} )}; bless $this, $class; #################### End of changes #################### return $this; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2021-05-16 12:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (151 votes). Check out past polls.

    Notices?