File Coverage

blib/lib/JMAP/Tester/Role/Result.pm
Criterion Covered Total %
statement 14 22 63.6
branch 0 4 0.0
condition 0 3 0.0
subroutine 5 8 62.5
pod 3 3 100.0
total 22 40 55.0


line stmt bran cond sub pod time code
1 1     1   554 use v5.14.0;
  1         4  
2 1     1   5 use warnings;
  1         1  
  1         37  
3             package JMAP::Tester::Role::Result 0.103;
4             # ABSTRACT: the kind of thing that you get back for a request
5              
6 1     1   6 use Moo::Role;
  1         2  
  1         6  
7              
8 1     1   347 use JMAP::Tester::Abort ();
  1         1  
  1         15  
9              
10 1     1   5 use namespace::clean;
  1         9  
  1         7  
11              
12             #pod =head1 OVERVIEW
13             #pod
14             #pod This is the role consumed by the class of any object returned by JMAP::Tester's
15             #pod C method. Its only guarantee, for now, is an C method,
16             #pod and a C method.
17             #pod
18             #pod =cut
19              
20             requires 'is_success';
21             requires 'response_payload';
22              
23             #pod =method assert_successful
24             #pod
25             #pod This method returns the result if it's a success and otherwise aborts.
26             #pod
27             #pod =cut
28              
29             sub assert_successful {
30 0     0 1   my ($self) = @_;
31              
32 0 0         return $self if $self->is_success;
33              
34 0 0 0       my $str = $self->can('has_ident') && $self->has_ident
35             ? $self->ident
36             : "JMAP failure";
37              
38 0           die JMAP::Tester::Abort->new($str);
39             }
40              
41             #pod =method assert_successful_set
42             #pod
43             #pod $result->assert_successful_set($name);
44             #pod
45             #pod This method is equivalent to:
46             #pod
47             #pod $result->assert_successful->sentence_named($name)->as_set->assert_no_errors;
48             #pod
49             #pod C<$name> must be provided.
50             #pod
51             #pod =cut
52              
53             sub assert_successful_set {
54 0     0 1   my ($self, $name) = @_;
55 0           $self->assert_successful->sentence_named($name)->as_set->assert_no_errors;
56             }
57              
58             #pod =method assert_single_successful_set
59             #pod
60             #pod $result->assert_single_successful_set($name);
61             #pod
62             #pod This method is equivalent to:
63             #pod
64             #pod $result->assert_successful->single_sentence($name)->as_set->assert_no_errors;
65             #pod
66             #pod C<$name> may be omitted, in which case the sentence name is not checked.
67             #pod
68             #pod =cut
69              
70             sub assert_single_successful_set {
71 0     0 1   my ($self, $name) = @_;
72 0           $self->assert_successful->single_sentence($name)->as_set->assert_no_errors;
73             }
74              
75             1;
76              
77             __END__