From: Arthur Axel 'fREW' Schmidt Date: Sat, 20 Feb 2010 06:54:08 +0000 (-0600) Subject: remove sugar and turn it into a tag X-Git-Tag: v0.00100~28 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f11f9542711c651746cf31e1ef1ccad0b5c52eb6;p=p5sagit%2FLog-Contextual.git remove sugar and turn it into a tag die without imports --- diff --git a/lib/Log/Contextual.pm b/lib/Log/Contextual.pm index 251c44d..9915155 100644 --- a/lib/Log/Contextual.pm +++ b/lib/Log/Contextual.pm @@ -5,10 +5,43 @@ use 5.006; $VERSION = '1.000'; require Exporter; +use Data::Dumper::Concise; BEGIN { @ISA = qw(Exporter) } -@EXPORT = qw(set_logger log_debug with_logger); +my @dlog = (qw{ + Dlog_debug DlogS_debug + Dlog_trace DlogS_trace + Dlog_warn DlogS_warn + Dlog_info DlogS_info + Dlog_error DlogS_error + Dlog_fatal DlogS_fatal +}); + +my @log = (qw{ + log_debug + log_trace + log_warn + log_info + log_error + log_fatal +}); + +@EXPORT_OK = ( + @dlog, @log, + qw{set_logger with_logger} +); + +%EXPORT_TAGS = ( + dlog => \@dlog, + log => \@log, +); + +sub import { + die 'Log::Contextual does not have a default import list' + if @_ == 1; + __PACKAGE__->export_to_level(1, shift, @_); +} our $Get_Logger; @@ -60,6 +93,116 @@ sub log_fatal (&) { if $log->is_fatal; } + + +sub Dlog_trace (&@) { + my $code = shift; + my @values = @_; + log_trace { + do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + }; + @values +} + +sub DlogS_trace (&$) { + my $code = $_[0]; + my $value = $_[1]; + log_trace { + do { local $_ = Data::Dumper::Concise::Dumper $value; $code->() }; + }; + $value +} + +sub Dlog_debug (&@) { + my $code = shift; + my @values = @_; + log_debug { + do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + }; + @values +} + +sub DlogS_debug (&$) { + my $code = $_[0]; + my $value = $_[1]; + log_debug { + do { local $_ = Data::Dumper::Concise::Dumper $value; $code->() }; + }; + $value +} + +sub Dlog_info (&@) { + my $code = shift; + my @values = @_; + log_info { + do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + }; + @values +} + +sub DlogS_info (&$) { + my $code = $_[0]; + my $value = $_[1]; + log_info { + do { local $_ = Data::Dumper::Concise::Dumper $value; $code->() }; + }; + $value +} + +sub Dlog_warn (&@) { + my $code = shift; + my @values = @_; + log_warn { + do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + }; + @values +} + +sub DlogS_warn (&$) { + my $code = $_[0]; + my $value = $_[1]; + log_warn { + do { local $_ = Data::Dumper::Concise::Dumper $value; $code->() }; + }; + $value +} + +sub Dlog_error (&@) { + my $code = shift; + my @values = @_; + log_error { + do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + }; + @values +} + +sub DlogS_error (&$) { + my $code = $_[0]; + my $value = $_[1]; + log_error { + do { local $_ = Data::Dumper::Concise::Dumper $value; $code->() }; + }; + $value +} + +sub Dlog_fatal (&@) { + my $code = shift; + my @values = @_; + log_fatal { + do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + }; + @values +} + +sub DlogS_fatal (&$) { + my $code = $_[0]; + my $value = $_[1]; + log_fatal { + do { local $_ = Data::Dumper::Concise::Dumper $value; $code->() }; + }; + $value +} + 1; __END__ diff --git a/lib/Log/Contextual/Sugar.pm b/lib/Log/Contextual/Sugar.pm deleted file mode 100644 index 123d25a..0000000 --- a/lib/Log/Contextual/Sugar.pm +++ /dev/null @@ -1,127 +0,0 @@ -package Log::Contextual::Sugar; - -require Exporter; - -BEGIN { @ISA = qw(Exporter) } - -@EXPORT = qw( - Dlog_debug DlogS_debug - Dlog_trace DlogS_trace - Dlog_warn DlogS_warn - Dlog_info DlogS_info - Dlog_error DlogS_error - Dlog_fatal DlogS_fatal -); - -use Data::Dumper::Concise; -use Log::Contextual (); - -sub Dlog_trace (&@) { - my $code = shift; - my @values = @_; - Log::Contextual::log_trace { - do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; - }; - @values -} - -sub DlogS_trace (&$) { - my $code = $_[0]; - my $value = $_[1]; - Log::Contextual::log_trace { - do { local $_ = Data::Dumper::Concise::Dumper $value; $code->() }; - }; - $value -} - -sub Dlog_debug (&@) { - my $code = shift; - my @values = @_; - Log::Contextual::log_debug { - do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; - }; - @values -} - -sub DlogS_debug (&$) { - my $code = $_[0]; - my $value = $_[1]; - Log::Contextual::log_debug { - do { local $_ = Data::Dumper::Concise::Dumper $value; $code->() }; - }; - $value -} - -sub Dlog_info (&@) { - my $code = shift; - my @values = @_; - Log::Contextual::log_info { - do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; - }; - @values -} - -sub DlogS_info (&$) { - my $code = $_[0]; - my $value = $_[1]; - Log::Contextual::log_info { - do { local $_ = Data::Dumper::Concise::Dumper $value; $code->() }; - }; - $value -} - -sub Dlog_warn (&@) { - my $code = shift; - my @values = @_; - Log::Contextual::log_warn { - do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; - }; - @values -} - -sub DlogS_warn (&$) { - my $code = $_[0]; - my $value = $_[1]; - Log::Contextual::log_warn { - do { local $_ = Data::Dumper::Concise::Dumper $value; $code->() }; - }; - $value -} - -sub Dlog_error (&@) { - my $code = shift; - my @values = @_; - Log::Contextual::log_error { - do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; - }; - @values -} - -sub DlogS_error (&$) { - my $code = $_[0]; - my $value = $_[1]; - Log::Contextual::log_error { - do { local $_ = Data::Dumper::Concise::Dumper $value; $code->() }; - }; - $value -} - -sub Dlog_fatal (&@) { - my $code = shift; - my @values = @_; - Log::Contextual::log_fatal { - do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; - }; - @values -} - -sub DlogS_fatal (&$) { - my $code = $_[0]; - my $value = $_[1]; - Log::Contextual::log_fatal { - do { local $_ = Data::Dumper::Concise::Dumper $value; $code->() }; - }; - $value -} - -1; diff --git a/t/log.t b/t/log.t index 1ad7cf9..48e85af 100644 --- a/t/log.t +++ b/t/log.t @@ -3,7 +3,7 @@ use warnings; use lib 't/lib'; use VarLogger; -use Log::Contextual; +use Log::Contextual qw{:log with_logger set_logger}; use Test::More qw(no_plan); my $var_logger1 = VarLogger->new; my $var_logger2 = VarLogger->new; diff --git a/t/sugar.t b/t/sugar.t index 1008b03..75e8d20 100644 --- a/t/sugar.t +++ b/t/sugar.t @@ -5,8 +5,7 @@ use lib 't/lib'; use VarLogger; use Test::More 'no_plan'; -use Log::Contextual; -use Log::Contextual::Sugar; +use Log::Contextual qw{:dlog set_logger}; my $var_log = VarLogger->new;