Commit | Line | Data |
471c4f09 |
1 | |
2 | =pod |
3 | |
4 | =head1 NAME |
5 | |
6 | Moose::Cookbook::Recipe5 |
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 | |
56 | =head1 AUTHOR |
57 | |
58 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
59 | |
60 | =head1 COPYRIGHT AND LICENSE |
61 | |
62 | Copyright 2006 by Infinity Interactive, Inc. |
63 | |
64 | L<http://www.iinteractive.com> |
65 | |
66 | This library is free software; you can redistribute it and/or modify |
67 | it under the same terms as Perl itself. |
68 | |
69 | =cut |