Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
use MooseX::Declare;
class Point {
has x => ( isa => 'Int', is => 'rw' );
has y => ( isa => 'Int', is => 'rw' );
method negated { $self->new( x => -$self->x, y => -$self->y ) }
method transpose { $self->new( x => $self->y, y => $self->x ) }
method inspect { say $self->x . ' @ ' . $self->y }
}
my $p = Point->new( x => 4, y => 3 );
$p->negated->inspect; # => -4 @ -3
$p->transpose->inspect; # => 3 @ 4
role Negated {
requires 'transpose';
method negated { $self->transpose };
}
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