From: Arthur Axel 'fREW' Schmidt Date: Tue, 14 Sep 2010 19:31:53 +0000 (-0500) Subject: better import arg munging for more import options X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1e9144f02ccd03b8b7742f1d2c0ce38c16bc1fbe;p=p5sagit%2FLog-Contextual.git better import arg munging for more import options --- diff --git a/lib/Log/Contextual.pm b/lib/Log/Contextual.pm index 3b6e4ea..550804f 100644 --- a/lib/Log/Contextual.pm +++ b/lib/Log/Contextual.pm @@ -36,23 +36,36 @@ our %EXPORT_TAGS = ( sub import { my $package = shift; - die 'Log::Contextual does not have a default import list' - unless @_; + my $skipnext; + my @rest; for my $idx ( 0 .. $#_ ) { + if ($skipnext) { + $skipnext--; + next; + } + my $val = $_[$idx]; - if ( defined $val && $val eq '-logger' ) { + if (!defined $val) { + next; + } elsif ( $val eq '-logger' ) { set_logger($_[$idx + 1]); - splice @_, $idx, 2; - } elsif ( defined $val && $val eq '-package_logger' ) { + $skipnext = 1; + } elsif ( $val eq '-package_logger' ) { _set_package_logger_for(scalar caller, $_[$idx + 1]); - splice @_, $idx, 2; - } elsif ( defined $val && $val eq '-default_logger' ) { + $skipnext = 1; + } elsif ( $val eq '-default_logger' ) { _set_default_logger_for(scalar caller, $_[$idx + 1]); - splice @_, $idx, 2; + $skipnext = 1; + } else { + push @rest, $val; } } - $package->export_to_level(1, $package, @_); + + die 'Log::Contextual does not have a default import list' + unless @rest; + + $package->export_to_level(1, $package, @rest); } our $Get_Logger;