File: force.t

package info (click to toggle)
libmoosex-singlearg-perl 0.09-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 128 kB
  • sloc: perl: 217; makefile: 7
file content (33 lines) | stat: -rwxr-xr-x 551 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
#!/usr/bin/env perl
use strict;
use warnings;

use Test2::V0;

{
    package MyClass;
    use Moose;
    use MooseX::SingleArg;

    single_arg arg1 => (
        force => 1,
    );

    has arg1 => (
        is  => 'ro',
        isa => 'HashRef',
    );
}

{
    my $obj = MyClass->new( {one=>1} );
    is( $obj->arg1(), {one=>1}, 'able to set a single arg to a hashref' );
}

like(
    dies { MyClass->new( arg1 => {one=>1} ) },
    qr{accepts only one argument },
    'when force is on then passing more than one argument errors',
);

done_testing;