Created
February 27, 2009 03:27
-
-
Save hidek/71265 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
| 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