Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save hidek/71265 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
{
package Parent;
use fields qw(name);
sub new {
my ($class, %args) =@_;
my $self = ref $class ? $class : fields::new($class);
$self->{name} = $args{name};
$self;
}
}
{
package Child;
use Moose;
extends qw(Parent Moose::Object);
no Moose;
sub new {
my $class = shift;
my $obj = $class->SUPER::new(@_);
return $class->meta->new_object(
__INSTANCE__ => $obj,
@_,
);
}
__PACKAGE__->meta->make_immutable;
}
my $obj = Child->new(name => 'foo');
warn $obj->{name};
#Pseudo-hashes are deprecated at subclass.pl line 10.
#No such pseudo-hash field "name" at subclass.pl line 10.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment