I gave :PreInit a whirl and it's looking good, at least for my simple test case:
CPAN::Forum
Object-InsideOut - Re: passing arguments to super class initializer
| Posted on Wed Jun 28 23:48:09 2006 by mgoldshteyn in response to 2552 (See the whole thread of 9) |
| Re: passing arguments to super class initializer |
|
I gave :PreInit a whirl and it's looking good, at least for my simple test case:
use warnings;
use strict;
package Vehicle;
{
use Object::InsideOut;
my @environment :Field(Standard => 'environment');
my %init_args :InitArgs = (
environment => {
Field => \@environment,
Mandatory => 1,
},
);
}
package Car;
{
use Object::InsideOut qw(Vehicle);
my @color :Field(Standard => 'color');
my %init_args :InitArgs = (
color => {
Field => \@color,
Mandatory => 1,
},
);
sub pre_init :PreInit
{
my ($self, $args) = @_;
$$args{Vehicle}={environment => 'land'};
}
}
package Ship;
{
use Object::InsideOut qw(Vehicle);
my @size :Field(Standard => 'size');
my %init_args :InitArgs = (
size => {
Field => \@size,
Mandatory => 1,
},
);
sub pre_init :PreInit
{
my ($self, $args) = @_;
$$args{Vehicle}={environment => 'sea'};
}
}
package main;
my $car=Car->new(color => 'red');
my $ship=Ship->new(size => 'small');
print 'A ',$car->get_color(),' car drives on ',$car->get_environment(),".\n";
print 'A ',$ship->get_size(),' ship sails over the large ',$ship->get_environment(),".\n";
|
| Write a response |
(2)
]