diff options
author | franck cuny <franck@lumberjaph.net> | 2011-07-22 13:52:46 +0200 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2011-07-26 13:21:02 +0200 |
commit | 0ec2c43ec73e5354bd91209ed52a66c993c7cf9f (patch) | |
tree | 8fc76332362dfebb68154d58c772aa2277ee6dd7 | |
parent | debug string if defined (diff) | |
download | net-http-spore-0ec2c43ec73e5354bd91209ed52a66c993c7cf9f.tar.gz |
fix bug with trace set to 0
Signed-off-by: franck cuny <franck@lumberjaph.net>
-rw-r--r-- | lib/Net/HTTP/Spore/Role/Debug.pm | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/Net/HTTP/Spore/Role/Debug.pm b/lib/Net/HTTP/Spore/Role/Debug.pm index 3989293..18f3412 100644 --- a/lib/Net/HTTP/Spore/Role/Debug.pm +++ b/lib/Net/HTTP/Spore/Role/Debug.pm @@ -7,6 +7,7 @@ has trace => ( is => 'rw', isa => 'Str', predicate => 'has_trace', + clearer => 'reset_trace', ); has _trace_fh => ( @@ -16,8 +17,15 @@ has _trace_fh => ( sub BUILD { my ($self, $args) = @_; - my $trace = $ENV{SPORE_TRACE} || $args->{trace}; - return unless defined $trace; + my $trace; + + $trace = $args->{trace} && $args->{trace} > 0 ? $args->{trace} : undef; + $trace = $ENV{SPORE_TRACE} if defined $ENV{SPORE_TRACE}; + + if (!defined $trace){ + $self->reset_trace; + return; + } my ($level, $fh); if ( $trace =~ /(\d)=(.+)$/ ) { @@ -40,6 +48,7 @@ sub _trace_msg { my $self = shift; my $template = shift; return unless $self->has_trace; + my $fh = $self->_trace_fh(); print $fh (sprintf( $template, @_ )."\n"); } |