File: 114_init_arg.t

package info (click to toggle)
libmoosex-getopt-perl 0.78-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 508 kB
  • sloc: perl: 607; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,155 bytes parent folder | download | duplicates (4)
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
use strict;
use warnings;

use Test::More 0.88;
use if $ENV{AUTHOR_TESTING}, 'Test::Warnings';

{
    package Test1;
    use Moose;
    with 'MooseX::Getopt';

    has _private => ( is => 'ro', isa => 'Str', init_arg => 'public' );
    has name_after => ( is => 'ro', isa => 'Str', init_arg => 'name_before' );
    has bar => ( is => 'ro', isa => 'Str', );
    has undefined_init_arg => ( is => 'ro', isa => 'Str', init_arg => undef );
};


{
    my $obj = Test1->new_with_options(
        argv => [ '--name_before', 'something', '--bar', 'baz', '--public',
                  1 ] );
    is( $obj->name_after, 'something', 'init_arg is respected' );

    is( $obj->_private, 1, 'works with "public" init_arg and private attribute');
}

{
    package Test::Dashes;
    use Moose;
    with 'MooseX::Getopt::Dashes';

    has name_after => ( is => 'ro', isa => 'Str', init_arg => 'name-before' );
    has bar => ( is => 'ro', isa => 'Str', );
};

{
    my $obj = Test::Dashes->new_with_options(
        argv => [ '--name-before', 'something', '--bar', 'baz', ] );
    is( $obj->name_after, 'something', 'init_arg is respected with dashes' );
}

done_testing;