Commit | Line | Data |
8d57392a |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
4 | use Test::More; |
5 | use Test::Fatal; |
6 | use Test::Moose; |
7 | |
8 | BEGIN { |
9 | package ExportsFoo; |
10 | use Sub::Exporter -setup => { |
11 | exports => ['foo'], |
12 | }; |
13 | |
14 | sub foo { 'FOO' } |
15 | |
16 | $INC{'ExportsFoo.pm'} = 1; |
17 | } |
18 | |
19 | { |
20 | package Foo; |
21 | use Moose::Role; |
22 | requires 'foo'; |
23 | } |
24 | |
25 | { |
26 | package Bar; |
27 | use Moose::Role; |
28 | requires 'bar'; |
29 | } |
30 | |
31 | { |
32 | package Class; |
33 | use Moose; |
34 | use ExportsFoo 'foo'; |
afd879e0 |
35 | |
36 | # The grossness near the end of the regex works around a bug with \Q not |
37 | # escaping \& properly with perl 5.8.x |
8d57392a |
38 | ::like( |
39 | ::exception { with 'Foo' }, |
afd879e0 |
40 | 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\)/, |
8d57392a |
41 | "imported 'method' isn't seen" |
42 | ); |
43 | Class->meta->add_method(foo => \&foo); |
44 | ::is( |
45 | ::exception { with 'Foo' }, |
46 | undef, |
47 | "now it's a method" |
48 | ); |
49 | |
50 | ::like( |
51 | ::exception { with 'Bar' }, |
52 | qr/^\Q'Bar' requires the method 'bar' to be implemented by 'Class' at/, |
53 | "requirement isn't imported, so don't give the extra info in the error" |
54 | ); |
55 | } |
56 | |
57 | does_ok('Class', 'Foo'); |
58 | |
59 | done_testing; |