File Coverage

blib/lib/JMAP/Tester/WebSocket/Response.pm
Criterion Covered Total %
statement 20 31 64.5
branch n/a
condition n/a
subroutine 7 12 58.3
pod 0 4 0.0
total 27 47 57.4


line stmt bran cond sub pod time code
1 1     1   10 use v5.10.0;
  1         3  
2 1     1   5 use warnings;
  1         2  
  1         76  
3              
4             package JMAP::Tester::WebSocket::Response 0.005;
5             # ABSTRACT: what you get in reply to a succesful JMAP request
6              
7 1     1   4 use Moo;
  1         2  
  1         6  
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              
29             with 'JMAP::Tester::Role::SentenceCollection', 'JMAP::Tester::WebSocket::Role::WebSocketResult';
30              
31 1     1   755 use JMAP::Tester::Response::Sentence;
  1         31567  
  1         33  
32 1     1   429 use JMAP::Tester::Response::Paragraph;
  1         30452  
  1         34  
33 1     1   424 use JMAP::Tester::SentenceBroker;
  1         3377  
  1         30  
34              
35 1     1   6 use namespace::clean;
  1         1  
  1         4  
36              
37             #pod =head1 OVERVIEW
38             #pod
39             #pod A JMAP::Tester::WebSocket::Response object represents the successful response to a JMAP
40             #pod call. It is a successful L.
41             #pod
42             #pod A Response is used mostly to contain the responses to the individual methods
43             #pod passed in the request.
44             #pod
45             #pod =cut
46              
47 0     0 0   sub is_success { 1 }
48              
49             has items => (
50             is => 'bare',
51             reader => '_items',
52             required => 1,
53             );
54              
55             has wrapper_properties => (
56             is => 'ro',
57             );
58              
59 0     0 0   sub items { @{ $_[0]->_items } }
  0            
60              
61             sub add_items {
62             $_[0]->sentence_broker->abort("can't add items to " . __PACKAGE__);
63             }
64              
65             sub default_diagnostic_dumper {
66 0     0 0   state $default = do {
67 0           require JSON::MaybeXS;
68 0           state $json = JSON::MaybeXS->new->utf8->convert_blessed->pretty->canonical;
69 0     0     sub { $json->encode($_[0]); }
70 0           };
71              
72 0           return $default;
73             }
74              
75             has _diagnostic_dumper => (
76             is => 'ro',
77             builder => 'default_diagnostic_dumper',
78             init_arg => 'diagnostic_dumper',
79             );
80              
81             sub dump_diagnostic {
82 0     0 0   my ($self, $value) = @_;
83 0           $self->_diagnostic_dumper->($value);
84             }
85              
86             1;
87              
88             __END__