use strict;
use warnings;
-use Test::More tests => 12;
+use Test::More tests => 13;
use Test::Exception;
use Test::Moose;
use Moose::Role;
has 'alias_to' => (is => 'ro', isa => 'Str');
+
+ has foo => ( is => "ro", default => "blah" );
after 'install_accessors' => sub {
my $self = shift;
does_ok($bar_attr, 'My::Attribute::Trait');
ok($bar_attr->has_applied_traits, '... got the applied traits');
is_deeply($bar_attr->applied_traits, [qw/My::Attribute::Trait/], '... got the applied traits');
+is($bar_attr->foo, "blah", "attr initialized");
my $gorch_attr = $c->meta->get_attribute('gorch');
ok(!$gorch_attr->does('My::Attribute::Trait'), '... gorch doesnt do the trait');
use strict;
use warnings;
-use Test::More tests => 13;
+use Test::More tests => 16;
use Test::Exception;
use Test::Moose;
{
package My::Attribute::Trait;
use Moose::Role;
-
+
has 'alias_to' => (is => 'ro', isa => 'Str');
-
+
+ has foo => ( is => "ro", default => "blah" );
+
after 'install_accessors' => sub {
my $self = shift;
$self->associated_class->add_method(
- $self->alias_to,
+ $self->alias_to,
$self->get_read_method_ref
);
};
-
+
package Moose::Meta::Attribute::Custom::Trait::Aliased;
sub register_implementation { 'My::Attribute::Trait' }
}
{
package My::Other::Attribute::Trait;
use Moose::Role;
-
+
my $method = sub {
42;
- };
-
+ };
+
+ has bar => ( isa => "Str", default => "oink" );
+
after 'install_accessors' => sub {
my $self = shift;
$self->associated_class->add_method(
- 'additional_method',
+ 'additional_method',
$method
);
};
-
+
package Moose::Meta::Attribute::Custom::Trait::Other;
sub register_implementation { 'My::Other::Attribute::Trait' }
}
{
package My::Class;
use Moose;
-
+
has 'bar' => (
traits => [qw/Aliased/],
is => 'ro',
);
}
-{
+{
package My::Derived::Class;
use Moose;
can_ok($c, 'baz') and
is($c->baz, 100, '... got the right value for baz');
-does_ok($c->meta->get_attribute('bar'), 'My::Attribute::Trait');
+my $bar_attr = $c->meta->get_attribute('bar');
+does_ok($bar_attr, 'My::Attribute::Trait');
+is($bar_attr->foo, "blah", "attr initialized");
my $quux = My::Derived::Class->new(bar => 1000);
can_ok($quux, 'baz');
is($quux->baz, 1000, '... got the right value for baz');
-ok($quux->meta->get_attribute('bar')->does('My::Attribute::Trait'));
+
+my $derived_bar_attr = $quux->meta->get_attribute("bar");
+does_ok($derived_bar_attr, 'My::Attribute::Trait' );
+
+is( $derived_bar_attr->foo, "blah", "attr initialized" );
TODO: {
- local $TODO = 'These do not pass - bug?';
- SKIP: {
- skip 'no additional_method, so cannot test its value', 1 if !can_ok($quux, 'additional_method');
- is($quux->additional_method, 42, '... got the right value for additional_method');
- }
- ok($quux->meta->get_attribute('bar')->does('My::Other::Attribute::Trait'));
+ local $TODO = 'traits in clone_and_inherit dont work yet';
+ does_ok($derived_bar_attr, 'My::Other::Attribute::Trait' );
+
+ is( eval { $derived_bar_attr->bar }, "oink", "attr initialized" );
+
+ can_ok($quux, 'additional_method');
+ is(eval { $quux->additional_method }, 42, '... got the right value for additional_method');
}