File: with-type-tiny.t

package info (click to toggle)
libmoose-perl 2.2207-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 7,416 kB
  • sloc: perl: 21,345; ansic: 291; makefile: 10
file content (101 lines) | stat: -rw-r--r-- 1,810 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use strict;
use warnings;

use Test::Needs { 'Types::Standard' => 0.021_03 };
use Test::More;
use Test::Fatal;

my @array_delegations = qw(
    accessor
    clear
    count
    delete
    elements
    first_index
    first
    get
    grep
    insert
    is_empty
    join
    map
    natatime
    pop
    push
    reduce
    set
    shallow_clone
    shift
    shuffle
    sort_in_place
    sort
    splice
    uniq
    unshift
);

my @hash_delegations = qw(
    accessor
    clear
    count
    defined
    delete
    elements
    exists
    get
    is_empty
    keys
    kv
    set
    shallow_clone
    values
);

is(
    exception {
        package MyClass;

        use Moose;
        use Types::Standard qw/ ArrayRef HashRef Str /;

        has plain_array => (
            is      => 'ro',
            isa     => ArrayRef,
            traits  => ['Array'],
            handles => {
                map { $_ . '_plain_array' => $_ } @array_delegations
            }
        );

        has array_of_str => (
            is      => 'ro',
            isa     => ArrayRef[Str],
            traits  => [ 'Array' ],
            handles => {
                map { $_ . '_array_of_str' => $_ } @array_delegations
            }
        );

        has plain_hash => (
            is      => 'ro',
            isa     => HashRef,
            traits  => ['Hash'],
            handles => {
                map { $_ . '_plain_hash' => $_ } @hash_delegations
            }
        );

        has hash_of_str => (
            is      => 'ro',
            isa     => HashRef[Str],
            traits  => [ 'Hash' ],
            handles => {
                map { $_ . '_hash_of_str' => $_ } @hash_delegations
            }
        );
    },
    undef,
    'Type::Tiny is usable with native traits',
);

done_testing;