blib/lib/OpusVL/AppKit/Action/AppKitForm.pm untested

filter: Statementstmt 0.0% 0 / 74 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 107 CC 12 SCAR 46.0
CC
12
Cov
0%
execute
156.0
load_config_file
2.0
process
2.0
CRAP 99.3
1 package OpusVL::AppKit::Action::AppKitForm;
2  
3 ############################################################################################################################
4 # use lines.
5 ############################################################################################################################
6 use Moose;
7 use namespace::autoclean;
8 use MRO::Compat;
9 extends 'Catalyst::Action';
10 use File::ShareDir;
11 use List::MoreUtils qw/uniq/;
12  
13 ############################################################################################################################
14 # Methods
15 ############################################################################################################################
16  
17 sub execute
18 {
19 my $self = shift;
20 my ($controller, $c, @args) = @_;
21  
22 # get the FormFu object ...
23 die("Failed to pull form from controller. Ensure your Controller 'extends' Catalyst::Controller::HTML::FormFu") unless $controller->can('form');
24 my $form = $controller->form;
25
26 # Configure the form to generate IDs automatically
27 $form->auto_id("formfield_%n_%r_%c");
28 # The action attribute should point the path of the config file...
29 my $config_file = $self->attributes->{AppKitForm}->[0];
30  
31 unless ( $controller->appkit_myclass )
32 {
33 die("Failed to load AppKitForm.. no appkit_myclass specified for $controller ");
34 }
35  
36 # build the start of config file path..
37 my $path = File::ShareDir::module_dir( $controller->appkit_myclass ) . '/root/forms/';
38 # ... build the rest of the path..
39 if ( defined $config_file )
40 {
41 $path .= $config_file;
42 }
43 else
44 {
45 $path .= $self->reverse . '.yml';
46 }
47  
48 $c->log->debug("AppKitForm Loading config: $path \n" ) if $c->debug;
49  
50 # .. now get the full path...
51 my $form_file = File::Spec->rel2abs( $path );
52  
53 if ( -r $form_file )
54 {
55 # .. load it..
56 $self->load_config_file ( $c, $form, $form_file );
57 my $new_formfu = $form->can('auto_container_comment_class');
58 if($c->config->{no_formfu_classes})
59 {
60 unless($new_formfu)
61 {
62 $c->log->warn('no_formfu_classes feature will not work without upgrade to HTML::FormFu 1.0');
63 }
64 }
65 else
66 {
67 if($new_formfu)
68 {
69 $form->auto_container_class('%t');
70 $form->auto_container_label_class('label');
71 $form->auto_container_comment_class('comment');
72 $form->auto_comment_class('comment');
73 $form->auto_container_error_class('error');
74 $form->auto_container_per_error_class('error_%s_%t');
75 $form->auto_error_class('error_message error_%s_%t');
76 }
77 }
78
79 my $previous_indicator = $form->indicator;
80 $form->indicator(sub
81 {
82 my $self = shift;
83 my $query = shift;
84 if(uc $form->method eq 'POST') {
85 unless(uc $c->req->method eq 'POST')
86 {
87 # check form is a post, if not return false.
88 return 0;
89 }
90 }
91 if($previous_indicator)
92 {
93 return $query->param($previous_indicator);
94 }
95 else
96 {
97 my @names = uniq grep {defined} map { $_->nested_name } @{ $self->get_fields };
98 return grep { defined $query->param($_) } @names;
99 }
100 });
101  
102 $self->process( $form );
103
104 # .. stash it..
105 $c->stash->{ 'form' } = $form;
106 }
107 else
108 {
109 die("Could not find form config: $form_file ");
110 }
111  
112 # call the next 'excute'...
113 my $r = $self->next::method(@_);
114  
115 return $r;
116 }
117  
118 sub load_config_file
119 {
120 my $self = shift;
121 my $c = shift;
122 my $form = shift;
123 my $form_file = shift;
124  
125 $form->load_config_file ( $form_file );
126 }
127  
128 sub process
129 {
130 my $self = shift;
131 my $form = shift;
132 # this is here so that other classes/roles can hook this method.
133 # .. process it..
134 $form->process;
135 }
136  
137 1;
138  
139 __END__
140  
141 =pod
142  
143 =encoding UTF-8
144  
145 =head1 NAME
146  
147 OpusVL::AppKit::Action::AppKitForm
148  
149 =head1 VERSION
150  
151 version 2.22
152  
153 =head1 SYNOPSIS
154  
155 package TestX::CatalystX::ExtensionA::Controller::ExtensionA
156 sub formpage :Local :AppKitForm("admin/users/userform.yml")
157 {
158 my ($self, $c) = @_;
159 $self->stash->{form}
160 $c->stash->{template} = 'formpage.tt';
161 }
162  
163 =head1 DESCRIPTION
164  
165 When extension plugins for the AppKit are written they often use FormFu. The Confguration file these
166 extentions FormFu bits can be tricky to load, what with all the namespace changes that occur.
167 This action class helps in making things more tidy.
168  
169 Basically this is just uses File::ShareDir (with the 'appkit_myclass' config key) to find the dir and looks
170 for the config file like so './root/forms/<actionname>.yml' .. or if you passed an argument, it will look for
171 './root/forms/ARGUMENT0'
172  
173 =head1 NAME
174  
175 OpusVL::AppKit::Action::AppKitForm - Action class for OpusVL::AppKit FormConfig Loading
176  
177 =head1 SEE ALSO
178  
179 L<Catalyst>
180 L<OpusVL::AppKit::Base::Controller::GUI>
181  
182 =head2 execute
183 Method called when an action is requested that has the 'AppKitForm' attribute.
184  
185 =head1 AUTHOR
186  
187 OpusVL - www.opusvl.com
188  
189 =head1 COPYRIGHT AND LICENSE
190  
191 This software is copyright (c) 2010 by OpusVL - www.opusvl.com.
192  
193 This is free software; you can redistribute it and/or modify it under
194 the same terms as the Perl 5 programming language system itself.
195  
196 =cut