| 1 | 2 | ▶ | use v5.20.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | package JMAP::Tester::Response::Sentence 0.113; | ||||||||||
| 3 | # ABSTRACT: a single triple within a JMAP response | ||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | use experimental 'signatures'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | #pod =head1 OVERVIEW | ||||||||||
| 12 | #pod | ||||||||||
| 13 | #pod These objects represent sentences in the JMAP response. That is, if your | ||||||||||
| 14 | #pod response is: | ||||||||||
| 15 | #pod | ||||||||||
| 16 | #pod [ | ||||||||||
| 17 | #pod [ "messages", { ... }, "a" ], # 1 | ||||||||||
| 18 | #pod [ "smellUpdates", { ... }, "b" ], # 2 | ||||||||||
| 19 | #pod [ "smells", { ... }, "b" ], # 3 | ||||||||||
| 20 | #pod ] | ||||||||||
| 21 | #pod | ||||||||||
| 22 | #pod ...then #1, #2, and #3 are each a single sentence. | ||||||||||
| 23 | #pod | ||||||||||
| 24 | #pod The first item in the triple is accessed with the C<name> method. The second | ||||||||||
| 25 | #pod is accessed with the C<arguments> method. The third, with the C<client_id> | ||||||||||
| 26 | #pod method. | ||||||||||
| 27 | #pod | ||||||||||
| 28 | #pod =cut | ||||||||||
| 29 | |||||||||||
| 30 | 2 | has name => (is => 'ro', required => 1); | |||||||||
| 31 | 2 | has arguments => (is => 'ro', required => 1); | |||||||||
| 32 | 2 | has client_id => (is => 'ro', required => 1); | |||||||||
| 33 | |||||||||||
| 34 | 2 | has sentence_broker => (is => 'ro', required => 1); | |||||||||
| 35 | |||||||||||
| 36 | 2 | ▶ | sub _strip_json_types ($self, $whatever) { | ||||||||
|
Subroutine
_strip_json_types: called CC=1 SCAR=0.0
| |||||||||||
| 37 | 2 | $self->sentence_broker->strip_json_types($whatever); | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | #pod =method as_triple | ||||||||||
| 41 | #pod | ||||||||||
| 42 | #pod =method as_stripped_triple | ||||||||||
| 43 | #pod | ||||||||||
| 44 | #pod C<as_triple> returns the underlying JSON data of the sentence, which may | ||||||||||
| 45 | #pod include objects used to convey type information for booleans, strings, and | ||||||||||
| 46 | #pod numbers. | ||||||||||
| 47 | #pod | ||||||||||
| 48 | #pod For unblessed data, use C<as_stripped_triple>. | ||||||||||
| 49 | #pod | ||||||||||
| 50 | #pod These return a three-element arrayref. | ||||||||||
| 51 | #pod | ||||||||||
| 52 | #pod =cut | ||||||||||
| 53 | |||||||||||
| 54 | 16 | ▶ | sub as_triple ($self) { [ $self->name, $self->arguments, $self->client_id ] } | ||||||||
|
Subroutine
as_triple: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 55 | |||||||||||
| 56 | 3 | ▶ | sub as_stripped_triple ($self) { | ||||||||
|
Subroutine
as_stripped_triple: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 57 | 3 | $self->sentence_broker->strip_json_types($self->as_triple); | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | #pod =method as_pair | ||||||||||
| 61 | #pod | ||||||||||
| 62 | #pod =method as_stripped_pair | ||||||||||
| 63 | #pod | ||||||||||
| 64 | #pod C<as_pair> returns the same thing as C<as_triple>, but without the | ||||||||||
| 65 | #pod C<client_id>. That means it returns a two-element arrayref. | ||||||||||
| 66 | #pod | ||||||||||
| 67 | #pod C<as_stripped_pair> returns the same minus JSON type information. | ||||||||||
| 68 | #pod | ||||||||||
| 69 | #pod =cut | ||||||||||
| 70 | |||||||||||
| 71 | 20 | ▶ | sub as_pair ($self) { [ $self->name, $self->arguments ] } | ||||||||
|
Subroutine
as_pair: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 72 | |||||||||||
| 73 | 3 | ▶ | sub as_stripped_pair ($self) { | ||||||||
|
Subroutine
as_stripped_pair: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 74 | 3 | $self->sentence_broker->strip_json_types($self->as_pair); | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | #pod =method as_set | ||||||||||
| 78 | #pod | ||||||||||
| 79 | #pod This method returns a L<JMAP::Tester::Response::Sentence::Set> object for the | ||||||||||
| 80 | #pod current sentence. That's a specialized Sentence for C<setFoos>-style JMAP | ||||||||||
| 81 | #pod method responses. | ||||||||||
| 82 | #pod | ||||||||||
| 83 | #pod =cut | ||||||||||
| 84 | |||||||||||
| 85 | 11 | ▶ | sub as_set ($self) { | ||||||||
|
Subroutine
as_set: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 86 | 11 | ▶ | unless ($self->name =~ m{/set$}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 1 | return $self->sentence_broker->response->abort( | |||||||||
| 88 | sprintf(qq{tried to call ->as_set on sentence named "%s"}, $self->name) | ||||||||||
| 89 | ); | ||||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 10 | require JMAP::Tester::Response::Sentence::Set; | |||||||||
| 93 | 10 | return JMAP::Tester::Response::Sentence::Set->new({ | |||||||||
| 94 | name => $self->name, | ||||||||||
| 95 | arguments => $self->arguments, | ||||||||||
| 96 | client_id => $self->client_id, | ||||||||||
| 97 | |||||||||||
| 98 | sentence_broker => $self->sentence_broker, | ||||||||||
| 99 | }); | ||||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | #pod =method assert_named | ||||||||||
| 103 | #pod | ||||||||||
| 104 | #pod $sentence->assert_named("theName") | ||||||||||
| 105 | #pod | ||||||||||
| 106 | #pod This method aborts unless the sentence's name is the given name. Otherwise, it | ||||||||||
| 107 | #pod returns the sentence. | ||||||||||
| 108 | #pod | ||||||||||
| 109 | #pod =cut | ||||||||||
| 110 | |||||||||||
| 111 | 5 | ▶ | sub assert_named ($self, $name) { | ||||||||
|
Subroutine
assert_named: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||
| 112 | 5 | ▶ | Carp::confess("no name given") unless defined $name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 113 | |||||||||||
| 114 | 5 | ▶ | return $self if $self->name eq $name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 115 | |||||||||||
| 116 | 2 | $self->sentence_broker->response->abort( | |||||||||
| 117 | sprintf qq{expected sentence named "%s" but got "%s"}, $name, $self->name | ||||||||||
| 118 | ); | ||||||||||
| 119 | } | ||||||||||
| 120 | |||||||||||
| 121 | 0 | ▶ | sub TO_JSON ($self) { | ||||||||
|
Subroutine
TO_JSON: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 122 | 0 | return [ $self->name, $self->arguments, $self->client_id ]; | |||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | 2 | 1; | |||||||||
| 126 | |||||||||||
| 127 | __END__ | ||||||||||