4 use MooseX::Declare::Types;
5 use MooseX::Types::Moose qw(Str Int);
6 use MooseX::Types::Structured qw(Dict Optional);
8 ## Possible interface for facets, with are a bit like roles for types. This
9 ## just a sketch, doesn't represent a lot of thought.
10 use MooseX::Types::Facets {
11 Str => [qw/ hasMinimumLength hasMaximumLength isWords matchesRegex/ ],
16 having hasMinimumLength(2),
35 parameterizes($p Parameters) {
36 having hasMaximumLength($p->length);
42 parameter total_length => (
47 parameter part_max_lengths => (
50 middle=>Optional[Int],
55 my $Namepart = subtype {
57 having isWords(maximum_words=>1),
60 parameter max_length => (
65 parameterize($p Parameters) {
66 having hasMaximumLength($p->max_length);
70 parameterize($p Parameters) {
74 max_length=>$p->part_max_lengths->{first},
78 max_length=>$p->part_max_lengths->{middle}
82 max_length=>$p->part_max_lengths->{last},
86 having hasMaximumLength($p->total_length);
91 ## MyApp/MyClass/Foo.pm
94 use MooseX::Types qw(EmailAddress);
95 use MyApp::Types qw(FullName Name);
99 with Class::DBIx::Role::Result => (
100 resultset_class => '',
107 ## fullname would have a minimum of 2 characters, a maximum of 45 and
108 ## would be composed of a maximum of 3 words separated by whitespace
112 isa=>FullName(length=>45),
115 ## name would be a HashRef with two required keys 'first' and 'last'
116 ## and a single optional key called 'middle'. each key value must be a
117 ## str composed of a single word with a minimum character length of 2
118 ## and maximum lengths of first=>35, middle=>25 and last=>50. Also the
119 ## overall total length.
133 method email($recipient Email) {
139 use aliased MyApp::MyClass::Foo;
142 fullname=>'Vanessa Li',
146 last=>'Napiorkowski',
150 my $foo_set = Foo->search( name => sub { $self->search ... });
156 coercion fixPerson($person Person) {
157 from Tuple($name Str, $age Int) {
158 $person->XXXXX(name=>$name, age=>$age);
164 my $name = "$fullname->{first} $fullname->{last}";
165 my $age = ($dob - DateTime-now)->years;
166 return $person->XXX(name=>$name, age=>$age);
173 isa=> Person->coercions(fixPerson, MorePeople),
179 as Delegate[Signature];