Articulate/Response.pm

filter: Statementstmt 87.1% 27 / 31 Branchbran 50.0% 4 / 8 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 70.0% 7 / 10 Podpod 100% 2 / 2 totaltotal 71.6% 43 / 60 CC 7 SCAR 16.1
CC
7
Cov
76%
response
9.7
serialise
2.0
__ANON__
2.0
CRAP 5.0
« Articulate/Routes/TransparentPreviews.pm ↑ Summary Articulate/Routes/TransparentForms.pm »
1 package Articulate::Response;
2 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 10 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 10 ▶use Exporter::Declare;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 default_exports qw(response);
10  
11 =head1 NAME
12  
13 Articulate::Response - represent a response
14  
15 =cut
16  
17 =head1 FUNCTIONS
18  
19 =head3 response
20  
21 =head3 articulate_response
22  
23 my $response = response type => $data;
24  
25 Creates a new response, using the type and data supplied as the respective arguments. Using this constructor, the error code will be 200 unless C<type> is C<error>.
26  
27 =cut
28  
29 sub response {
30 4 ▶ my ( $type, $data ) = @_;
Subroutine response: called CC=7 SCAR=22.7
Pod documented
31 4 ▶ my $http_code =
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'error' ? : 0 4 4
32 $type eq 'error'
33 ? 500
34 : 200;
35 4 ▶ return __PACKAGE__->new(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 4 4
36 {
37 type => $type,
38 http_code => $http_code,
39 }
40 ) unless defined $data;
41 4 ▶ if ( ref $data eq ref {} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data eq ref {}) 4 0 4
42 4 ▶ if ( defined $data->{$type}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{$type} and builtin::blessed($data->{$type}) and $data->{$type}->can("http_code")) 0 4 4
Condition50%3/6
defined $data->{$type} and builtin::blessed($data->{$type}) and $data->{$type}->can("http_code")
!ll&&!rl&&r
400
defined $data->{$type} and builtin::blessed($data->{$type})
!ll&&!rl&&r
130
MC/DC0%0/3
defined $data->{$type} and builtin::blessed($data->{$type}) and $data->{$type}->can("http_code")
defined $data->{$type} builtin::blessed($data->{$type}) $data->{$type}->can("http_code")
Truth table50%2/4
A and B and C
A= defined $data->{$type}B= builtin::blessed($data->{$type})C= $data->{$type}->can("http_code")
ABCresult
0XX0
10X0
1100
1111
43 and blessed $data->{$type}
44 and $data->{$type}->can('http_code') )
45 {
46 0 $http_code = $data->{$type}->http_code;
47 }
48 }
49 4 return __PACKAGE__->new(
50 {
51 type => $type,
52 data => $data,
53 http_code => $http_code,
54 }
55 );
56 }
57  
58 =head1 METHODS
59  
60 =head3 new
61  
62 An unremarkable Moo constructor.
63  
64 =cut
65  
66 =head3 serialise
67  
68 Sends the response to Articulate::Serialisation->serialise.
69  
70 Note: the behaviour of this method may change!
71  
72 =cut
73  
74 sub serialise
75 { # this is convenient as it is probably the next thing which will always be done.
76  
77 # Articulate::Serialisation::serialisation->serialise (shift);
78 0 ▶ shift;
Subroutine serialise: not called CC=1 SCAR=6.9
Pod documented
79 }
80  
81 =head1 ATTRIBUTES
82  
83 =head3 http_code
84  
85 The HTTP response code which best applies to the response. The default is 500.
86  
87 It is not guaranteed that this will be passed to the ultimate client (e.g. a later error may cause a 500; the service may be accessed in a way other than HTTP).
88  
89 =cut
90  
91 has http_code => (
92 is => 'rw',
93 default => 500,
94 4 ▶ coerce => sub { 0 + shift }
Subroutine __ANON__: called CC=1 SCAR=0.0
95 10 );
96  
97 =head3 type
98  
99 The type of response, which will be used by serialisers etc. to determine how to complete processing (e.g. which template to use).
100  
101 =cut
102  
103 has type => (
104 is => 'rw',
105 0 ▶ default => sub { 'error' }
Subroutine __ANON__: not called CC=1 SCAR=6.9
106 10 );
107  
108 =head3 data
109  
110 The actual content of the response, including any metadata. Typically this will be of the form
111  
112 {
113 item => {
114 article => {
115 meta => { ... }
116 content => " ... "
117 }
118 }
119 }
120  
121 =cut
122  
123 has data => (
124 is => 'rw',
125 0 ▶ default => sub { {} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
126 10 );
127  
128 10 1;
« Articulate/Routes/TransparentPreviews.pm ↑ Summary Articulate/Routes/TransparentForms.pm »