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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../";
use Test::More;
use t::Util;
test('Foo in t/lib/Foo.pm', <<'END', {'MooseX::Declare' => 0});
use MooseX::Declare;
class Foo {
has 'affe' => (
is => 'ro',
isa => 'Str',
);
method foo ($x) { $x }
method inner { 23 }
method bar ($moo) { "outer(${moo})-" . inner() }
class ::Bar is mutable {
method bar { blessed($_[0]) ? 0 : 1 }
}
class ::Baz {
method baz {}
}
}
END
test('Role in t/lib/Foo.pm', <<'END', {'MooseX::Declare' => 0});
use MooseX::Declare;
role Role {
requires 'required_thing';
method role_method {}
}
END
test('Moo::Kooh in t/lib/Foo.pm', <<'END', {'MooseX::Declare' => 0, Foo => 0, Role => 0});
use MooseX::Declare;
class Moo::Kooh {
extends 'Foo';
around foo ($x) { $x + 1 }
augment bar ($moo) { "inner(${moo})" }
method kooh {}
method required_thing {}
with 'Role';
}
END
test('Corge in t/lib/Foo.pm', <<'END', {'MooseX::Declare' => 0, 'Foo::Baz' => 0, Role => 0});
use MooseX::Declare;
class Corge extends Foo::Baz with Role {
method corge {}
method required_thing {}
}
END
test('Quux in t/lib/Foo.pm', <<'END', {'MooseX::Declare' => 0, 'Corge' => 0});
use MooseX::Declare;
class Quux extends Corge {
has 'x' => (
is => 'ro',
isa => 'Int',
);
method quux {}
}
END
test('SecondRole in t/lib/Foo.pm', <<'END', {'MooseX::Declare' => 0});
use MooseX::Declare;
role SecondRole {}
END
test('SecondRole in t/lib/Foo.pm', <<'END', {'MooseX::Declare' => 0, 'Role' => 0, 'SecondRole' => 0});
use MooseX::Declare;
class MultiRole with Role with SecondRole {
method required_thing {}
}
END
test('SecondRole in t/lib/Foo.pm', <<'END', {'MooseX::Declare' => 0, 'Role' => 0, 'SecondRole' => 0});
use MooseX::Declare;
class MultiRole2 with (Role, SecondRole) {
method required_thing {}
}
END
test('manual namespace', <<'END', {'MooseX::Declare' => 0, 'Foo::Bar::Baz' => 0, 'Foo::Bar::Fnording' => 0});
use MooseX::Declare;
namespace Foo::Bar;
sub base { __PACKAGE__ }
class ::Baz {
sub TestPackage::baz { __PACKAGE__ }
}
role ::Fnording {
sub TestPackage::fnord { __PACKAGE__ }
}
class ::Qux extends ::Baz with ::Fnording {
sub TestPackage::qux { __PACKAGE__ }
}
END
test('manual namespace', <<'END', {'MooseX::Declare' => 0, 'Foo::Z' => 0, 'Foo::A' => 0, 'Foo::B' => 0, 'Foo::C' => 0});
use MooseX::Declare;
namespace Foo;
role ::Z {
method foo (Int $x) { $x }
}
role ::C {
with '::Z';
around foo (Int $x) { $self->$orig(int($x / 3)) }
}
role ::B {
with '::C';
around foo (Int $x) { $self->$orig($x + 2) }
}
role ::A {
with '::B';
around foo (Int $x) { $self->$orig($x * 2) }
}
class TEST {
with '::A';
around foo (Int $x) { $self->$orig($x + 2) }
}
class AnotherTest {
with '::Z';
around foo (Int $x) { $self->$orig($x * 2) }
}
END
done_testing;
|