Skip to content

Instantly share code, notes, and snippets.

@mstratman
Created March 11, 2011 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mstratman/865259 to your computer and use it in GitHub Desktop.
Save mstratman/865259 to your computer and use it in GitHub Desktop.
# NOTE: This is simply an example of a legacy blessed-hash object.
# I do not recommend using it.
package Animal1;
use strict;
sub new {
my $class = shift;
my $self = shift;
$self = {} unless $self && ref $self eq 'HASH';
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 'Animal1';
has 'humps' => ( is => 'ro', isa => 'Num' );
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