6 Moose::Cookbook::Recipe5 - More subtypes, coercion in a B<Request> class
14 use Moose::Util::TypeConstraints;
17 use Params::Coerce ();
22 => where { $_->isa('HTTP::Headers') };
26 => via { HTTP::Headers->new( @{ $_ } ) }
28 => via { HTTP::Headers->new( %{ $_ } ) };
32 => where { $_->isa('URI') };
36 => via { $_->isa('URI') ? $_ : Params::Coerce::coerce( 'URI', $_ ) }
38 => via { URI->new( $_, 'http' ) };
42 => where { /^HTTP\/[0-9]\.[0-9]$/ };
44 has 'base' => (is => 'rw', isa => 'Uri', coerce => 1);
45 has 'url' => (is => 'rw', isa => 'Uri', coerce => 1);
46 has 'method' => (is => 'rw', isa => 'Str');
47 has 'protocol' => (is => 'rw', isa => 'Protocol');
52 default => sub { HTTP::Headers->new }
59 (the other 4 recipes kinda burned me out a bit)
63 Stevan Little E<lt>stevan@iinteractive.comE<gt>
65 =head1 COPYRIGHT AND LICENSE
67 Copyright 2006 by Infinity Interactive, Inc.
69 L<http://www.iinteractive.com>
71 This library is free software; you can redistribute it and/or modify
72 it under the same terms as Perl itself.