~ubuntu-branches/ubuntu/precise/libmoosex-aliases-perl/precise

« back to all changes in this revision

Viewing changes to t/03-roles.t

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Yu
  • Date: 2011-02-26 22:55:41 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110226225541-eiamo6l2vqqdbdtu
Tags: 0.09-1
* New upstream release
* Bump to debhelper compat 8
* Use new 3.0 (quilt) source format
* Standards-Version 3.9.1
  - Explicitly refer to GPL-1 license text in common-licenses.
* Update dependencies per upstream
* No longer run RELEASE_TESTING tests
* Refresh copyright information

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env perl
 
2
use strict;
 
3
use warnings;
 
4
use Test::More tests => 6;
 
5
use Test::Moose;
 
6
use Test::Requires { Moose => 1.9900 };
 
7
 
 
8
my ($foo_called, $baz_called, $run_called);
 
9
 
 
10
{
 
11
    package MyTestRole;
 
12
    use Moose::Role;
 
13
    use MooseX::Aliases;
 
14
 
 
15
    has foo => (
 
16
        is      => 'rw',
 
17
        alias   => 'bar',
 
18
        trigger => sub { $foo_called++ },
 
19
    );
 
20
 
 
21
    has baz => (
 
22
        is      => 'rw',
 
23
        alias   => [qw/quux quuux/],
 
24
        trigger => sub { $baz_called++ },
 
25
    );
 
26
 
 
27
    sub run { $run_called++ }
 
28
    alias walk => 'run';
 
29
}
 
30
 
 
31
{
 
32
    package MyTest;
 
33
    use Moose;
 
34
    with 'MyTestRole';
 
35
}
 
36
 
 
37
with_immutable {
 
38
    ($foo_called, $baz_called, $run_called) = (0, 0, 0);
 
39
    my $t = MyTest->new;
 
40
    $t->foo(1);
 
41
    $t->bar(1);
 
42
    $t->baz(1);
 
43
    $t->quux(1);
 
44
    $t->quuux(1);
 
45
    is($foo_called, 2, 'all aliased methods were called from foo');
 
46
    is($baz_called, 3, 'all aliased methods were called from baz');
 
47
    $t->run;
 
48
    $t->walk;
 
49
    is($run_called, 2, 'all aliased methods were called from run');
 
50
} 'MyTest';