diff options
author | franck cuny <franck@lumberjaph.net> | 2010-06-08 17:44:40 +0200 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-06-08 17:45:59 +0200 |
commit | 900285cda4e4105f02789d29ea71492105a5048c (patch) | |
tree | bee6de73ab5af53c5243a5050cc447dc5444dbc3 | |
parent | add dispatcher for viewing content; update help (diff) | |
download | net-http-console-900285cda4e4105f02789d29ea71492105a5048c.tar.gz |
role to log and write
-rw-r--r-- | lib/Net/HTTP/Console.pm | 1 | ||||
-rw-r--r-- | lib/Net/HTTP/Console/Dispatcher/HTTP.pm | 8 | ||||
-rw-r--r-- | lib/Net/HTTP/Console/Dispatcher/Set.pm | 14 | ||||
-rw-r--r-- | lib/Net/HTTP/Console/Dispatcher/View.pm | 2 | ||||
-rw-r--r-- | lib/Net/HTTP/Console/Role/HTTP/Response.pm | 4 | ||||
-rw-r--r-- | lib/Net/HTTP/Console/Role/Message.pm | 18 | ||||
-rw-r--r-- | lib/Net/HTTP/Console/Role/Plugins.pm | 2 |
7 files changed, 28 insertions, 21 deletions
diff --git a/lib/Net/HTTP/Console.pm b/lib/Net/HTTP/Console.pm index eef3ba8..a1bc1dd 100644 --- a/lib/Net/HTTP/Console.pm +++ b/lib/Net/HTTP/Console.pm @@ -9,6 +9,7 @@ class Net::HTTP::Console { with 'Net::HTTP::Console::Role::Headers'; with 'Net::HTTP::Console::Role::Prompt'; with 'Net::HTTP::Console::Role::Plugins'; + with 'Net::HTTP::Console::Role::Message'; with 'Net::HTTP::Console::Role::API'; with 'Net::HTTP::Console::Role::HTTP::Response'; diff --git a/lib/Net/HTTP/Console/Dispatcher/HTTP.pm b/lib/Net/HTTP/Console/Dispatcher/HTTP.pm index c0e24ae..88f8814 100644 --- a/lib/Net/HTTP/Console/Dispatcher/HTTP.pm +++ b/lib/Net/HTTP/Console/Dispatcher/HTTP.pm @@ -21,7 +21,7 @@ class Net::HTTP::Console::Dispatcher::HTTP with Net::HTTP::Console::Dispatcher { $self->_do_request_with_body($method, $path, $body); } else { - # XXX unsupporter method + $self->application->logger('error', 'unsupported HTTP method'); } return 1; } @@ -32,7 +32,7 @@ class Net::HTTP::Console::Dispatcher::HTTP with Net::HTTP::Console::Dispatcher { my ($content, $result) = $self->application->api_object->anonymous; $self->application->_set_and_show($content, $result); }catch{ - # XXX error + $self->application->error('error', $_); }; } @@ -58,9 +58,7 @@ class Net::HTTP::Console::Dispatcher::HTTP with Net::HTTP::Console::Dispatcher { my ($content, $result) = $self->application->api_object->anonymous; $self->application->_set_and_show($content, $result); }catch{ - warn $_; - use YAML::Syck; - warn Dump $_->http_error; + $self->application->error('error', $_); }; } } diff --git a/lib/Net/HTTP/Console/Dispatcher/Set.pm b/lib/Net/HTTP/Console/Dispatcher/Set.pm index f97474b..d514f37 100644 --- a/lib/Net/HTTP/Console/Dispatcher/Set.pm +++ b/lib/Net/HTTP/Console/Dispatcher/Set.pm @@ -13,10 +13,6 @@ class Net::HTTP::Console::Dispatcher::Set with Net::HTTP::Console::Dispatcher { }elsif($command eq 'unset') { $self->_unset_header($key) if $type eq 'header'; } - - # elsif ($command eq 'show_defined_headers') { - # $self->_show_defined_headers(); - # } } method pattern($input) { @@ -25,19 +21,13 @@ class Net::HTTP::Console::Dispatcher::Set with Net::HTTP::Console::Dispatcher { method _set_header($header, $value) { $self->application->set_header($header, $value); - print "header $header set to $value\n"; + $self->application->print("header $header set to $value"); } method _unset_header($header) { $self->application->delete_header($header); - print "header $header unset\n"; + $self->application->print("header $header unset"); } - - # method _show_defined_headers { - # foreach ($self->application->all_headers) { - # print $_->[0].": ".$_->[1]."\n"; - # } - # } } 1; diff --git a/lib/Net/HTTP/Console/Dispatcher/View.pm b/lib/Net/HTTP/Console/Dispatcher/View.pm index 059fe53..5b52fc0 100644 --- a/lib/Net/HTTP/Console/Dispatcher/View.pm +++ b/lib/Net/HTTP/Console/Dispatcher/View.pm @@ -19,7 +19,7 @@ class Net::HTTP::Console::Dispatcher::View with Net::HTTP::Console::Dispatcher { } elsif ($key eq 'defined_headers') { foreach ($self->application->all_headers) { - print $_->[0] . ': ' . $_->[1] . "\n"; + $self->application->print( $_->[0] . ': ' . $_->[1]); } } } diff --git a/lib/Net/HTTP/Console/Role/HTTP/Response.pm b/lib/Net/HTTP/Console/Role/HTTP/Response.pm index 606c7de..27f6925 100644 --- a/lib/Net/HTTP/Console/Role/HTTP/Response.pm +++ b/lib/Net/HTTP/Console/Role/HTTP/Response.pm @@ -24,12 +24,12 @@ role Net::HTTP::Console::Role::HTTP::Response { ); method _show_last_content { - print $self->_last_http_content; + $self->print($self->_last_http_content); } method _show_last_headers { foreach my $k (keys %{$self->_last_http_response->headers}) { - print "$k: ".$self->_last_http_response->header($k)."\n"; + $self->print("$k: ".$self->_last_http_response->header($k)); } } diff --git a/lib/Net/HTTP/Console/Role/Message.pm b/lib/Net/HTTP/Console/Role/Message.pm new file mode 100644 index 0000000..4b3fce6 --- /dev/null +++ b/lib/Net/HTTP/Console/Role/Message.pm @@ -0,0 +1,18 @@ +package Net::HTTP::Console::Role::Message; + +use MooseX::Declare; + +role Net::HTTP::Console::Role::Message { + + # XXX colors ? + method logger($level, $message) { + print "[".uc($level)."] ".$message."\n"; + } + + method print($message) { + print $message."\n"; + } + +} + +1; diff --git a/lib/Net/HTTP/Console/Role/Plugins.pm b/lib/Net/HTTP/Console/Role/Plugins.pm index 2bddccd..8486cdb 100644 --- a/lib/Net/HTTP/Console/Role/Plugins.pm +++ b/lib/Net/HTTP/Console/Role/Plugins.pm @@ -43,7 +43,7 @@ role Net::HTTP::Console::Role::Plugins { last if ($result = $_->dispatch($input)); } }catch{ - print "[ERROR]: ".$_; + $self->application->logger('error', $_); }; } } |