Created
February 20, 2009 07:14
-
-
Save hidek/67358 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| package Parent; | |
| use strict; | |
| use warnings; | |
| sub new { | |
| my ($class, %args) = @_; | |
| bless {%args}, $class; | |
| } | |
| sub name { | |
| my ($self, $name) = @_; | |
| $self->{name} = $name if $name; | |
| return $self->{name}; | |
| } | |
| package Child; | |
| use Moose; | |
| has parent => ( | |
| is => 'ro', | |
| isa => 'Parent', | |
| handles => [qw/ name hello/], | |
| ); | |
| no Moose; | |
| sub BUILDARGS { | |
| my ($class, %args) = @_; | |
| $args{parent} = Parent->new(%args); | |
| return {%args}; | |
| } | |
| __PACKAGE__->meta->make_immutable; | |
| } | |
| my $child = Child->new(name => 'hoge'); | |
| warn $child->name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment