updatin
[gitmo/Moose.git] / lib / Moose / Cookbook / Recipe5.pod
CommitLineData
471c4f09 1
2=pod
3
4=head1 NAME
5
3824830b 6Moose::Cookbook::Recipe5 - More subtypes, coercion in a B<Request> class
471c4f09 7
8=head1 SYNOPSIS
9
10 package Request;
11 use strict;
12 use warnings;
13 use Moose;
05d9eaf6 14 use Moose::Util::TypeConstraints;
471c4f09 15
16 use HTTP::Headers ();
17 use Params::Coerce ();
18 use URI ();
19
20 subtype Header
21 => as Object
22 => where { $_->isa('HTTP::Headers') };
23
24 coerce Header
25 => from ArrayRef
26 => via { HTTP::Headers->new( @{ $_ } ) }
27 => from HashRef
28 => via { HTTP::Headers->new( %{ $_ } ) };
29
30 subtype Uri
31 => as Object
32 => where { $_->isa('URI') };
33
34 coerce Uri
35 => from Object
36 => via { $_->isa('URI') ? $_ : Params::Coerce::coerce( 'URI', $_ ) }
37 => from Str
38 => via { URI->new( $_, 'http' ) };
39
40 subtype Protocol
41 => as Str
42 => where { /^HTTP\/[0-9]\.[0-9]$/ };
43
471c4f09 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');
48 has 'headers' => (
49 is => 'rw',
50 isa => 'Header',
51 coerce => 1,
52 default => sub { HTTP::Headers->new }
53 );
54
55=head1 DESCRIPTION
56
9deed647 57Coming Soon.
58
59(the other 4 recipes kinda burned me out a bit)
3824830b 60
471c4f09 61=head1 AUTHOR
62
63Stevan Little E<lt>stevan@iinteractive.comE<gt>
64
65=head1 COPYRIGHT AND LICENSE
66
67Copyright 2006 by Infinity Interactive, Inc.
68
69L<http://www.iinteractive.com>
70
71This library is free software; you can redistribute it and/or modify
72it under the same terms as Perl itself.
73
74=cut