draegtun (owner)

Revisions

gist: 126839 Download_button fork
public
Public Clone URL: git://gist.github.com/126839.git
Point_neo_moose.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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