MooseX-TypeLibrary with tests and first pod (phaylon)
[gitmo/MooseX-Types.git] / t / lib / TestLibrary.pm
1 package TestLibrary;
2 use warnings;
3 use strict;
4
5 use MooseX::TypeLibrary::Moose qw( Str ArrayRef Int );
6 use MooseX::TypeLibrary
7     -declare => [qw( NonEmptyStr IntArrayRef TwentyThree )];
8
9 subtype NonEmptyStr,
10     as Str,
11     where { length $_ },
12     message { 'Str must not be empty' };
13
14 coerce NonEmptyStr,
15     from Int,
16         via { "$_" };
17
18 subtype IntArrayRef,
19     as ArrayRef,
20     where { not grep { $_ !~ /^\d+$/ } @$_ },
21     message { 'ArrayRef contains non-Int value' };
22
23 coerce IntArrayRef,
24     from Int,
25         via { [$_] };
26
27 subtype TwentyThree,
28     as Int,
29     where { $_ == 23 },
30     message { 'Int is not 23' };
31
32 1;