Permalink
Browse files

Refactor RT#62397 patch to much shorter code.

The code is now much shorter, even than the 1.00 code.
  • Loading branch information...
1 parent 2681ab1 commit 1d4bf890117e03fb72ad1c598b1f9055ce23f5e6 @dolmen committed Oct 26, 2010
Showing with 13 additions and 20 deletions.
  1. +13 −20 lib/POE/Component/Logger.pm
@@ -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,
@@ -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))
+ );
}

0 comments on commit 1d4bf89

Please sign in to comment.