hi, would something like that OK?

package Test;

use Moose;

has 'ver' => ( required => 1 );

has '_obj' => (
  lazy => 1,
  default => sub {
     my $self = shift;
     if ( $self->ver == 1 ) {
        return Test::V1->new(@_);
    } else {
         return Test::V2->new(@_);
     },
  },
  handles => sub {
         my ( $self, $meta ) = @_;
         if ( $self->ver == 1 ) {
              return map { $_ => $_ ) ('sub1', 'sub2'); # subs/attrs in Test::V1
         } else {
              return map { $_ => $_ ) ('sub3', 'sub4'); # subs/attrs in Test::V2
         }
  }
);

Thanks.

On Sat, Apr 18, 2009 at 9:42 PM, Fayland Lam <fayl...@gmail.com> wrote:
> one more thing, when I call
>
> Test->new( ver => 2, otherval => 3 );
> the delegation would pass otherval => 3 to Test::V2 too.
>
> Thanks for any tip.
>
> On Sat, Apr 18, 2009 at 7:51 PM, Fayland Lam <fayl...@gmail.com> 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/

Reply via email to