well, my final solution is
package Test;
use Moose;
sub new {
my $class = shift;
my $params = $class->BUILDARGS(@_);
my $obj;
if ( $params->{ver} == 1 ) {
require T::V1;
$obj = T::V1->new($params);
} else {
require T::V2;
$obj = T::V2->new($params);
}
return $class->meta->new_object(
__INSTANCE__ => $obj,
@_,
);
}
any comment are welcome. Thanks.
>> On Sat, Apr 18, 2009 at 7:51 PM, Fayland Lam <[email protected]> wrote:
>>> see I have Test::V1 and Test::V2.
>>>
>>> package Test::V1;
>>> use Moose;
>>> has 'var' => ( default => 1 );
>>> package Test::V2;
>>> use Moose;
>>> has 'var' => (default => 2 );
>>>
>>> then I have a Test
>>> package Test;
>>> use Moose;
>>> has 'ver' => ( required => 1 );
>>>
>>> I want something like follows:
>>> my $t1 = Test->new( ver => 1);
>>> print $t1->var; # 1;
>>> my $t2 = Test->new( ver => 2 );
>>> print $t2->var; # 2
>>>
>>> in V1 and V2, there would be something more than 'var' and have different
>>> subs.
>>> how to delegate depends on the 'ver' in Test? any hint?
>>>
>>> Thanks.
>>>
>>> --
>>> Fayland Lam // http://www.fayland.org/
>>> Foorum based on Catalyst // http://www.foorumbbs.com/
>>>
>>
>>
>>
>> --
>> Fayland Lam // http://www.fayland.org/
>> Foorum based on Catalyst // http://www.foorumbbs.com/
>>
>
>
>
> --
> Fayland Lam // http://www.fayland.org/
> Foorum based on Catalyst // http://www.foorumbbs.com/
>
--
Fayland Lam // http://www.fayland.org/
Foorum based on Catalyst // http://www.foorumbbs.com/