| 1 | 2 | ▶ | use v5.20.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | package JMAP::Tester::Response::Paragraph 0.113; | ||||||||||||||||||||||||||||
| 3 | # ABSTRACT: a group of sentences in a JMAP response | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use experimental 'signatures'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use JMAP::Tester::Abort 'abort'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | #pod =head1 OVERVIEW | ||||||||||||||||||||||||||||
| 13 | #pod | ||||||||||||||||||||||||||||
| 14 | #pod These objects represent paragraphs in the JMAP response. That is, if your | ||||||||||||||||||||||||||||
| 15 | #pod response is: | ||||||||||||||||||||||||||||
| 16 | #pod | ||||||||||||||||||||||||||||
| 17 | #pod [ | ||||||||||||||||||||||||||||
| 18 | #pod [ "messages", { ... }, "a" ], # 1 | ||||||||||||||||||||||||||||
| 19 | #pod [ "smellUpdates", { ... }, "b" ], # 2 | ||||||||||||||||||||||||||||
| 20 | #pod [ "smells", { ... }, "b" ], # 3 | ||||||||||||||||||||||||||||
| 21 | #pod ] | ||||||||||||||||||||||||||||
| 22 | #pod | ||||||||||||||||||||||||||||
| 23 | #pod ...then #1 forms one paragraph and #2 and #3 together form another. It goes by | ||||||||||||||||||||||||||||
| 24 | #pod matching client ids. | ||||||||||||||||||||||||||||
| 25 | #pod | ||||||||||||||||||||||||||||
| 26 | #pod =cut | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | sub client_id ($self) { | ||||||||||||||||||||||||||
|
Subroutine
client_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 1 | $self->_sentences->[0]->client_id; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 23 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | abort("tried to build 0-sentence paragraph") | ||||||||||||||||||||||||||||
| 34 | 23 | ▶ | unless @{ $_[0]->_sentences }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 22 | my $client_id = $_[0]->_sentences->[0]->client_id; | |||||||||||||||||||||||||||
| 37 | abort("tried to build paragraph with non-uniform client_ids") | ||||||||||||||||||||||||||||
| 38 | 22 | ▶ | if grep {; $_->client_id ne $client_id } @{ $_[0]->_sentences }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 2 | has sentences => (is => 'bare', reader => '_sentences', required => 1); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | #pod =method sentences | ||||||||||||||||||||||||||||
| 44 | #pod | ||||||||||||||||||||||||||||
| 45 | #pod The C<sentences> method returns a list of | ||||||||||||||||||||||||||||
| 46 | #pod L<Sentence|JMAP::Tester::Response::Sentence> objects, one for each sentence | ||||||||||||||||||||||||||||
| 47 | #pod in the paragraph. | ||||||||||||||||||||||||||||
| 48 | #pod | ||||||||||||||||||||||||||||
| 49 | #pod =cut | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 16 | ▶ | sub sentences ($self) { @{ $self->_sentences } } | ||||||||||||||||||||||||||
|
Subroutine
sentences: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | #pod =method sentence | ||||||||||||||||||||||||||||
| 54 | #pod | ||||||||||||||||||||||||||||
| 55 | #pod my $sentence = $para->sentence($n); | ||||||||||||||||||||||||||||
| 56 | #pod | ||||||||||||||||||||||||||||
| 57 | #pod This method returns the I<n>th sentence of the paragraph. | ||||||||||||||||||||||||||||
| 58 | #pod | ||||||||||||||||||||||||||||
| 59 | #pod =cut | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 6 | ▶ | sub sentence ($self, $n) { | ||||||||||||||||||||||||||
|
Subroutine
sentence: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 6 | ▶ | abort("there is no sentence for index $n") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | unless $self->_sentences->[$n]; | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | #pod =method single | ||||||||||||||||||||||||||||
| 67 | #pod | ||||||||||||||||||||||||||||
| 68 | #pod my $sentence = $para->single; | ||||||||||||||||||||||||||||
| 69 | #pod my $sentence = $para->single($name); | ||||||||||||||||||||||||||||
| 70 | #pod | ||||||||||||||||||||||||||||
| 71 | #pod This method throws an exception if there is more than one sentence in the | ||||||||||||||||||||||||||||
| 72 | #pod paragraph. If a C<$name> argument is given and the paragraph's single | ||||||||||||||||||||||||||||
| 73 | #pod sentence doesn't have that name, an exception is raised. | ||||||||||||||||||||||||||||
| 74 | #pod | ||||||||||||||||||||||||||||
| 75 | #pod Otherwise, this method returns the sentence. | ||||||||||||||||||||||||||||
| 76 | #pod | ||||||||||||||||||||||||||||
| 77 | #pod =cut | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 6 | ▶ | sub single ($self, $name = undef) { | ||||||||||||||||||||||||||
|
Subroutine
single: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 6 | my @sentences = $self->sentences; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 6 | ▶ | abort("more than one sentence in paragraph, but ->single called") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | if @sentences > 1; | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 5 | ▶ | abort("single sentence not of expected name <$name>") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $name and $name ne $sentences[0]->name
MC/DC100%2/2
defined $name and $name ne $sentences[0]->name
defined $name
$name ne $sentences[0]->name
Truth table100%3/3
A and B
A= defined $nameB= $name ne $sentences[0]->name
| |||||||||||||||||||||||||||||
| 86 | if defined $name && $name ne $sentences[0]->name; | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 4 | return $sentences[0]; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | #pod =method assert_n_sentences | ||||||||||||||||||||||||||||
| 92 | #pod | ||||||||||||||||||||||||||||
| 93 | #pod my ($s1, $s2, ...) = $paragraph->assert_n_sentences($n); | ||||||||||||||||||||||||||||
| 94 | #pod | ||||||||||||||||||||||||||||
| 95 | #pod This method returns all the sentences in the paragarph, as long as there are | ||||||||||||||||||||||||||||
| 96 | #pod exactly C<$n>. Otherwise, it aborts. | ||||||||||||||||||||||||||||
| 97 | #pod | ||||||||||||||||||||||||||||
| 98 | #pod =cut | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 3 | ▶ | sub assert_n_sentences ($self, $n) { | ||||||||||||||||||||||||||
|
Subroutine
assert_n_sentences: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 101 | 3 | ▶ | Carp::confess("no sentence count given") unless defined $n; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 2 | my @sentences = $self->sentences; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 2 | ▶ | unless (@sentences == $n) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 1 | abort("expected $n sentences but got " . @sentences) | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 1 | return @sentences; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | #pod =method sentence_named | ||||||||||||||||||||||||||||
| 113 | #pod | ||||||||||||||||||||||||||||
| 114 | #pod my $sentence = $paragraph->sentence_named($name); | ||||||||||||||||||||||||||||
| 115 | #pod | ||||||||||||||||||||||||||||
| 116 | #pod This method returns the sentence with the given name. If no such sentence | ||||||||||||||||||||||||||||
| 117 | #pod exists, or if two sentences with the name exist, the tester will abort. | ||||||||||||||||||||||||||||
| 118 | #pod | ||||||||||||||||||||||||||||
| 119 | #pod =cut | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 4 | ▶ | sub sentence_named ($self, $name) { | ||||||||||||||||||||||||||
|
Subroutine
sentence_named: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | 4 | ▶ | Carp::confess("no sentence name given") unless defined $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 3 | my @sentences = grep {; $_->name eq $name } $self->sentences; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 3 | ▶ | unless (@sentences) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 1 | abort(qq{no sentence found with name "$name"}); | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 2 | ▶ | if (@sentences > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 1 | abort(qq{found more than one sentence with name "$name"}); | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 1 | return $sentences[0]; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | #pod =method as_triples | ||||||||||||||||||||||||||||
| 138 | #pod | ||||||||||||||||||||||||||||
| 139 | #pod =method as_stripped_triples | ||||||||||||||||||||||||||||
| 140 | #pod | ||||||||||||||||||||||||||||
| 141 | #pod C<as_triples> returns an arrayref containing the result of calling | ||||||||||||||||||||||||||||
| 142 | #pod C<as_triple> on each sentence in the paragraph. C<as_stripped_triples> removes | ||||||||||||||||||||||||||||
| 143 | #pod JSON types. | ||||||||||||||||||||||||||||
| 144 | #pod | ||||||||||||||||||||||||||||
| 145 | #pod =cut | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 1 | ▶ | sub as_triples ($self) { | ||||||||||||||||||||||||||
|
Subroutine
as_triples: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 148 | 1 | [ map {; $_->as_triple } $self->sentences ] | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 1 | ▶ | sub as_stripped_triples ($self) { | ||||||||||||||||||||||||||
|
Subroutine
as_stripped_triples: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 152 | 1 | [ map {; $_->as_stripped_triple } $self->sentences ] | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | #pod =method as_pairs | ||||||||||||||||||||||||||||
| 156 | #pod | ||||||||||||||||||||||||||||
| 157 | #pod C<as_pairs> returns an arrayref containing the result of calling C<as_pair> | ||||||||||||||||||||||||||||
| 158 | #pod on each sentence in the paragraph. C<as_stripped_pairs> removes JSON types. | ||||||||||||||||||||||||||||
| 159 | #pod | ||||||||||||||||||||||||||||
| 160 | #pod =cut | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 1 | ▶ | sub as_pairs ($self) { | ||||||||||||||||||||||||||
|
Subroutine
as_pairs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 163 | 1 | [ map {; $_->as_pair } $self->sentences ] | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 1 | ▶ | sub as_stripped_pairs ($self) { | ||||||||||||||||||||||||||
|
Subroutine
as_stripped_pairs: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 167 | 1 | [ map {; $_->as_stripped_pair } $self->sentences ] | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 2 | 1; | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | __END__ | ||||||||||||||||||||||||||||