Created
June 9, 2009 22:06
-
-
Save draegtun/126830 to your computer and use it in GitHub Desktop.
This file contains 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
{ | |
package Point; | |
use Moose; | |
has x => ( isa => 'Int', is => 'rw' ); | |
has y => ( isa => 'Int', is => 'rw' ); | |
sub negated { | |
my $self = shift; | |
$self->new( x => -$self->x, y => -$self->y ); | |
} | |
sub transpose { | |
my $self = shift; | |
$self->new( x => $self->y, y => $self->x ); | |
} | |
sub inspect { say "$_[0]->{x} \@ $_[0]->{y}" } | |
no Moose; | |
} | |
my $p = Point->new( x => 4, y => 3 ); | |
$p->negated->inspect; # => -4 @ -3 | |
$p->transpose->inspect; # => 3 @ 4 | |
{ | |
package Negated; | |
use Moose::Role; | |
requires 'transpose'; | |
sub negated { | |
my $self = shift; | |
$self->transpose; | |
} | |
no Moose::Role; | |
} | |
Negated->meta->apply( $p ); | |
$p->negated->inspect; # => 3 @ 4 | |
$p->transpose->inspect; # => 3 @ 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment