File: sanity_check.t

package info (click to toggle)
libmoosex-abstractmethod-perl 0.004-2
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 208 kB
  • sloc: perl: 334; makefile: 2
file content (86 lines) | stat: -rw-r--r-- 1,913 bytes parent folder | download
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env perl
#
# This file is part of MooseX-AbstractMethod
#
# This software is Copyright (c) 2011 by Chris Weyl.
#
# This is free software, licensed under:
#
#   The GNU Lesser General Public License, Version 2.1, February 1999
#

# basically, a test suite to make sure my understanding of how the method MOP
# works is correct... and that it stays that way :)

use Test::More 0.82;
use Test::Moose;
use Moose::Util 'does_role';


{
    package Test::Trait::Method;
    use Moose::Role;
    use namespace::autoclean;

}

my $abstract_meta = Moose::Meta::Class->create_anon_class(
    superclasses => [ 'Moose::Meta::Method' ],
    roles        => [ 'Test::Trait::Method' ],
    cache        => 1,
);

{
    package foo;
    use Moose;

    sub _abstract {
        my $name = shift;

        my $method = $abstract_meta->name->wrap(sub { die },
                name         => $name,
                package_name => __PACKAGE__,
        );

        __PACKAGE__->meta->add_method($name => $method)
    }

    _abstract('dne');
    _abstract('dne2');
}
{
    package bar;
    use Moose;

    extends 'foo';

    sub dne { warn "now implemented!" }
}

use constant TESTTRAIT => 'Test::Trait::Method';

with_immutable {

    # base class
    my $foo_mmeta = foo->meta->get_method('dne');
    meta_ok('foo');
    does_ok($foo_mmeta, TESTTRAIT);

    with_immutable {

        # descendents
        my $bar_mmeta  = bar->meta->find_method_by_name('dne');
        my $dne2_mmeta = bar->meta->find_method_by_name('dne2');

        # method is overridden
        ok !does_role($bar_mmeta, TESTTRAIT), 'bar::dne does not do TESTTRAIT';;
        is 'bar', $bar_mmeta->original_package_name, 'bar::dne from bar';

        # method is not overridden
        ok does_role($dne2_mmeta, TESTTRAIT);
        is 'foo', $dne2_mmeta->original_package_name, 'bar::dne2 from foo';
    } qw{ bar };

} qw{ foo };

done_testing;