blob: 4c2e080e20ed4fefa30471f98003b261731bfc60 (
plain)
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
|
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Test::Moose;
BEGIN {
package ExportsFoo;
use Sub::Exporter -setup => {
exports => ['foo'],
};
sub foo { 'FOO' }
$INC{'ExportsFoo.pm'} = 1;
}
{
package Foo;
use Moose::Role;
requires 'foo';
}
{
package Bar;
use Moose::Role;
requires 'bar';
}
{
package Class;
use Moose;
use ExportsFoo 'foo';
# The grossness near the end of the regex works around a bug with \Q not
# escaping \& properly with perl 5.8.x
::like(
::exception { with 'Foo' },
qr/^\Q'Foo' requires the method 'foo' to be implemented by 'Class'. If you imported functions intending to use them as methods, you need to explicitly mark them as such, via Class->meta->add_method(foo => \E\\\&foo\)/,
"imported 'method' isn't seen"
);
Class->meta->add_method(foo => \&foo);
::is(
::exception { with 'Foo' },
undef,
"now it's a method"
);
::like(
::exception { with 'Bar' },
qr/^\Q'Bar' requires the method 'bar' to be implemented by 'Class' at/,
"requirement isn't imported, so don't give the extra info in the error"
);
}
does_ok('Class', 'Foo');
done_testing;
|