| 1 | package Langertha::Role::JSON; | ||||||||||||||
| 2 | # ABSTRACT: Role for JSON | ||||||||||||||
| 3 | 194 | our $VERSION = '0.505'; | |||||||||||||
| 4 | 194 | ▶ | use Moose::Role; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 194 | ▶ | use JSON::MaybeXS; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 194 | ▶ | use Encode qw( encode_utf8 decode_utf8 ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 7548 | ▶ | sub json { shift->_json } | ||||||||||||
|
Subroutine
json: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 2 | ▶ | sub decode_json_text { | ||||||||||||
|
Subroutine
decode_json_text: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||
| 11 | 0 | ▶ | my ( $self, $text ) = @_; | ||||||||||||
|
Subroutine
decode_json_text: not called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||
| 12 | 0 | ▶ | return undef unless defined $text; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 13 | 0 | return $self->_json->decode(encode_utf8($text)); | |||||||||||||
| 14 | } | ||||||||||||||
| 15 | |||||||||||||||
| 16 | |||||||||||||||
| 17 | 252 | ▶ | sub encode_json_text { | ||||||||||||
|
Subroutine
encode_json_text: called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||||
| 18 | 0 | ▶ | my ( $self, $data ) = @_; | ||||||||||||
|
Subroutine
encode_json_text: not called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||||
| 19 | 0 | return decode_utf8( $self->_json->encode($data) ); | |||||||||||||
| 20 | } | ||||||||||||||
| 21 | |||||||||||||||
| 22 | |||||||||||||||
| 23 | |||||||||||||||
| 24 | 194 | has _json => ( | |||||||||||||
| 25 | is => 'ro', | ||||||||||||||
| 26 | lazy_build => 1, | ||||||||||||||
| 27 | ); | ||||||||||||||
| 28 | # convert_blessed => 1 lets the encoder serialize the distribution's value | ||||||||||||||
| 29 | # objects (Usage, Cost, Tool, ToolCall, ToolChoice, UsageRecord, ...) through | ||||||||||||||
| 30 | # their TO_JSON, matching what those classes' POD calls "the house default". | ||||||||||||||
| 31 | # Plain request bodies carry no blessed values, so this changes nothing for | ||||||||||||||
| 32 | # them; it only turns a croak into a serialization when a caller hands a value | ||||||||||||||
| 33 | # object to $engine->json. -- karr k120 | ||||||||||||||
| 34 | 2771 | ▶ | sub _build__json { JSON::MaybeXS->new( utf8 => 1, canonical => 1, convert_blessed => 1 ) } | ||||||||||||
|
Subroutine
_build__json: called CC=1 SCAR=0.0
| |||||||||||||||
| 35 | |||||||||||||||
| 36 | |||||||||||||||
| 37 | 194 | 1; | |||||||||||||
| 38 | |||||||||||||||
| 39 | __END__ | ||||||||||||||