line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CatalystX::Resource::TraitFor::Controller::Resource::Form; |
2
|
|
|
|
|
|
|
$CatalystX::Resource::TraitFor::Controller::Resource::Form::VERSION = '0.03'; |
3
|
9
|
|
|
9
|
|
13796
|
use MooseX::MethodAttributes::Role; |
|
9
|
|
|
|
|
24
|
|
|
9
|
|
|
|
|
83
|
|
4
|
9
|
|
|
9
|
|
85154
|
use MooseX::Types::LoadableClass qw/ LoadableClass /; |
|
9
|
|
|
|
|
27
|
|
|
9
|
|
|
|
|
116
|
|
5
|
9
|
|
|
9
|
|
14079
|
use namespace::autoclean; |
|
9
|
|
|
|
|
23
|
|
|
9
|
|
|
|
|
135
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: handles form related stuff |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
requires qw/ |
10
|
|
|
|
|
|
|
resource_key |
11
|
|
|
|
|
|
|
_msg |
12
|
|
|
|
|
|
|
_redirect |
13
|
|
|
|
|
|
|
/; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has 'form_class' => ( |
17
|
|
|
|
|
|
|
is => 'rw', |
18
|
|
|
|
|
|
|
required => 1, |
19
|
|
|
|
|
|
|
isa => LoadableClass, |
20
|
|
|
|
|
|
|
coerce => 1, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has 'form_template' => ( |
25
|
|
|
|
|
|
|
is => 'ro', |
26
|
|
|
|
|
|
|
predicate => 'has_form_template', |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub form { |
31
|
49
|
|
|
49
|
1
|
1909
|
my ( $self, $c, $activate_fields ) = @_; |
32
|
|
|
|
|
|
|
|
33
|
49
|
|
|
|
|
195
|
my $resource = $c->stash->{ $self->resource_key }; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# activate_form_fields in stash overrides activate_fields from config |
36
|
|
|
|
|
|
|
my $activate_form_fields = |
37
|
|
|
|
|
|
|
exists $c->stash->{activate_form_fields} |
38
|
|
|
|
|
|
|
? $c->stash->{activate_form_fields} |
39
|
49
|
50
|
|
|
|
204
|
: [@$activate_fields]; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $form_attrs_new = |
42
|
49
|
100
|
|
|
|
3266
|
exists $c->stash->{form_attrs_new} ? $c->stash->{form_attrs_new} : {}; |
43
|
|
|
|
|
|
|
my $form_attrs_process = |
44
|
49
|
100
|
|
|
|
4641
|
exists $c->stash->{form_attrs_process} ? $c->stash->{form_attrs_process} : {}; |
45
|
|
|
|
|
|
|
|
46
|
49
|
|
|
|
|
6253
|
my $form = $self->form_class->new(%$form_attrs_new); |
47
|
49
|
|
|
|
|
19600438
|
$form->process( |
48
|
|
|
|
|
|
|
active => $activate_form_fields, |
49
|
|
|
|
|
|
|
item => $resource, |
50
|
|
|
|
|
|
|
params => $c->req->params, |
51
|
|
|
|
|
|
|
posted => ($c->req->method eq 'POST'), |
52
|
|
|
|
|
|
|
%$form_attrs_process, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
49
|
100
|
|
|
|
1354428
|
my $template = $self->has_form_template |
56
|
|
|
|
|
|
|
? $self->form_template # path to tt file |
57
|
|
|
|
|
|
|
: \'[% form.render %]'; # ref to inline template string |
58
|
49
|
|
|
|
|
430
|
$c->stash( template => $template, form => $form ); |
59
|
|
|
|
|
|
|
|
60
|
49
|
100
|
|
|
|
5215
|
return unless $form->validated; |
61
|
|
|
|
|
|
|
|
62
|
24
|
100
|
|
|
|
3800
|
if ( $c->stash->{set_create_msg} ) { |
|
|
50
|
|
|
|
|
|
63
|
11
|
|
|
|
|
940
|
$c->flash( msg => $self->_msg( $c, 'create' ) ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
elsif ( $c->stash->{set_update_msg} ) { |
66
|
13
|
|
|
|
|
1796
|
$c->flash( msg => $self->_msg( $c, 'update' ) ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
24
|
|
|
|
|
117185
|
$self->_redirect($c); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=pod |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=encoding UTF-8 |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 NAME |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
CatalystX::Resource::TraitFor::Controller::Resource::Form - handles form related stuff |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 VERSION |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
version 0.03 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 form_class |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
HTML::FormHandler class to use for this resource. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
e.g.: 'MyApp::Form::Resources' |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 form_template |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
template file for HTML::FormHandler |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
optional, if you don't supply a form_template a stringified version will be used |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 METHODS |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 form |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
handle form validation, configuration of visible fields |
109
|
|
|
|
|
|
|
and setting of notification messages |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 Catalyst stash variables |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 form_attrs_new |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
you can pass attributes to $form->new via $c->stash->{form_attrs_new} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
$c->stash->{form_attrs_new} = { #... }; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 form_attrs_process |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
you can pass attributes to $form->process via $c->stash->{form_attrs_process} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
$c->stash->{form_attrs_process} = { posted => 0 }; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 AUTHOR |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
David Schmidt <davewood@cpan.org> |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
This software is copyright (c) 2011 by David Schmidt. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
134
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |