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 | |
43 | |
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 | |
57 | =head1 AUTHOR |
58 | |
59 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
60 | |
61 | =head1 COPYRIGHT AND LICENSE |
62 | |
63 | Copyright 2006 by Infinity Interactive, Inc. |
64 | |
65 | L<http://www.iinteractive.com> |
66 | |
67 | This library is free software; you can redistribute it and/or modify |
68 | it under the same terms as Perl itself. |
69 | |
70 | =cut |