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