Commit | Line | Data |
f315aab3 |
1 | #!/usr/bin/perl |
2 | use strict; |
3 | use warnings; |
4 | use Test::More; |
5 | use Test::Exception; |
6 | |
7 | { |
8 | package Point; |
9 | use Moose; |
10 | |
11 | with qw/DoesNegated DoesTranspose/; |
12 | |
13 | has x => ( isa => 'Int', is => 'rw' ); |
14 | has y => ( isa => 'Int', is => 'rw' ); |
15 | |
16 | sub inspect { [$_[0]->x, $_[0]->y] } |
17 | |
18 | no Moose; |
19 | } |
20 | |
21 | { |
22 | package DoesNegated; |
23 | use Moose::Role; |
24 | |
25 | sub negated { |
26 | my $self = shift; |
27 | $self->new( x => -$self->x, y => -$self->y ); |
28 | } |
29 | |
30 | no Moose::Role; |
31 | } |
32 | |
33 | { |
34 | package DoesTranspose; |
35 | use Moose::Role; |
36 | |
37 | sub transpose { |
38 | my $self = shift; |
39 | $self->new( x => $self->y, y => $self->x ); |
40 | } |
41 | |
42 | no Moose::Role; |
43 | } |
44 | |
45 | my $p = Point->new( x => 4, y => 3 ); |
46 | |
47 | DoesTranspose->meta->apply( $p, alias => { transpose => 'negated' } ); |
48 | |
49 | is_deeply($p->negated->inspect, [3, 4]); |
50 | is_deeply($p->transpose->inspect, [3, 4]); |
51 | |
52 | done_testing; |