Skip to content

Instantly share code, notes, and snippets.

@alecchen
Created June 15, 2012 07:42
Show Gist options
  • Save alecchen/2935250 to your computer and use it in GitHub Desktop.
Save alecchen/2935250 to your computer and use it in GitHub Desktop.
#---------------------------------------------------------------------------
# Foo
#---------------------------------------------------------------------------
package Foo;
use Moose;
has 'name' => ( is => 'rw', isa => 'Str' );
sub hello {
my $self = shift;
print $self->name, "\n";
}
#---------------------------------------------------------------------------
# Bar
#---------------------------------------------------------------------------
package Bar;
sub new {
my ($class, %args) = @_;
my $self = bless \%args, $class;
return $self;
}
sub name {
my ($self, $new_value) = @_;
$self->{name} = $new_value if $new_value;
return $self->{name};
}
sub hello {
my $self = shift;
print $self->name, "\n";
}
1;
#---------------------------------------------------------------------------
# main
#---------------------------------------------------------------------------
package main;
my $foo = Foo->new(name => 'FOO');
$foo->hello;
my $bar = Bar->new(name => 'BAR');
$bar->hello;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment