File: composed.t

package info (click to toggle)
libhtml-formhandler-perl 0.40057-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,320 kB
  • ctags: 685
  • sloc: perl: 8,849; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,443 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use strict;
use warnings;
use Test::More;

{
    package Test::Composed;
    use Moose;
    with 'HTML::FormHandler::Traits';

    has 'test' => ( is => 'rw' );
    has 'foo' => ( is => 'rw' );
}

{
    package Test::Another;
    use Moose;
    with 'HTML::FormHandler::Traits';
    has 'another_test' => ( is => 'rw' );
}

{
    package Test::Trait::One;
    use Moose::Role;

    has 'test_one' => ( is => 'rw' );
}

{
    package Test::Trait::Two;
    use Moose::Role;

    has 'test_two' => ( is => 'rw' );

}

my $class = Test::Composed->with_traits( 'Test::Trait::One', 'Test::Trait::Two' );
is( $class, 'Test::Composed::1', 'got class' );

my $obj1 = $class->new( test_one => 1, test_two => 2 );
ok( $obj1, 'constructed an instance' );
is( $obj1->test_one, 1, 'right value' );

$class = Test::Composed->with_traits( 'Test::Trait::Two' );
is( $class, 'Test::Composed::2', 'got a class' );

my $obj2 = $class->new( test_two => 3 );
ok( $obj2, 'constructed an instance' );
is( $obj2->test_two, 3, 'right value' );

$class = Test::Another->with_traits( 'Test::Trait::One' );
is( $class, 'Test::Another::3', 'right class name' );
my $obj3 = $class->new( 'another_test' => 1 );
is( $obj3->another_test, 1, 'instance ok' );

my $obj4 = Test::Another->new_with_traits( traits => ['Test::Trait::Two'], test_two => 'foo' );
is( $obj4->test_two, 'foo', 'instantiated ok' );
is( $obj4->meta->name, 'Test::Another::4', 'named ok' );


done_testing;