Skip to content

Instantly share code, notes, and snippets.

@hidek
Created February 27, 2009 03:30
Show Gist options
  • Select an option

  • Save hidek/71268 to your computer and use it in GitHub Desktop.

Select an option

Save hidek/71268 to your computer and use it in GitHub Desktop.
{
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/],
);
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