File: single_arg.t

package info (click to toggle)
libmoox-buildargs-perl 0.04-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 140 kB
  • sloc: perl: 286; makefile: 2
file content (49 lines) | stat: -rwxr-xr-x 782 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env perl
use Test2::Bundle::Extended;

{
    package Foo;
    use Moo;
    with 'MooX::SingleArg';
    __PACKAGE__->single_arg('bar');
    has bar => ( is=>'ro' );
}

my $list = Foo->new( bar=>11 );
is(
    $list->bar(),
    11,
    'list arguments',
);

my $hash_ref = Foo->new({ bar=>22 });
is(
    $hash_ref->bar(),
    22,
    'hash ref arguments',
);

my $single   = Foo->new( 33 );
is(
    $single->bar(),
    33,
    'single arguments',
);

{
    package FooForced;
    use Moo;
    with 'MooX::SingleArg';
    __PACKAGE__->single_arg('bar');
    __PACKAGE__->force_single_arg( 1 );
    has bar => ( is=>'ro' );
}

my $forced = FooForced->new({ bar=>44 });
is(
    $forced->bar(),
    { bar=>44 },
    'hash ref arguments with force_single_arg',
);

done_testing;