merge trunk to pluggable errors
[gitmo/Moose.git] / t / 000_recipes / basics / 005_coercion.t
similarity index 62%
rename from t/000_recipes/005_coercion.t
rename to t/000_recipes/basics/005_coercion.t
index 7ea0371..7643abf 100644 (file)
@@ -8,61 +8,45 @@ use Test::More;
 BEGIN {
     eval "use HTTP::Headers; use Params::Coerce; use URI;";
     plan skip_all => "HTTP::Headers & Params::Coerce & URI required for this test" if $@;        
-    plan tests => 18;    
+    plan tests => 17;    
 }
 
 use Test::Exception;
 
-BEGIN {
-    use_ok('Moose');           
-}
-
 {
-       package Request;
-       use Moose;
+    package Request;
+    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 } 
+
+    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 }
     );
-    
-    __PACKAGE__->meta->make_immutable(debug => 0);
+
+    __PACKAGE__->meta->make_immutable( debug => 0 );
 }
 
 my $r = Request->new;