| 1 | package JMAP::Tester::Sugar 0.113; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use v5.20.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use experimental 'signatures'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use Sub::Exporter -setup => [ qw( jset jcreate json_literal ) ]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 8 | ▶ | sub jset ($type, $arg, $call_id = undef) { | ||||||||
|
Subroutine
jset: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||
| 11 | 8 | my %method_arg = %$arg; | |||||||||
| 12 | 8 | ▶ | if (my $create_spec = delete $method_arg{create}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | 8 | ▶ | unless (ref $create_spec eq 'ARRAY') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | 4 | $create_spec = [ $create_spec ]; | |||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | 8 | $method_arg{create} = {}; | |||||||||
| 18 | |||||||||||
| 19 | 8 | my $i = 0; | |||||||||
| 20 | 8 | for my $creation (@$create_spec) { | |||||||||
| 21 | 12 | $method_arg{create}{"$type-" . $i++} = $creation; | |||||||||
| 22 | } | ||||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | return [ | ||||||||||
| 26 | 8 | ▶ | "$type/set", | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | \%method_arg, | ||||||||||
| 28 | (defined $call_id ? $call_id : ()), | ||||||||||
| 29 | ]; | ||||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 4 | ▶ | sub jcreate ($type, $create, $call_id = undef) { | ||||||||
|
Subroutine
jcreate: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 33 | 4 | return jset($type, { create => $create }, $call_id); | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 2 | package JMAP::Tester::JSONLiteral 0.113 { | |||||||||
| 37 | 2 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 2 | my ($class, $bytes) = @_; | |||||||||
| 39 | |||||||||||
| 40 | 2 | bless { _bytes => $bytes }, $class; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 1 | ▶ | sub bytes { return $_[0]{_bytes} } | ||||||||
|
Subroutine
bytes: called CC=1 SCAR=0.0
| |||||||||||
| 44 | |||||||||||
| 45 | 1 | ▶ | sub TO_JSON { | ||||||||
|
Subroutine
TO_JSON: called CC=1 SCAR=0.0
| |||||||||||
| 46 | # Some day, somebody is going to think that they can do this: | ||||||||||
| 47 | # $tester->request([[ json_literal(...), {...} ]]); | ||||||||||
| 48 | # | ||||||||||
| 49 | # ...but they can't, because you can't supply the JSON encoder a hunk of | ||||||||||
| 50 | # bytes to stick in the middle. We can only decline to encode *at all*. | ||||||||||
| 51 | # Because TO_JSON can't really die to abort JSON encoding, we just put some | ||||||||||
| 52 | # obvious "you did it wrong" text into the output, and then we hope that | ||||||||||
| 53 | # the user reads the logging! -- rjbs, 2025-12-11 | ||||||||||
| 54 | 1 | return "ERROR: a JMAP::Tester json_literal was passed to a JSON encoder" | |||||||||
| 55 | } | ||||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 2 | ▶ | sub json_literal ($bytes) { | ||||||||
|
Subroutine
json_literal: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 59 | 2 | return JMAP::Tester::JSONLiteral->new($bytes); | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 2 | 1; | |||||||||
| 63 | |||||||||||
| 64 | __END__ | ||||||||||