Structured/Stringify/AsJSON.pm

filter: Statementstmt 33.3% 1 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 50.0% 2 / 4 CC 1 SCAR 2.6
CC
1
Cov
33%
BEGIN
1.3
CRAP 1.3
« Structured/Event/ScriptRun.pm ↑ Summary Structured/Stringify/Sprintf.pm »
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__
« Structured/Event/ScriptRun.pm ↑ Summary Structured/Stringify/Sprintf.pm »