File Coverage

blib/lib/JMAP/Tester/Response.pm
Criterion Covered Total %
statement 40 40 100.0
branch n/a
condition n/a
subroutine 12 12 100.0
pod 0 4 0.0
total 52 56 92.8


line stmt bran cond sub pod time code
1 4     4   277306 use v5.20.0;
  4         16  
2              
3             package JMAP::Tester::Response 0.109;
4             # ABSTRACT: what you get in reply to a succesful JMAP request
5              
6 4     4   528 use Moo;
  4         7094  
  4         23  
7 4     4   2914 use experimental 'signatures';
  4         1250  
  4         27  
8              
9             # We can't use 'sub sentencebroker;' as a stub here as it conflicts
10             # with older Role::Tiny versions (2.000006, 2.000008, and others).
11             # With the stub, we'd see this error during compilation:
12             #
13             # Can't use string ("-1") as a symbol ref while "strict refs" in use at
14             # /usr/share/perl5/Role/Tiny.pm line 382
15             #
16             # We could pin a newer Role::Tiny version but this fix is easy enough
17              
18             has sentence_broker => (
19             is => 'ro',
20             lazy => 1,
21             init_arg => undef,
22             default => sub {
23             my ($self) = @_;
24             JMAP::Tester::SentenceBroker->new({ response => $self });
25             },
26             );
27              
28             with 'JMAP::Tester::Role::SentenceCollection', 'JMAP::Tester::Role::HTTPResult';
29              
30 4     4   3252 use JMAP::Tester::Response::Sentence;
  4         13  
  4         166  
31 4     4   2197 use JMAP::Tester::Response::Paragraph;
  4         13  
  4         242  
32 4     4   2010 use JMAP::Tester::SentenceBroker;
  4         13  
  4         198  
33              
34 4     4   26 use namespace::clean;
  4         6  
  4         28  
35              
36             #pod =head1 OVERVIEW
37             #pod
38             #pod A JMAP::Tester::Response object represents the successful response to a JMAP
39             #pod call. It is a successful L.
40             #pod
41             #pod A Response is used mostly to contain the responses to the individual methods
42             #pod passed in the request.
43             #pod
44             #pod =cut
45              
46 1     1 0 9 sub is_success { 1 }
47              
48             has items => (
49             is => 'bare',
50             reader => '_items',
51             required => 1,
52             );
53              
54             has wrapper_properties => (
55             is => 'ro',
56             );
57              
58 93     93 0 157 sub items ($self) { @{ $self->_items } }
  93         157  
  93         134  
  93         137  
  93         453  
59              
60             sub add_items ($self, @) {
61             $self->sentence_broker->abort("can't add items to " . __PACKAGE__);
62             }
63              
64             sub default_diagnostic_dumper {
65 19     19 0 656212 state $default = do {
66 2         572 require JSON::MaybeXS;
67 2         8655 state $json = JSON::MaybeXS->new->utf8->convert_blessed->pretty->canonical;
68 11     11   148 sub ($value) { $json->encode($value); }
  11         24  
  11         17  
  11         19  
69 2         52 };
70              
71 19         433 return $default;
72             }
73              
74             has _diagnostic_dumper => (
75             is => 'ro',
76             builder => 'default_diagnostic_dumper',
77             init_arg => 'diagnostic_dumper',
78             );
79              
80 11     11 0 22 sub dump_diagnostic ($self, $value) {
  11         22  
  11         23  
  11         19  
81 11         48 $self->_diagnostic_dumper->($value);
82             }
83              
84             1;
85              
86             __END__