diff options
author | franck cuny <franck@lumberjaph.net> | 2010-10-26 17:35:08 +0200 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-10-26 17:35:08 +0200 |
commit | 2389782526e6c35589bb4d9bbadea78559ac1eda (patch) | |
tree | 89ab004cc9edfb2a76ec60ebd14f1c973b6e0c5b | |
parent | add expected_status to top level (diff) | |
download | net-http-spore-2389782526e6c35589bb4d9bbadea78559ac1eda.tar.gz |
add role to trace
-rw-r--r-- | lib/Net/HTTP/Spore/Meta.pm | 1 | ||||
-rw-r--r-- | lib/Net/HTTP/Spore/Meta/Class.pm | 2 | ||||
-rw-r--r-- | lib/Net/HTTP/Spore/Meta/Method/Spore.pm | 6 | ||||
-rw-r--r-- | lib/Net/HTTP/Spore/Role/Debug.pm | 14 | ||||
-rw-r--r-- | lib/Net/HTTP/Spore/Role/Request.pm | 7 |
5 files changed, 28 insertions, 2 deletions
diff --git a/lib/Net/HTTP/Spore/Meta.pm b/lib/Net/HTTP/Spore/Meta.pm index ec773b6..14b4266 100644 --- a/lib/Net/HTTP/Spore/Meta.pm +++ b/lib/Net/HTTP/Spore/Meta.pm @@ -36,6 +36,7 @@ sub init_meta { for => $for, roles => [ qw/ + Net::HTTP::Spore::Role::Debug Net::HTTP::Spore::Role::Description Net::HTTP::Spore::Role::UserAgent Net::HTTP::Spore::Role::Request diff --git a/lib/Net/HTTP/Spore/Meta/Class.pm b/lib/Net/HTTP/Spore/Meta/Class.pm index 4ddd5c6..7571305 100644 --- a/lib/Net/HTTP/Spore/Meta/Class.pm +++ b/lib/Net/HTTP/Spore/Meta/Class.pm @@ -4,7 +4,7 @@ package Net::HTTP::Spore::Meta::Class; use Moose::Role; -with qw/Net::HTTP::Spore::Meta::Method::Spore/; +with qw/Net::HTTP::Spore::Meta::Method::Spore Net::HTTP::Spore::Role::Debug/; 1; diff --git a/lib/Net/HTTP/Spore/Meta/Method/Spore.pm b/lib/Net/HTTP/Spore/Meta/Method/Spore.pm index 1cea574..a616149 100644 --- a/lib/Net/HTTP/Spore/Meta/Method/Spore.pm +++ b/lib/Net/HTTP/Spore/Meta/Method/Spore.pm @@ -54,6 +54,12 @@ sub add_spore_method { my $code = delete $options{code}; + $meta->_trace_msg( '-> attach ' + . $name . ' (' + . $options{method} . ' => ' + . $options{path} + . ')' ); + $meta->add_method( $name, Net::HTTP::Spore::Meta::Method->wrap( diff --git a/lib/Net/HTTP/Spore/Role/Debug.pm b/lib/Net/HTTP/Spore/Role/Debug.pm new file mode 100644 index 0000000..772373a --- /dev/null +++ b/lib/Net/HTTP/Spore/Role/Debug.pm @@ -0,0 +1,14 @@ +package Net::HTTP::Spore::Role::Debug; + +use Moose::Role; + +has trace => ( + is => 'rw', + isa => 'Bool', + lazy => 1, + default => sub { $ENV{SPORE_TRACE} ? 1 : 0; } +); + +sub _trace_msg { print STDOUT $_[1]."\n" if $_[0]->trace; } + +1; diff --git a/lib/Net/HTTP/Spore/Role/Request.pm b/lib/Net/HTTP/Spore/Role/Request.pm index ddd52e6..7fbb290 100644 --- a/lib/Net/HTTP/Spore/Role/Request.pm +++ b/lib/Net/HTTP/Spore/Role/Request.pm @@ -38,7 +38,10 @@ sub http_request { return $response; } - my $result = $self->request($request->finalize); + my $final = $request->finalize; + $self->_trace_msg("<- ".$request->method. " => ".$request->uri); + + my $result = $self->request($final); $response = $request->new_response( $result->code, @@ -46,6 +49,8 @@ sub http_request { $result->content, ); + $self->_trace_msg("<- HTTP Status".$result->code ); + map { $_->($response) } reverse @middlewares; $response; |