From 13c0b93c7cca4288f64064136f13ee6bedb1f4ea Mon Sep 17 00:00:00 2001
From: Alexander Hartmaier <abraxxa@cpan.org>
Date: Mon, 24 Oct 2016 20:09:21 +0200
Subject: [PATCH 1/2] add failing test case for RT#118413
---
t/rest.t | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/t/rest.t b/t/rest.t
index 4b4d166..dd16dcd 100644
--- a/t/rest.t
+++ b/t/rest.t
@@ -51,6 +51,18 @@ my %testdata = (
user_agent => $ua,
persistent_headers => $persistent_headers,
);
+{
+ ok(my $client = RESTExample->new({
+ server => '
http://localhost:3000',
+ type => 'application/json',
+ }), 'New object');
+ is($client->has_no_headers, 1, 'client has no headers');
+ #is_deeply($client->httpheaders, {}, 'client has no headers');
+ $client->set_persistent_header('X-Test' => 'foo' );
+ is_deeply($client->httpheaders, { 'X-Test' => 'foo' },
+ 'should have at least persistent_headers');
+
+}
ok(my $obj = RESTExample->new(%testdata), 'New object');
isa_ok($obj, 'RESTExample');
--
2.9.3
From 64564b870635d322ad1a48c13e324f66c1e46bd9 Mon Sep 17 00:00:00 2001
From: Alexander Hartmaier <abraxxa@cpan.org>
Date: Mon, 24 Oct 2016 20:09:37 +0200
Subject: [PATCH 2/2] proposed patch for RT#118413
---
lib/Role/REST/Client.pm | 30 +++++++++++-------------------
1 file changed, 11 insertions(+), 19 deletions(-)
diff --git a/lib/Role/REST/Client.pm b/lib/Role/REST/Client.pm
index 4d5faf7..f84d3c8 100644
--- a/lib/Role/REST/Client.pm
+++ b/lib/Role/REST/Client.pm
@@ -47,16 +47,9 @@ sub _build_user_agent {
}
has persistent_headers => (
- is => 'lazy',
+ is => 'rw',
# isa => HashRef[Str],
default => sub { {} },
- trigger => sub {
- my ( $self, $header, $old_header ) = @_;
- # Update httpheaders if their value was initialized first
- while (my ($key, $value) = each %$header) {
- $self->set_header($key, $value) unless $self->exist_header($key);
- }
- },
handles_via => 'Hash',
handles => {
set_persistent_header => 'set',
@@ -66,10 +59,11 @@ has persistent_headers => (
},
);
-has httpheaders => (
- is => 'lazy',
+has _httpheaders => (
+ is => 'rw',
isa => HashRef[Str],
- writer => '_set_httpheaders',
+ init_arg => 'httpheaders',
+ default => sub { {} },
handles_via => 'Hash',
handles => {
set_header => 'set',
@@ -77,9 +71,15 @@ has httpheaders => (
exist_header => 'exists',
has_no_headers => 'is_empty',
clear_headers => 'clear',
+ reset_headers => 'clear',
},
);
+sub httpheaders {
+ my $self = shift;
+ return { %{$self->persistent_headers}, %{$self->_httpheaders} };
+}
+
has serializer_class => (
isa => Str,
is => 'ro',
@@ -92,14 +92,6 @@ has serializer_options => (
default => sub { return {} },
);
-sub _build_httpheaders {
- my ($self, $headers) = @_;
- $headers ||= {};
- $self->_set_httpheaders( { %{$self->persistent_headers}, %$headers });
-}
-
-sub reset_headers {my $self = shift;$self->_set_httpheaders({ %{$self->persistent_headers} })}
-
sub _rest_response_class { 'Role::REST::Client::Response' }
# If the response is a hashref, we expect it to be in the format returned by
--
2.9.3