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;
10 $TODO = q{Mouse is not yet completed};
16 package My::Attribute::Trait;
19 has 'alias_to' => (is => 'ro', isa => 'Str');
21 has foo => ( is => "ro", default => "blah" );
23 after 'install_accessors' => sub {
25 $self->associated_class->add_method(
27 $self->get_read_method_ref
31 package Mouse::Meta::Attribute::Custom::Trait::Aliased;
32 sub register_implementation { 'My::Attribute::Trait' }
36 package My::Other::Attribute::Trait;
43 has the_other_attr => ( isa => "Str", is => "rw", default => "oink" );
45 after 'install_accessors' => sub {
47 $self->associated_class->add_method(
53 package Mouse::Meta::Attribute::Custom::Trait::Other;
54 sub register_implementation { 'My::Other::Attribute::Trait' }
62 traits => [qw/Aliased/],
70 package My::Derived::Class;
76 traits => [qw/Other/],
80 my $c = My::Class->new(bar => 100);
81 isa_ok($c, 'My::Class');
83 is($c->bar, 100, '... got the right value for bar');
86 is($c->baz, 100, '... got the right value for baz');
88 my $bar_attr = $c->meta->get_attribute('bar');
89 does_ok($bar_attr, 'My::Attribute::Trait');
90 is($bar_attr->foo, "blah", "attr initialized");
92 ok(!$bar_attr->meta->does_role('Aliased'), "does_role ignores aliases for sanity");
93 ok($bar_attr->does('Aliased'), "attr->does uses aliases");
94 ok(!$bar_attr->meta->does_role('Fictional'), "does_role returns false for nonexistent roles");
95 ok(!$bar_attr->does('Fictional'), "attr->does returns false for nonexistent roles");
97 my $quux = My::Derived::Class->new(bar => 1000);
99 is($quux->bar, 1000, '... got the right value for bar');
101 can_ok($quux, 'baz');
102 is($quux->baz, 1000, '... got the right value for baz');
104 my $derived_bar_attr = $quux->meta->get_attribute("bar");
105 does_ok($derived_bar_attr, 'My::Attribute::Trait' );
107 is( $derived_bar_attr->foo, "blah", "attr initialized" );
109 does_ok($derived_bar_attr, 'My::Other::Attribute::Trait' );
111 is($derived_bar_attr->the_other_attr, "oink", "attr initialized" );
113 ok(!$derived_bar_attr->meta->does_role('Aliased'), "does_role ignores aliases for sanity");
114 ok($derived_bar_attr->does('Aliased'), "attr->does uses aliases");
115 ok(!$derived_bar_attr->meta->does_role('Fictional'), "does_role returns false for nonexistent roles");
116 ok(!$derived_bar_attr->does('Fictional'), "attr->does returns false for nonexistent roles");
118 can_ok($quux, 'additional_method');
119 is(eval { $quux->additional_method }, 42, '... got the right value for additional_method');