Remove not_implemented from the list of allowed methods
[catagits/Catalyst-Action-Serialize-Data-Serializer.git] / t / lib / Test / Rest.pm
index 01aa90a..7032cc8 100644 (file)
@@ -1,14 +1,7 @@
-#
-# Rest.pm
-# Created by: Adam Jacob, Marchex, <adam@hjksolutions.com>
-# Created on: 10/16/2006 11:11:25 AM PDT
-#
-# $Id: $
-
 package Test::Rest;
 
-use strict;
-use warnings;
+use Moose;
+use namespace::autoclean;
 
 use LWP::UserAgent;
 use Params::Validate qw(:all);
@@ -27,14 +20,21 @@ sub new {
 }
 
 {
-    my @non_data_methods = qw(GET DELETE OPTIONS);
+    my @non_data_methods = qw(HEAD GET DELETE OPTIONS);
     foreach my $method (@non_data_methods) {
         no strict 'refs';
         my $sub = lc($method);
         *$sub = sub {
             my $self = shift;
-            my %p    = validate( @_, { url => { type => SCALAR }, }, );
+            my %p = validate(
+                @_,
+                {
+                    url     => { type => SCALAR },
+                    headers => { type => HASHREF, default => {} },
+                },
+            );
             my $req  = HTTP::Request->new( "$method" => $p{'url'} );
+            $req->header( $_ => $p{headers}{$_} ) for keys %{ $p{headers} };
             $req->content_type( $self->{'content_type'} );
             return $req;
         };
@@ -51,9 +51,11 @@ sub new {
                 {
                     url  => { type => SCALAR },
                     data => 1,
+                    headers => { type => HASHREF, default => {} },
                 },
             );
             my $req = HTTP::Request->new( "$method" => $p{'url'} );
+            $req->header( $_ => $p{headers}{$_} ) for keys %{ $p{headers} };
             $req->content_type( $self->{'content_type'} );
             $req->content_length(
                 do { use bytes; length( $p{'data'} ) }