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