| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Log::Any::Plugin::Stringify; | 
| 2 |  |  |  |  |  |  | # ABSTRACT: Custom argument stringification plugin for log adapters | 
| 3 |  |  |  |  |  |  | $Log::Any::Plugin::Stringify::VERSION = '0.007'; | 
| 4 | 1 |  |  | 1 |  | 696 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 26 |  | 
| 5 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 29 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 1 |  |  |  |  | 55 | use Log::Any::Plugin::Util qw( | 
| 8 |  |  |  |  |  |  | all_logging_methods get_old_method set_new_method | 
| 9 | 1 |  |  | 1 |  | 4 | ); | 
|  | 1 |  |  |  |  | 2 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 1 |  |  | 1 |  | 5 | use Data::Dumper; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 207 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | sub install { | 
| 14 | 2 |  |  | 2 | 1 | 7 | my ($class, $adapter_class, %args) = @_; | 
| 15 |  |  |  |  |  |  |  | 
| 16 | 2 |  | 100 |  |  | 9 | my $stringifier = $args{stringifier} || \&default_stringifier; | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | # Inject the stringifier into the existing logging methods | 
| 19 |  |  |  |  |  |  | # | 
| 20 | 2 |  |  |  |  | 6 | for my $method_name ( all_logging_methods() ) { | 
| 21 | 38 |  |  |  |  | 94 | my $old_method = get_old_method($adapter_class, $method_name); | 
| 22 |  |  |  |  |  |  | set_new_method($adapter_class, $method_name, sub { | 
| 23 | 6 |  |  | 6 |  | 1700 | my $self = shift; | 
| 24 | 6 |  |  |  |  | 12 | $self->$old_method($stringifier->(@_)); | 
| 25 | 38 |  |  |  |  | 156 | }); | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  | } | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | sub default_stringifier { | 
| 30 | 5 |  |  | 5 | 1 | 12 | my (@args) = @_; | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 5 |  |  |  |  | 8 | local $Data::Dumper::Indent    = 0; | 
| 33 | 5 |  |  |  |  | 9 | local $Data::Dumper::Pair      = '='; | 
| 34 | 5 |  |  |  |  | 8 | local $Data::Dumper::Quotekeys = 0; | 
| 35 | 5 |  |  |  |  | 6 | local $Data::Dumper::Sortkeys  = 1; | 
| 36 | 5 |  |  |  |  | 9 | local $Data::Dumper::Terse     = 1; | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 5 | 100 |  |  |  | 9 | return join('', map { ref $_ ? Dumper($_) : $_ } @args); | 
|  | 11 |  |  |  |  | 37 |  | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | 1; | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | __END__ |