Commit | Line | Data |
4a07d076 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use Test::More; |
6 | use Test::Exception; |
7 | |
8 | { |
9 | package Foo; |
10 | use Mouse; |
11 | |
12 | has foo => ( |
13 | is => 'ro', |
14 | ); |
15 | |
16 | has bar => ( |
17 | clearer => 'clear_bar', |
18 | ); |
19 | } |
20 | |
21 | { |
22 | package Foo::Sub; |
23 | use Mouse; |
24 | |
25 | extends 'Foo'; |
26 | |
b4d32aba |
27 | ::lives_ok { has '+foo' => (is => 'rw') } "can override is"; |
4a07d076 |
28 | ::throws_ok { has '+foo' => (reader => 'bar') } qr/illegal/, "can't override reader"; |
29 | ::lives_ok { has '+foo' => (clearer => 'baz') } "can override unspecified things"; |
30 | |
31 | ::throws_ok { has '+bar' => (clearer => 'quux') } qr/illegal/, "can't override clearer"; |
32 | ::lives_ok { has '+bar' => (predicate => 'has_bar') } "can override unspecified things"; |
33 | } |
34 | |
35 | { |
36 | package Bar::Meta::Attribute; |
37 | use Mouse::Role; |
38 | |
39 | has my_illegal_option => (is => 'ro'); |
40 | |
41 | around illegal_options_for_inheritance => sub { |
42 | return (shift->(@_), 'my_illegal_option'); |
43 | }; |
44 | } |
45 | |
46 | { |
47 | package Bar; |
48 | use Mouse; |
49 | |
50 | ::lives_ok { |
51 | has bar => ( |
52 | traits => ['Bar::Meta::Attribute'], |
53 | my_illegal_option => 'FOO', |
54 | is => 'bare', |
55 | ); |
56 | } "can use illegal options"; |
57 | |
58 | has baz => ( |
59 | traits => ['Bar::Meta::Attribute'], |
60 | is => 'bare', |
61 | ); |
62 | } |
63 | |
64 | { |
65 | package Bar::Sub; |
66 | use Mouse; |
67 | |
68 | extends 'Bar'; |
69 | |
70 | ::throws_ok { has '+bar' => (my_illegal_option => 'BAR') } |
71 | qr/illegal/, |
72 | "can't override illegal attribute"; |
73 | ::lives_ok { has '+baz' => (my_illegal_option => 'BAR') } |
74 | "can add illegal option if superclass doesn't set it"; |
75 | } |
76 | |
77 | my $bar_attr = Bar->meta->get_attribute('bar'); |
78 | ok((grep { $_ eq 'my_illegal_option' } $bar_attr->illegal_options_for_inheritance) > 0, '... added my_illegal_option as illegal option for inheritance'); |
79 | |
80 | done_testing; |