Commit | Line | Data |
777fcfcf |
1 | package MooObjectWithDelegate; |
2 | use ClassicObject; |
ee22f92c |
3 | use Scalar::Util (); |
777fcfcf |
4 | use Moo; |
5 | |
6 | has 'delegated' => ( |
7 | is => 'ro', |
8 | isa => sub { |
ee22f92c |
9 | do { $_[0] && Scalar::Util::blessed($_[0]) } |
777fcfcf |
10 | or die "Not an Object!"; |
11 | }, |
12 | lazy => 1, |
13 | builder => '_build_delegated', |
14 | handles => [qw/connect/], |
15 | ); |
16 | |
17 | sub _build_delegated { |
18 | my $self = shift; |
19 | return ClassicObject->new; |
20 | } |
21 | |
22 | around 'connect', sub { |
23 | my ($orig, $self, @args) = @_; |
24 | return $self->$orig(@args) . 'b'; |
25 | }; |
26 | |
27 | |
28 | 1; |