File: constraint.t

package info (click to toggle)
libmoosex-attributeshortcuts-perl 0.024-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 312 kB
  • ctags: 9
  • sloc: perl: 326; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,061 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
44
45
46
47
48
49
50
51
use strict;
use warnings;

# test our new constraint option
#
# this test is perhaps a bit redundnant, given t/inline_*.t, but it's kinda
# where I'd like to see it go when Test::Moose::More is retrofitted with
# isa/type_constraint checking support.

use Test::More;
use Test::Moose::More;
use Moose::Util;
use Moose::Util::TypeConstraints;

my $shortcuts;

{
    package TestClass;

    use Moose;
    use namespace::autoclean;
    use MooseX::AttributeShortcuts;

    $shortcuts = Shortcuts;

    has foo => (
        is         => 'rw',
        isa        => 'Str',
        constraint => sub { /^Hi/ },
    );

}

my $tc =
    Moose::Util::TypeConstraints::find_or_create_isa_type_constraint('Str')
    ->create_child_type(constraint => sub { /^Hi/ })
    ;

validate_class TestClass => (
    attributes => [
        foo => {
            -does           => [ $shortcuts ],
            accessor        => 'foo',
            original_isa    => 'Str',
            type_constraint => $tc,
            isa             => $tc,
        },
    ],
);

done_testing;