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'; |
35 | ::like( |
36 | ::exception { with 'Foo' }, |
37 | 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 => \&foo)/, |
38 | "imported 'method' isn't seen" |
39 | ); |
40 | Class->meta->add_method(foo => \&foo); |
41 | ::is( |
42 | ::exception { with 'Foo' }, |
43 | undef, |
44 | "now it's a method" |
45 | ); |
46 | |
47 | ::like( |
48 | ::exception { with 'Bar' }, |
49 | qr/^\Q'Bar' requires the method 'bar' to be implemented by 'Class' at/, |
50 | "requirement isn't imported, so don't give the extra info in the error" |
51 | ); |
52 | } |
53 | |
54 | does_ok('Class', 'Foo'); |
55 | |
56 | done_testing; |