App/Response.pm

filter: Statementstmt 35.0% 14 / 40 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 42.8% 3 / 7 Podpod 0.0% 0 / 4 totaltotal 29.8% 17 / 57 CC 4 SCAR 14.1
CC
4
Cov
30%
xhr_fix
6.0
new
6.0
field_error
6.0
CRAP 4.1
« App/Request/CGI.pm ↑ Summary App/Presenter.pm »
1 package Web::App::Response;
2 # $Id: Response.pm,v 1.5 2009/03/23 00:36:38 apla Exp $
3  
4 1 ▶use Class::Easy;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Storable ('dclone');
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use HTTP::Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 has 'headers', is => 'rw';
11 1 has 'data';
12 1 has 'presenter', is => 'rw';
13  
14 1 our $template = {
15 headers => HTTP::Headers->new (
16 'Content-Type' => 'text/html; charset=utf-8',
17 'Cache-Control' => 'no-store',
18 ),
19 data => {
20 form => {
21 values => {},
22 errors => {},
23 },
24 },
25 };
26  
27 0 ▶sub xhr_fix {
Subroutine xhr_fix: not called CC=2 SCAR=17.9
Pod undocumented
28 0 my $self = shift;
29 0 my $app = shift;
30 0 my $params = shift;
31
32 0 ▶ return unless $app->request->type eq 'XHR';
Branch: 1 branch
BranchTrueFalseTotal
unless $app->request->type eq "XHR" 0 0 0
33
34 # we need to add fixes for xhr:
35 # 1. set correct presentation
36 # 2. remove redirect header
37
38 0 $app->set_presentation ({type => 'json'});
39
40 0 return;
41 }
42  
43 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
44 0 my $class = shift;
45
46 0 my $self = dclone ($template);
47
48 0 ▶ if ($Class::Easy::DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Class::Easy::DEBUG) 0 0 0
49 0 $self->{data}->{'debug-mode'} = $Class::Easy::DEBUG;
50 }
51
52 0 bless $self, $class;
53
54 0 return $self;
55
56 }
57  
58 0 ▶sub generic_error {
Subroutine generic_error: not called CC=1 SCAR=6.9
Pod undocumented
59 0 my $self = shift;
60 0 my $code = shift;
61
62 0 $self->data->{result} = 'error';
63
64 0 push @{$self->data->{errors}->{generic}}, $code;
65 }
66  
67 0 ▶sub field_error {
Subroutine field_error: not called CC=2 SCAR=17.9
Pod undocumented
68 0 my $self = shift;
69 0 my $field = shift;
70 0 my $code = shift;
71
72 0 my $d = $self->data;
73
74 0 my $fields = $d->{request}->screen->params;
75
76 0 my $field_params = (grep {$_->{name} eq $field} @$fields)[0];
77
78 0 $d->{result} = 'error';
79
80 $d->{errors}->{$field} = [
81 0 ▶ $field_params->{required} ? 'required' : 'optional',
Branch: 1 branch
BranchTrueFalseTotal
$field_params->{'required'} ? : 0 0 0
82 $code
83 ];
84 }
85  
86  
87 1 1;
« App/Request/CGI.pm ↑ Summary App/Presenter.pm »