There is not really any automatic way to do this in Mojo::Base, it's a very
simple module. But you could do something like this.
has 'token' => sub { my $self = shift; exists $self->{Tiger} ?
$self->Tiger->token : $self->token };
This would only affect the default of course, and would not update based on
the contained Tiger's token. If you want it properly delegated, you should
upgrade to Moo or Moose classes, and allow the Tiger attribute to delegate
'token'. See https://metacpan.org/pod/Moose::Manual::Delegation ('handles'
works mostly the same in Moo and Moose).
On Thu, Apr 6, 2017 at 4:07 PM, Pavel Serikov <[email protected]>
wrote:
> Question in comment to code :)
>
> package Cat;
> use Mojo::Base -base;
>
> has 'token' => '12345';
> has 'Tiger' => sub { Cat::Tiger-> new };
>
>
> package Cat::Tiger;
> use Mojo::Base 'Cat';
>
>
> package main;
> my $c = Cat->new(token=>'54321');
> warn Dumper $c->Tiger->token; # how to make '54321' instead of '12345' ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.