forked from moose/MooseX-ClassAttribute
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test class_has inheritance + default sub
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |