Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Multiple inheritance with multiple contructors?

by Anonymous Monk
on Mar 16, 2012 at 18:23 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://960036]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-19 06:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found