cookbook
[gitmo/Moose.git] / lib / Moose / Cookbook / Recipe5.pod
diff --git a/lib/Moose/Cookbook/Recipe5.pod b/lib/Moose/Cookbook/Recipe5.pod
new file mode 100644 (file)
index 0000000..6bc325d
--- /dev/null
@@ -0,0 +1,70 @@
+
+=pod
+
+=head1 NAME
+
+Moose::Cookbook::Recipe5
+
+=head1 SYNOPSIS
+
+  package Request;
+  use strict;
+  use warnings;
+  use Moose;
+  
+  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
+
+=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
\ No newline at end of file