File Coverage

blib/lib/JMAP/Tester/Response.pm
Criterion Covered Total %
statement 28 28 100.0
branch n/a
condition n/a
subroutine 11 11 100.0
pod 0 4 0.0
total 39 43 90.7


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