Jifty/Response.pm

filter: Statementstmt 46.8% 22 / 47 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 46.1% 6 / 13 Podpod 100% 7 / 7 totaltotal 41.6% 35 / 84 CC 7 SCAR 16.0
CC
7
Cov
37%
success
12.0
new
6.0
result
6.0
CRAP 4.9
« Jifty/View.pm ↑ Summary Jifty/Script/App.pm »
1 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Jifty::Response;
5  
6 =head1 NAME
7  
8 Jifty::Response - Canonical internal representation of the result of a L<Jifty::Action>
9  
10 =head1 DESCRIPTION
11  
12 The answer to a L<Jifty::Request> is a C<Jifty::Response> object.
13 Currently, the response object exists merely to collect the
14 L<Jifty::Result> objects of each L<Jifty::Action> that ran.
15  
16 =cut
17  
18 1 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # Monkeypatch Mouse to silence misleading warnings. See rt.cpan.org #63675.
21 {
22 1 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶ *Mouse::Meta::Class::inherit_from_foreign_class = sub { return };
Subroutine __ANON__: called CC=1 SCAR=0.0
24 }
25  
26 1 extends 'Plack::Response';
27  
28 1 has 'error' => (is => 'rw');
29  
30 =head2 new
31  
32 Default the status to 200.
33  
34 =cut
35  
36 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
37 0 my $class = shift;
38 0 my $self = $class->SUPER::new(@_);
39 0 ▶ $self->status(200) unless $self->status;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->status 0 0 0
40 0 return $self;
41 }
42  
43 =head2 add_header NAME VALUE
44  
45 Deprecated. Use header(NAME, VALUE)
46  
47 =cut
48  
49 0 ▶sub add_header {
Subroutine add_header: not called CC=1 SCAR=6.9
Pod documented
50 0 my $self = shift;
51 0 $self->header(@_);
52 }
53  
54 =head2 result MONIKER [RESULT]
55  
56 Gets or sets the L<Jifty::Result> of the L<Jifty::Action> with the given
57 I<MONIKER>.
58  
59 =cut
60  
61 0 ▶sub result {
Subroutine result: not called CC=2 SCAR=17.9
Pod documented
62 0 my $self = shift;
63 0 my $moniker = shift;
64 0 ▶ $self->{results}{$moniker} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
65 0 return $self->{results}{$moniker};
66 }
67  
68 =head2 results
69  
70 Returns a hash which maps moniker to its L<Jifty::Result>
71  
72 =cut
73  
74 0 ▶sub results {
Subroutine results: not called CC=2 SCAR=17.9
Pod documented
75 0 my $self = shift;
76 0 ▶ return %{$self->{results} || {}};
Condition0%0/2
$self->{'results'} || {}
l!l
00
MC/DC0%0/1
$self->{'results'} || {}
$self->{'results'}
Truth table0%0/2
A
A= $self->{'results'}
Aresult
11
00
77 }
78  
79 =head2 messages
80  
81 Returns the aggregate messages of all of the L<Jifty::Result>s.
82  
83 =cut
84  
85 0 ▶sub messages {
Subroutine messages: not called CC=2 SCAR=17.9
Pod documented
86 0 my $self = shift;
87 0 my %results = $self->results;
88 0 ▶ return map {$_, $results{$_}->message} grep {defined $results{$_}->message and length $results{$_}->message} sort keys %results;
Condition0%0/3
defined $results{$_}->message && length $results{$_}->message
!ll&&!rl&&r
000
MC/DC0%0/2
defined $results{$_}->message && length $results{$_}->message
defined $results{$_}->message length $results{$_}->message
Truth table0%0/3
A && B
A= defined $results{$_}->messageB= length $results{$_}->message
ABresult
0X0
100
111
89 }
90  
91 =head2 error [MESSAGE]
92  
93 Gets or sets a generalized error response. Setting an error also
94 makes the response a L</failure>.
95  
96 =head2 success
97  
98 Returns true if none of the results are failures and there is no
99 L</error> set.
100  
101 =cut
102  
103 0 ▶sub success {
Subroutine success: not called CC=3 SCAR=24.8
Pod documented
104 0 my $self = shift;
105 0 ▶ return 0 if grep {$_->failure} values %{$self->{results} || {}};
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_->failure;} values %{$self->{"results"} or {};} 0 0 0
Condition0%0/2
$self->{'results'} || {}
l!l
00
MC/DC0%0/1
$self->{'results'} || {}
$self->{'results'}
Truth table0%0/2
A
A= $self->{'results'}
Aresult
11
00
106 0 return 1;
107 }
108  
109 =head2 failure
110  
111 Returns true if any of the results failed or there was an L</error>
112 set.
113  
114 =cut
115  
116 0 ▶sub failure {
Subroutine failure: not called CC=1 SCAR=6.9
Pod documented
117 0 my $self = shift;
118 0 return not $self->success;
119 }
120  
121 1 ▶no Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
122 1 __PACKAGE__->meta->make_immutable(inline_constructor => 0);
123 1 1;
« Jifty/View.pm ↑ Summary Jifty/Script/App.pm »