lib/OpusVL/AppKit/Action/AppKitForm.pm

filter: Statementstmt 86.3% 63 / 73 Branchbran 54.5% 12 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 33.3% 1 / 3 totaltotal 79.4% 85 / 107 CC 12 SCAR 18.4
CC
12
Cov
79%
execute
10.9
__ANON__
5.2
BEGIN
1.0
CRAP 6.3
« lib/OpusVL/AppKit/RolesFor/Schema/AppKitAuthDB/Result/User.pm ↑ Summary blib/lib/OpusVL/AppKit/LDAPAuth.pm »
1 package OpusVL::AppKit::Action::AppKitForm;
2  
3 ############################################################################################################################
4 # use lines.
5 ############################################################################################################################
6 9 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use MRO::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 extends 'Catalyst::Action';
10 9 ▶use File::ShareDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use List::MoreUtils qw/uniq/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 ############################################################################################################################
14 # Methods
15 ############################################################################################################################
16  
17 sub execute
18 {
19 16 ▶ my $self = shift;
Subroutine execute: called CC=9 SCAR=23.9
Pod documented
20 16 my ($controller, $c, @args) = @_;
21  
22 # get the FormFu object ...
23 16 ▶ die("Failed to pull form from controller. Ensure your Controller 'extends' Catalyst::Controller::HTML::FormFu") unless $controller->can('form');
Branch: 1 branch
BranchTrueFalseTotal
unless $controller->can("form") 0 16 16
24 16 my $form = $controller->form;
25
26 # Configure the form to generate IDs automatically
27 16 $form->auto_id("formfield_%n_%r_%c");
28 # The action attribute should point the path of the config file...
29 16 my $config_file = $self->attributes->{AppKitForm}->[0];
30  
31 16 ▶ unless ( $controller->appkit_myclass )
Branch: 1 branch
BranchTrueFalseTotal
unless ($controller->appkit_myclass) 0 16 16
32 {
33 0 die("Failed to load AppKitForm.. no appkit_myclass specified for $controller ");
34 }
35  
36 # build the start of config file path..
37 16 my $path = File::ShareDir::module_dir( $controller->appkit_myclass ) . '/root/forms/';
38 # ... build the rest of the path..
39 16 ▶ if ( defined $config_file )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config_file) { } 15 1 16
40 {
41 15 $path .= $config_file;
42 }
43 else
44 {
45 1 $path .= $self->reverse . '.yml';
46 }
47  
48 16 ▶ $c->log->debug("AppKitForm Loading config: $path \n" ) if $c->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $c->debug 0 16 16
49  
50 # .. now get the full path...
51 16 my $form_file = File::Spec->rel2abs( $path );
52  
53 16 ▶ if ( -r $form_file )
Branch: 1 branch
BranchTrueFalseTotal
if (-r $form_file) { } 16 0 16
54 {
55 # .. load it..
56 16 $self->load_config_file ( $c, $form, $form_file );
57 16 my $new_formfu = $form->can('auto_container_comment_class');
58 16 ▶ if($c->config->{no_formfu_classes})
Branch: 1 branch
BranchTrueFalseTotal
if ($c->config->{'no_formfu_classes'}) { } 0 16 16
59 {
60 0 ▶ unless($new_formfu)
Branch: 1 branch
BranchTrueFalseTotal
unless ($new_formfu) 0 0 0
61 {
62 0 $c->log->warn('no_formfu_classes feature will not work without upgrade to HTML::FormFu 1.0');
63 }
64 }
65 else
66 {
67 16 ▶ if($new_formfu)
Branch: 1 branch
BranchTrueFalseTotal
if ($new_formfu) 16 0 16
68 {
69 16 $form->auto_container_class('%t');
70 16 $form->auto_container_label_class('label');
71 16 $form->auto_container_comment_class('comment');
72 16 $form->auto_comment_class('comment');
73 16 $form->auto_container_error_class('error');
74 16 $form->auto_container_per_error_class('error_%s_%t');
75 16 $form->auto_error_class('error_message error_%s_%t');
76 }
77 }
78
79 16 my $previous_indicator = $form->indicator;
80 $form->indicator(sub
81 {
82 21 ▶ my $self = shift;
Subroutine __ANON__: called CC=4 SCAR=16.5
83 21 my $query = shift;
84 21 ▶ if(uc $form->method eq 'POST') {
Branch: 1 branch
BranchTrueFalseTotal
if (uc $form->method eq "POST") 21 0 21
85 21 ▶ unless(uc $c->req->method eq 'POST')
Branch: 1 branch
BranchTrueFalseTotal
unless (uc $c->req->method eq "POST") 7 14 21
86 {
87 # check form is a post, if not return false.
88 7 return 0;
89 }
90 }
91 14 ▶ if($previous_indicator)
Branch: 1 branch
BranchTrueFalseTotal
if ($previous_indicator) { } 14 0 14
92 {
93 14 return $query->param($previous_indicator);
94 }
95 else
96 {
97 0 my @names = uniq grep {defined} map { $_->nested_name } @{ $self->get_fields };
98 0 return grep { defined $query->param($_) } @names;
99 }
100 16 });
101  
102 16 $self->process( $form );
103
104 # .. stash it..
105 16 $c->stash->{ 'form' } = $form;
106 }
107 else
108 {
109 0 die("Could not find form config: $form_file ");
110 }
111  
112 # call the next 'excute'...
113 16 my $r = $self->next::method(@_);
114  
115 16 return $r;
116 }
117  
118 sub load_config_file
119 {
120 16 ▶ my $self = shift;
Subroutine load_config_file: called CC=1 SCAR=0.0
Pod undocumented
121 16 my $c = shift;
122 16 my $form = shift;
123 16 my $form_file = shift;
124  
125 16 $form->load_config_file ( $form_file );
126 }
127  
128 sub process
129 {
130 16 ▶ my $self = shift;
Subroutine process: called CC=1 SCAR=0.0
Pod undocumented
131 16 my $form = shift;
132 # this is here so that other classes/roles can hook this method.
133 # .. process it..
134 16 $form->process;
135 }
136  
137 9 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.24
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
« lib/OpusVL/AppKit/RolesFor/Schema/AppKitAuthDB/Result/User.pm ↑ Summary blib/lib/OpusVL/AppKit/LDAPAuth.pm »