Stevan Little > Moose-0.05 > Moose::Cookbook::Recipe5

Download:
Moose-0.05.tar.gz

Annotate this POD

CPAN RT

New  4
Open  11
View Bugs
Report a bug
Source   Latest Release: Moose-0.54

NAME ^

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

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 } 
  );

DESCRIPTION ^

Coming Soon.

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

AUTHOR ^

Stevan Little <stevan@iinteractive.com>

COPYRIGHT AND LICENSE ^

Copyright 2006 by Infinity Interactive, Inc.

http://www.iinteractive.com

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