
=pod

=head1 NAME

Moose::Cookbook::Recipe5 - More subtypes, coercion in a B<Request> class

=head1 SYNOPSIS

  package Request;
  use strict;
  use warnings;
  use Moose;
  use Moose::Util::TypeConstraints;
  
  use HTTP::Headers  ();
  use Params::Coerce ();
  use URI            ();
  
  subtype Header
      => as Object
      => where { $_->isa('HTTP::Headers') };
  
  coerce Header
      => from ArrayRef
          => via { HTTP::Headers->new( @{ $_ } ) }
      => from HashRef
          => via { HTTP::Headers->new( %{ $_ } ) };
  
  subtype Uri
      => as Object
      => where { $_->isa('URI') };
  
  coerce Uri
      => from Object
          => via { $_->isa('URI') ? $_ : Params::Coerce::coerce( 'URI', $_ ) }
      => from Str
          => via { URI->new( $_, 'http' ) };
  
  subtype Protocol
      => as Str
      => where { /^HTTP\/[0-9]\.[0-9]$/ };
  
  has 'base'     => (is => 'rw', isa => 'Uri', coerce  => 1);
  has 'url'      => (is => 'rw', isa => 'Uri', coerce  => 1);	
  has 'method'   => (is => 'rw', isa => 'Str');	
  has 'protocol' => (is => 'rw', isa => 'Protocol');		
  has 'headers'  => (
      is      => 'rw',
      isa     => 'Header',
      coerce  => 1,
      default => sub { HTTP::Headers->new } 
  );

=head1 DESCRIPTION

Coming Soon. 

(the other 4 recipes kinda burned me out a bit)

=head1 AUTHOR

Stevan Little E<lt>stevan@iinteractive.comE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright 2006 by Infinity Interactive, Inc.

L<http://www.iinteractive.com>

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut