File Coverage

blib/lib/RapidApp/Responder/CustomPrompt.pm
Criterion Covered Total %
statement 12 39 30.7
branch 0 30 0.0
condition 0 3 0.0
subroutine 4 7 57.1
pod 0 3 0.0
total 16 82 19.5


line stmt bran cond sub pod time code
1             package RapidApp::Responder::CustomPrompt;
2              
3 6     6   39 use Moose;
  6         13  
  6         39  
4             extends 'RapidApp::Responder';
5              
6 6     6   33694 use RapidApp::Util qw(:all);
  6         12  
  6         2565  
7 6     6   43 use HTML::Entities;
  6         11  
  6         3224  
8              
9             has 'title' => ( is => 'ro', isa => 'Maybe[Str]', default => undef );
10             has 'param_name' => ( is => 'ro', isa => 'Maybe[Str]', default => undef );
11             has 'height' => ( is => 'ro', isa => 'Maybe[Int]', default => undef );
12             has 'width' => ( is => 'ro', isa => 'Maybe[Int]', default => undef );
13             has 'buttons' => ( is => 'ro', isa => 'Maybe[ArrayRef[Str]]', default => undef );
14             has 'buttonIcons' => ( is => 'ro', isa => 'Maybe[HashRef[Str]]', default => undef );
15             has 'items' => ( is => 'ro', isa => 'Maybe[ArrayRef|HashRef]', default => undef );
16             has 'formpanel_cnf' => ( is => 'ro', isa => 'Maybe[HashRef]', default => undef );
17             has 'noCancel' => ( is => 'ro', default => undef );
18             has 'validate' => ( is => 'ro', default => undef );
19             has 'EnterButton' => ( is => 'ro', isa => 'Maybe[Str]', default => undef );
20             has 'EscButton' => ( is => 'ro', isa => 'Maybe[Str]', default => undef );
21             has 'focusField' => ( is => 'ro', isa => 'Maybe[Str]', default => undef );
22              
23             sub customprompt_data {
24 0     0 0   my $self = shift;
25            
26 0           my $data = {};
27 0 0         $data->{title} = $self->title if (defined $self->title);
28 0 0         $data->{param_name} = $self->param_name if (defined $self->param_name);
29 0 0         $data->{height} = $self->height if (defined $self->height);
30 0 0         $data->{width} = $self->width if (defined $self->width);
31 0 0         $data->{buttons} = $self->buttons if (defined $self->buttons);
32 0 0         $data->{buttonIcons} = $self->buttonIcons if (defined $self->buttonIcons);
33 0 0         $data->{items} = $self->items if (defined $self->items);
34 0 0         $data->{formpanel_cnf} = $self->formpanel_cnf if (defined $self->formpanel_cnf);
35 0 0         $data->{noCancel} = $self->noCancel if (defined $self->noCancel);
36 0 0         $data->{validate} = $self->validate if (defined $self->validate);
37 0 0         $data->{EnterButton} = $self->EnterButton if (defined $self->EnterButton);
38 0 0         $data->{EscButton} = $self->EscButton if (defined $self->EscButton);
39 0 0         $data->{focusField} = $self->focusField if (defined $self->focusField);
40              
41 0           return $data;
42             }
43              
44             sub customprompt_json {
45 0     0 0   my $self = shift;
46 0           return RapidApp::JSON::MixedEncoder::encode_json($self->customprompt_data);
47             }
48              
49             sub writeResponse {
50 0     0 0   my ($self, $c)= @_;
51            
52 0           $c->response->header('X-RapidApp-CustomPrompt' => $self->customprompt_json);
53             #$c->response->status(500);
54            
55 0           my $rct= $c->stash->{requestContentType};
56 0 0 0       if ($rct eq 'text/x-rapidapp-form-response' || $rct eq 'JSON') {
57 0           $c->stash->{json}= { success => \0 };
58 0           $c->view('RapidApp::JSON')->process($c);
59             }
60             else {
61 0 0         unless (length($c->response->body) > 0) {
62 0           $c->response->content_type('text/plain; charset=utf-8');
63 0           $c->response->body("More user input was needed to complete your request, but we can only send prompts through dynamic javascript requests");
64             }
65             }
66             }
67              
68 6     6   42 no Moose;
  6         18  
  6         32  
69             __PACKAGE__->meta->make_immutable;
70             1;