Make restarters immutable handling less naive + tests
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Test.pm
index 9791b24..2535f76 100644 (file)
@@ -2,14 +2,14 @@ package Catalyst::Test;
 
 use strict;
 use warnings;
-use Test::More;
+use Test::More ();
 
 use Catalyst::Exception;
 use Catalyst::Utils;
 use Class::MOP;
 use Sub::Exporter;
 
-sub build_exports {
+my $build_exports = sub {
     my ($self, $meth, $args, $defaults) = @_;
 
     my $request;
@@ -55,14 +55,13 @@ sub build_exports {
             return Test::More->builder->is_eq(scalar($res->content_type),@_);
         },
     };
-}
+};
 
-use namespace::clean;
 our $default_host;
 
 {
     my $import = Sub::Exporter::build_exporter({
-        groups => [ all => \&build_exports ],
+        groups => [ all => $build_exports ],
         into_level => 1,
     });
 
@@ -70,7 +69,7 @@ our $default_host;
     sub import {
         my ($self, $class, $opts) = @_;
         $import->($self, '-all' => { class => $class });
-        $opts ||= {};
+        $opts = {} unless ref $opts eq 'HASH';
         $default_host = $opts->{default_host} if exists $opts->{default_host};
     }
 }
@@ -255,6 +254,7 @@ sub remote_request {
 sub _customize_request {
     my $request = shift;
     my $opts = pop(@_) || {};
+    $opts = {} unless ref($opts) eq 'HASH';
     if ( my $host = exists $opts->{host} ? $opts->{host} : $default_host  ) {
         $request->header( 'Host' => $host );
     }