Skip to content

Commit

Permalink
Test class_has inheritance + default sub
Browse files Browse the repository at this point in the history
  • Loading branch information
pplu committed Feb 5, 2016
1 parent a89470b commit 386b3e4
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions t/13-default.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use strict;
use warnings;
use Test::More;

{
package ClassBase;

use Moose;
use MooseX::ClassAttribute;

class_has 'attributes' => (
is => 'ro',
lazy => 1,
default => sub {
my $class = shift;
my @atts = $class->meta->get_all_attributes;
return [ sort map { $_->name } @atts ];
},
);

has att1 => (is => 'ro');
has att2 => (is => 'ro');
}

{
package ClassChild;
use Moose;

extends 'ClassBase';

has att3 => (is => 'ro');
}

is_deeply(ClassBase->attributes, [ 'att1', 'att2' ]);
is_deeply(ClassChild->attributes, [ 'att1', 'att2', 'att3' ]);

{
package ClassBase2;

use Moose;
use MooseX::ClassAttribute;

class_has 'attributes' => (
is => 'ro',
lazy => 1,
default => sub {
my $class = shift;
my @atts = $class->meta->get_all_attributes;
return [ sort map { $_->name } @atts ];
},
);

has att1 => (is => 'ro');
has att2 => (is => 'ro');
}

{
package ClassChild2;
use Moose;

extends 'ClassBase2';

has att3 => (is => 'ro');
}

is_deeply(ClassChild2->attributes, [ 'att1', 'att2', 'att3' ]);
is_deeply(ClassBase2->attributes, [ 'att1', 'att2' ]);

done_testing();

0 comments on commit 386b3e4

Please sign in to comment.