summary refs log tree commit diff
path: root/lib/Net/HTTP/Console/Role/HTTP.pm
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-06-06 16:52:32 +0200
committerfranck cuny <franck@lumberjaph.net>2010-06-06 16:52:32 +0200
commit6754c25c01c202ff788ffba6265d98b4b75f4db4 (patch)
tree8ec3b04963a14462a51479555381cdec361f5f43 /lib/Net/HTTP/Console/Role/HTTP.pm
downloadnet-http-console-6754c25c01c202ff788ffba6265d98b4b75f4db4.tar.gz
initial commit
Diffstat (limited to 'lib/Net/HTTP/Console/Role/HTTP.pm')
-rw-r--r--lib/Net/HTTP/Console/Role/HTTP.pm42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/Net/HTTP/Console/Role/HTTP.pm b/lib/Net/HTTP/Console/Role/HTTP.pm
new file mode 100644
index 0000000..d0bd2c8
--- /dev/null
+++ b/lib/Net/HTTP/Console/Role/HTTP.pm
@@ -0,0 +1,42 @@
+package Net::HTTP::Console::Role::HTTP;
+
+use Moose::Role;
+
+has _last_http_response => (
+    is      => 'rw',
+    isa     => 'Object',
+    clearer => '_clear_last_http_response',
+);
+has _last_http_content => (
+    is      => 'rw',
+    isa     => 'Str',
+    clearer => '_clear_last_http_content',
+);
+has _json => (
+    is      => 'rw',
+    isa     => 'Object',
+    lazy    => 1,
+    default => sub { JSON->new; },
+);
+
+sub _show_last_content {
+    my $self = shift;
+    print $self->_last_http_content;
+}
+
+sub _show_last_headers {
+    my $self = shift;
+    foreach my $k (keys %{$self->_last_http_response->headers}) {
+        print "$k: ".$self->_last_http_response->header($k)."\n";
+    }
+}
+
+sub _set_and_show {
+    my ($self, $content, $response) = @_;
+    my $json = $self->_json->pretty->encode($content);
+    $self->_last_http_content($json);
+    $self->_last_http_response($response);
+    $self->_show_last_content;
+}
+
+1;