Commit | Line | Data |
cbac5987 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | |
6 | { |
7 | package Test::MyMooseClass; |
8 | |
9 | use Moose; |
10 | use MooseX::Types::Parameterizable qw(Parameterizable); |
11 | use MooseX::Types::Moose qw(Str Int); |
12 | use MooseX::Types -declare=>[qw(Varchar)]; |
13 | |
14 | ## Minor change from docs to avoid additional test dependencies |
15 | subtype Varchar, |
16 | as Parameterizable[Str,Int], |
17 | where { |
18 | my($string, $int) = @_; |
19 | $int >= length($string) ? 1:0; |
20 | }; |
21 | |
37821564 |
22 | has short_string => ( is => 'rw', isa => Varchar[5] ); |
cbac5987 |
23 | } |
24 | |
25 | my $obj = Test::MyMooseClass->new(short_string => 'four'); |
26 | |
27 | is $obj->short_string, 'four', 'attribute stored correctly'; |
28 | |
29 | # this should die |
30 | eval { $obj->short_string('longer') }; |
31 | |
32 | like $@, qr/Attribute \(short_string\) does not pass the type constraint/, 'fails on longer string with correct error message'; |
33 | |
34 | done_testing; |