Tester/Role/Result.pm

filter: Statementstmt 97.8% 46 / 47 Branchbran 78.5% 11 / 14 Conditioncond 66.6% 4 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 92.3% 12 / 13 Podpod 50.0% 3 / 6 totaltotal 85.5% 77 / 90 CC 13 SCAR 15.2
CC
13
Cov
91%
abort
9.2
assert_successful
4.0
assert_single_successful_set
2.0
CRAP 4.6
« Tester/Role/SentenceCollection.pm ↑ Summary Tester/UA/LWP.pm »
1 2 ▶use v5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package JMAP::Tester::Role::Result 0.113;
4 # ABSTRACT: the kind of thing that you get back for a request
5  
6 2 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Data::OptList ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use JMAP::Tester::Abort ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 #pod =head1 OVERVIEW
16 #pod
17 #pod This is the role consumed by the class of any object returned by JMAP::Tester's
18 #pod C<request> method. Its only guarantee, for now, is an C<is_success> method,
19 #pod and a C<response_payload> method.
20 #pod
21 #pod =cut
22  
23 2 requires 'is_success';
24 2 requires 'response_payload';
25  
26 #pod =method assert_successful
27 #pod
28 #pod This method returns the result if it's a success and otherwise aborts.
29 #pod
30 #pod =cut
31  
32 6 ▶sub assert_successful ($self) {
Subroutine assert_successful: called CC=4 SCAR=13.9
Pod documented
33 6 ▶ return $self if $self->is_success;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_success 4 2 6
34  
35 2 ▶ my $str = $self->can('has_ident') && $self->has_ident
Branch: 1 branch
BranchTrueFalseTotal
$self->can('has_ident') && $self->has_ident ? : 1 1 2
Condition66%2/3
$self->can("has_ident") and $self->has_ident
!ll&&!rl&&r
011
MC/DC50%1/2
$self->can("has_ident") and $self->has_ident
$self->can("has_ident") $self->has_ident
Truth table66%2/3
A and B
A= $self->can("has_ident")B= $self->has_ident
ABresult
0X0
100
111
36 ? $self->ident
37 : "JMAP failure";
38  
39 2 die JMAP::Tester::Abort->new($str);
40 }
41  
42 #pod =method assert_successful_set
43 #pod
44 #pod $result->assert_successful_set($name);
45 #pod
46 #pod This method is equivalent to:
47 #pod
48 #pod $result->assert_successful->sentence_named($name)->as_set->assert_no_errors;
49 #pod
50 #pod C<$name> must be provided.
51 #pod
52 #pod =cut
53  
54 1 ▶sub assert_successful_set ($self, $name) {
Subroutine assert_successful_set: called CC=1 SCAR=0.0
Pod documented
55 1 $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 2 ▶sub assert_single_successful_set ($self, $name = undef) {
Subroutine assert_single_successful_set: called CC=2 SCAR=6.9
Pod documented
71 2 $self->assert_successful->single_sentence($name)->as_set->assert_no_errors;
72 }
73  
74 2 has diagnostic_dumper => (
75 is => 'ro',
76 required => 1,
77 );
78  
79 30 ▶sub dump_diagnostic ($self, $value) {
Subroutine dump_diagnostic: called CC=1 SCAR=0.0
Pod undocumented
80 30 $self->diagnostic_dumper->($value);
81 }
82  
83 0 ▶sub default_diagnostics ($self) {
Subroutine default_diagnostics: not called CC=1 SCAR=6.9
Pod undocumented
84 0 return;
85 }
86  
87 32 ▶sub abort ($self, $string, $diag_spec = undef) {
Subroutine abort: called CC=9 SCAR=22.2
Pod undocumented
88 32 ▶ $diag_spec //= $self->default_diagnostics;
Condition66%2/3
$diag_spec //= $self->default_diagnostics
l!l&&r!l&&!r
19130
MC/DC0%0/2
$diag_spec //= $self->default_diagnostics
$diag_spec $self->default_diagnostics
Truth table66%2/3
A //= B
A= $diag_specB= $self->default_diagnostics
ABresult
1X1
011
000
89  
90 32 my @diagnostics;
91  
92 32 ▶ if ($diag_spec) {
Branch: 1 branch
BranchTrueFalseTotal
if ($diag_spec) 32 0 32
93 32 my $todo = Data::OptList::mkopt($diag_spec);
94  
95 32 PAIR: for my $pair (@$todo) {
96 34 my ($label, $value) = @$pair;
97  
98 34 ▶ if (not defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 4 30 34
99 4 push @diagnostics, "$label\n";
100 4 next PAIR;
101 }
102  
103 30 ▶ if (ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) 30 0 30
104 30 $value = $self->dump_diagnostic($value);
105 }
106  
107 30 push @diagnostics, "$label: $value";
108 30 ▶ $diagnostics[-1] .= "\n" unless $value =~ /\n\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /\n\z/u 30 0 30
109 }
110 }
111  
112 32 ▶ die JMAP::Tester::Abort->new({
Branch: 1 branch
BranchTrueFalseTotal
@diagnostics ? : 31 1 32
113 message => $string,
114 (@diagnostics ? (diagnostics => \@diagnostics) : ()),
115 });
116 }
117  
118 2 1;
119  
120 __END__
« Tester/Role/SentenceCollection.pm ↑ Summary Tester/UA/LWP.pm »