File: types.t

package info (click to toggle)
libfunction-parameters-perl 2.001003-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 948 kB
  • sloc: perl: 6,478; makefile: 3
file content (42 lines) | stat: -rw-r--r-- 957 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
#!perl
use strict;
use warnings FATAL => 'all';
use Test::More
    eval { require Moose; require MooseX::Types }
    ? (tests => 4)
    : (skip_all => "Moose, MooseX::Types required for testing types")
;
use Test::Fatal;

{
    package MyTypes;
    use MooseX::Types::Moose qw/Str/;
    use Moose::Util::TypeConstraints;
    use MooseX::Types -declare => [qw/CustomType/];

    BEGIN {
        subtype CustomType,
            as Str,
            where { length($_) == 2 };
    }
}

{
    package TestClass;
    use Function::Parameters qw(:strict);
    BEGIN { MyTypes->import('CustomType') };
    use MooseX::Types::Moose qw/ArrayRef/;
    #use namespace::clean;

    method foo ((CustomType) $bar) { }

    method bar ((ArrayRef[CustomType]) $baz) { }
}

my $o = bless {} => 'TestClass';

is(exception { $o->foo('42') }, undef);
ok(exception { $o->foo('bar') });

is(exception { $o->bar(['42', '23']) }, undef);
ok(exception { $o->bar(['foo', 'bar']) });