Failing test for an unparameterized method
[gitmo/MooseX-Role-Parameterized.git] / t / 011-reference-parameters.t
CommitLineData
dc032014 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More tests => 8;
5
6do {
7 package MyRole::Delegator;
8 use MooseX::Role::Parameterized;
9
10 parameter handles => (
11 is => 'rw',
12 required => 1,
13 );
14
15 role {
16 my $p = shift;
17
18 has attr => (
19 is => 'rw',
20 isa => 'MyClass::WithMethods',
21 handles => $p->handles,
22 );
23 };
24};
25
26do {
27 package MyClass::WithMethods;
28
29 sub foo { "foo" }
30 sub bar { "bar" }
31 sub baz { "baz" }
32};
33
34do {
35 package MyArrayConsumer;
36 use Moose;
37 with 'MyRole::Delegator' => {
38 handles => ['foo', 'bar'],
39 };
40};
41
42can_ok(MyArrayConsumer => 'foo', 'bar');
43cant_ok(MyArrayConsumer => 'baz');
44
45do {
46 package MyRegexConsumer;
47 use Moose;
48 with 'MyRole::Delegator' => {
49 handles => qr/^ba/,
50 };
51};
52
53can_ok(MyRegexConsumer => 'bar', 'baz');
54cant_ok(MyRegexConsumer => 'foo');
55
56do {
57 package MyHashConsumer;
58 use Moose;
59 with 'MyRole::Delegator' => {
60 handles => {
61 my_foo => 'foo',
62 his_baz => 'baz',
63 },
64 };
65};
66
67can_ok(MyHashConsumer => 'my_foo', 'his_baz');
68cant_ok(MyHashConsumer => qw/foo bar baz/);
69
70sub cant_ok {
71 local $Test::Builder::Level = $Test::Builder::Level + 1;
72 my $instance = shift;
73 for my $method (@_) {
74 ok(!$instance->can($method), "$instance cannot $method");
75 }
76}
77