| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
|
| 5 |
{ |
| 6 |
package Test::Composed; |
| 7 |
use Moose; |
| 8 |
with 'HTML::FormHandler::Traits'; |
| 9 |
|
| 10 |
has 'test' => ( is => 'rw' ); |
| 11 |
has 'foo' => ( is => 'rw' ); |
| 12 |
} |
| 13 |
|
| 14 |
{ |
| 15 |
package Test::Another; |
| 16 |
use Moose; |
| 17 |
with 'HTML::FormHandler::Traits'; |
| 18 |
has 'another_test' => ( is => 'rw' ); |
| 19 |
} |
| 20 |
|
| 21 |
{ |
| 22 |
package Test::Trait::One; |
| 23 |
use Moose::Role; |
| 24 |
|
| 25 |
has 'test_one' => ( is => 'rw' ); |
| 26 |
} |
| 27 |
|
| 28 |
{ |
| 29 |
package Test::Trait::Two; |
| 30 |
use Moose::Role; |
| 31 |
|
| 32 |
has 'test_two' => ( is => 'rw' ); |
| 33 |
|
| 34 |
} |
| 35 |
|
| 36 |
my $class = Test::Composed->with_traits( 'Test::Trait::One', 'Test::Trait::Two' ); |
| 37 |
is( $class, 'Test::Composed::1', 'got class' ); |
| 38 |
|
| 39 |
my $obj1 = $class->new( test_one => 1, test_two => 2 ); |
| 40 |
ok( $obj1, 'constructed an instance' ); |
| 41 |
is( $obj1->test_one, 1, 'right value' ); |
| 42 |
|
| 43 |
$class = Test::Composed->with_traits( 'Test::Trait::Two' ); |
| 44 |
is( $class, 'Test::Composed::2', 'got a class' ); |
| 45 |
|
| 46 |
my $obj2 = $class->new( test_two => 3 ); |
| 47 |
ok( $obj2, 'constructed an instance' ); |
| 48 |
is( $obj2->test_two, 3, 'right value' ); |
| 49 |
|
| 50 |
$class = Test::Another->with_traits( 'Test::Trait::One' ); |
| 51 |
is( $class, 'Test::Another::3', 'right class name' ); |
| 52 |
my $obj3 = $class->new( 'another_test' => 1 ); |
| 53 |
is( $obj3->another_test, 1, 'instance ok' ); |
| 54 |
|
| 55 |
my $obj4 = Test::Another->new_with_traits( traits => ['Test::Trait::Two'], test_two => 'foo' ); |
| 56 |
is( $obj4->test_two, 'foo', 'instantiated ok' ); |
| 57 |
is( $obj4->meta->name, 'Test::Another::4', 'named ok' ); |
| 58 |
|
| 59 |
|
| 60 |
done_testing; |