Skip to content

@mstratman /Animal2.pm
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
# NOTE: This is simply an example of a legacy blessed-hash object.
# I do not recommend using it.
package Animal2;
use strict;
sub new {
my $class = shift;
my $self = {};
$self->{_name} = shift;
bless($self, $class);
return $self;
}
sub name {
my $self = shift;
if (@_) { $self->{_name} = shift }
return $self->{_name};
}
1;
package Camel;
use Moose;
use MooseX::NonMoose;
extends 'Animal2';
has 'humps' => ( is => 'ro', isa => 'Num' );
sub FOREIGNBUILDARGS {
my $class = shift;
# We expect a hashref with 'name' and 'humps'.
my $args = shift;
# Give Animal2 what it wants: just the name, and nothing else.
return $args->{name};
}
no Moose;
__PACKAGE__->meta->make_immutable;
#!/usr/bin/perl
use Modern::Perl;
use Camel;
my $c = Camel->new({ name => "Samuel Camel", humps => 2 });
say $c->name, " has ", $c->humps, " humps";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.