| 1 | package Log::Message::Structured::Stringify::AsJSON; | ||
| 2 | 0 | ▶ | use Moose::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 3 | use namespace::autoclean; | ||
| 4 | |||
| 5 | use JSON::Any; | ||
| 6 | use utf8 (); | ||
| 7 | |||
| 8 | requires 'as_hash'; | ||
| 9 | |||
| 10 | around 'as_string' => sub { | ||
| 11 | my $orig = shift; | ||
| 12 | my $self = shift; | ||
| 13 | my $hashref = $self->as_hash; | ||
| 14 | my $json = JSON::Any->objToJson( $hashref ); | ||
| 15 | utf8::decode($json) if !utf8::is_utf8($json) and utf8::valid($json); # if it's valid utf8 mark it as such | ||
| 16 | return $json; | ||
| 17 | }; | ||
| 18 | |||
| 19 | |||
| 20 | 1; | ||
| 21 | |||
| 22 | __END__ | ||