Skip to content

Commit

Permalink
improved debug messages to show more details
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 11, 2012
1 parent a52ba18 commit 400dd78
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions lib/Mojo/EventEmitter.pm
Expand Up @@ -15,18 +15,18 @@ use constant DEBUG => $ENV{MOJO_EVENTEMITTER_DEBUG} || 0;
sub emit {
my ($self, $name) = (shift, shift);
if (my $s = $self->{events}->{$name}) {
warn '-- Emit ', blessed($self), " $name (", scalar(@$s), ")\n" if DEBUG;
warn "-- Emit @{[blessed($self)]} $name (@{[scalar(@$s)]})\n" if DEBUG;
for my $cb (@$s) { $self->$cb(@_) }
}
elsif (DEBUG) { warn '-- Emit ', blessed($self), " $name (0)\n" }
elsif (DEBUG) { warn "-- Emit @{[blessed($self)]} $name (0)\n" }
return $self;
}

sub emit_safe {
my ($self, $name) = (shift, shift);

if (my $s = $self->{events}->{$name}) {
warn '-- Safe ', blessed($self), " $name (", scalar(@$s), ")\n" if DEBUG;
warn "-- Safe @{[blessed($self)]} $name (@{[scalar(@$s)]})\n" if DEBUG;
for my $cb (@$s) {
if (!eval { $self->$cb(@_); 1 } && $name ne 'error') {
$self->once(error => sub { warn $_[1] })
Expand All @@ -35,7 +35,7 @@ sub emit_safe {
}
}
}
elsif (DEBUG) { warn '-- Safe ', blessed($self), " $name (0)\n" }
elsif (DEBUG) { warn "-- Safe @{[blessed($self)]} $name (0)\n" }

return $self;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -245,13 +245,13 @@ sub _listen {

sub _read {
my ($self, $id, $chunk) = @_;
warn "-- Server <<< Client\n$chunk\n" if DEBUG;

# Make sure we have a transaction
my $c = $self->{connections}->{$id};
my $tx = $c->{tx} ||= $self->_build_tx($id, $c);

# Parse chunk
warn "-- Server <<< Client (@{[$tx->req->url->to_abs]})\n$chunk\n" if DEBUG;
$tx->server_read($chunk);

# Last keep alive request
Expand Down Expand Up @@ -293,7 +293,7 @@ sub _write {
return if $c->{writing}++;
my $chunk = $tx->server_write;
delete $c->{writing};
warn "-- Server >>> Client\n$chunk\n" if DEBUG;
warn "-- Server >>> Client (@{[$tx->req->url->to_abs]})\n$chunk\n" if DEBUG;

# Write
my $stream = $self->ioloop->stream($id);
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -100,7 +100,7 @@ sub start {
if ($cb) {

# Start non-blocking
warn "-- New non-blocking request\n" if DEBUG;
warn "-- Non-blocking request (@{[$tx->req->url->to_abs]})\n" if DEBUG;
unless ($self->{nb}) {
croak 'Blocking request in progress' if keys %{$self->{connections}};
warn "-- Switching to non-blocking mode\n" if DEBUG;
Expand All @@ -111,7 +111,7 @@ sub start {
}

# Start blocking
warn "-- New blocking request\n" if DEBUG;
warn "-- Blocking request (@{[$tx->req->url->to_abs]})\n" if DEBUG;
if (delete $self->{nb}) {
croak 'Non-blocking requests in progress' if keys %{$self->{connections}};
warn "-- Switching to blocking mode\n" if DEBUG;
Expand Down Expand Up @@ -380,13 +380,13 @@ sub _loop {

sub _read {
my ($self, $id, $chunk) = @_;
warn "-- Client <<< Server\n$chunk\n" if DEBUG;

# Corrupted connection
return unless my $c = $self->{connections}->{$id};
return $self->_remove($id) unless my $tx = $c->{tx};

# Process incoming data
warn "-- Client <<< Server (@{[$tx->req->url->to_abs]})\n$chunk\n" if DEBUG;
$tx->client_read($chunk);
if ($tx->is_finished) { $self->_handle($id) }
elsif ($c->{tx}->is_writing) { $self->_write($id) }
Expand Down Expand Up @@ -521,7 +521,7 @@ sub _write {
return if $self->{writing}++;
my $chunk = $tx->client_write;
delete $self->{writing};
warn "-- Client >>> Server\n$chunk\n" if DEBUG;
warn "-- Client >>> Server (@{[$tx->req->url->to_abs]})\n$chunk\n" if DEBUG;

# More data to follow
my $cb;
Expand Down

0 comments on commit 400dd78

Please sign in to comment.