Skip to content

Commit

Permalink
Refactor RT#62397 patch to much shorter code.
Browse files Browse the repository at this point in the history
The code is now much shorter, even than the 1.00 code.
  • Loading branch information
dolmen committed Oct 27, 2010
1 parent 2681ab1 commit 1d4bf89
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions lib/POE/Component/Logger.pm
Expand Up @@ -17,7 +17,9 @@ sub spawn {
_start => \&_start_logger,
_stop => \&_stop_logger,

# Log at the $DefaultLevel
log => sub { my @args = @_; $args[STATE] = $DefaultLevel; _poe_log(@args) },
# Log at a specific level
debug => \&_poe_log,
info => \&_poe_log,
notice => \&_poe_log,
Expand Down Expand Up @@ -50,28 +52,19 @@ sub _stop_logger {
delete $heap->{_logger};
}

# Convert arguments into a HASHREf or arguments for Log::Dispatch
sub _expand_args
{
my $level = shift;
my $arg0 = $_[0];

if (ref $arg0) {
$arg0->{level} = $level unless exists $arg0->{level};
return %{$arg0};
} else {
return (
level => $level,
message => join('', @_),
);
}
}

# Private log method that calls Log::Dispatch
sub _poe_log {
my ($heap, $level, @args) = @_[HEAP, STATE, ARG0..$#_];
my $logger = $heap->{_logger};
$logger->log(_expand_args($level, @args));
my ($heap, $level, $arg0, @args) = @_[HEAP, STATE, ARG0..$#_];

$heap->{_logger}->log(
# The default level is the POE event name ($_[STATE])
# (may be overriden in given hashref)
level => $level,
# If we get a HASHREF, expand it
# If we get a scalar, concatenate args as the message
(ref $arg0) ? (%{$arg0})
: (message => join('', $arg0, @args))
);
}


Expand Down

0 comments on commit 1d4bf89

Please sign in to comment.