0_03_01
[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;
14
15 use HTTP::Headers ();
16 use Params::Coerce ();
17 use URI ();
18
19 subtype Header
20 => as Object
21 => where { $_->isa('HTTP::Headers') };
22
23 coerce Header
24 => from ArrayRef
25 => via { HTTP::Headers->new( @{ $_ } ) }
26 => from HashRef
27 => via { HTTP::Headers->new( %{ $_ } ) };
28
29 subtype Uri
30 => as Object
31 => where { $_->isa('URI') };
32
33 coerce Uri
34 => from Object
35 => via { $_->isa('URI') ? $_ : Params::Coerce::coerce( 'URI', $_ ) }
36 => from Str
37 => via { URI->new( $_, 'http' ) };
38
39 subtype Protocol
40 => as Str
41 => where { /^HTTP\/[0-9]\.[0-9]$/ };
42
471c4f09 43 has 'base' => (is => 'rw', isa => 'Uri', coerce => 1);
44 has 'url' => (is => 'rw', isa => 'Uri', coerce => 1);
45 has 'method' => (is => 'rw', isa => 'Str');
46 has 'protocol' => (is => 'rw', isa => 'Protocol');
47 has 'headers' => (
48 is => 'rw',
49 isa => 'Header',
50 coerce => 1,
51 default => sub { HTTP::Headers->new }
52 );
53
54=head1 DESCRIPTION
55
9deed647 56Coming Soon.
57
58(the other 4 recipes kinda burned me out a bit)
3824830b 59
471c4f09 60=head1 AUTHOR
61
62Stevan Little E<lt>stevan@iinteractive.comE<gt>
63
64=head1 COPYRIGHT AND LICENSE
65
66Copyright 2006 by Infinity Interactive, Inc.
67
68L<http://www.iinteractive.com>
69
70This library is free software; you can redistribute it and/or modify
71it under the same terms as Perl itself.
72
73=cut