File: init_arg.t

package info (click to toggle)
libmoox-aliases-perl 0.001006-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 148 kB
  • sloc: perl: 74; makefile: 2
file content (62 lines) | stat: -rw-r--r-- 1,664 bytes parent folder | download | duplicates (3)
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
61
62
use strictures 1;
use Test::More;

{
    package MyTest;
    use Moo;
    use MooX::Aliases;

    has foo => (
        is    => 'ro',
        alias => ['bar'],
    );

    has baz => (
        is => 'rw',
        init_arg => undef,
        alias    => ['quux'],
    );

    package MyTest::Sub;
    use Moo;
    use MooX::Aliases;

    extends qw(MyTest);
    has '+foo' => (
        is      => 'rw',
        alias   => 'override',
    );
}

my $test1 = MyTest->new(foo => 'foo', baz => 'baz');
is($test1->foo, 'foo', 'Attribute set with default init_arg');
is($test1->baz, undef, 'Attribute set with default init_arg (undef)');

$test1->baz('baz');
is($test1->baz, 'baz',
    'Attribute set with default writer, read with default reader');
is($test1->quux, 'baz',
    'Attribute set with default writer, read with aliased reader');

$test1->quux('quux');
is($test1->baz, 'quux', 'Attribute set with aliased writer');
is($test1->quux, 'quux', 'Attribute set with aliased writer');

my $test2 = MyTest->new(bar => 'foo', baz => 'baz');
is($test2->foo, 'foo', 'Attribute set wtih aliased init_arg');
is($test2->baz, undef, 'Attribute set with default init_arg (undef)');

$test2->baz('baz');
is($test2->baz, 'baz',
    'Attribute set with default writer, read with default reader');
is($test2->quux, 'baz',
    'Attribute set with default writer, read with aliased reader');

$test2->quux('quux');
is($test2->baz, 'quux', 'Attribute set with aliased writer');
is($test2->quux, 'quux', 'Attribute set with aliased writer');

my $test3 = MyTest::Sub->new(override => 'over');
is($test3->override, 'over', 'Overriden attribute set with aliased writer');

done_testing;