Design/Controller/Flower.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 55 CC 2 SCAR 11.0
CC
2
Cov
0%
process
6.0
format_details
2.0
format_errors
2.0
CRAP 3.0
1 package WWW::Garden::Design::Controller::Flower;
2  
3 use Mojo::Base 'Mojolicious::Controller';
4  
5 use Date::Simple;
6  
7 use Moo;
8  
9 use WWW::Garden::Design::Util::ValidateForm;
10  
11 our $VERSION = '0.97';
12  
13 # -----------------------------------------------
14  
15 sub format_details
16 {
17 my($self, $item) = @_;
18  
19 $self -> app -> log -> debug('Flower.format_details(...)');
20  
21 my($html) = "<tr>\n";
22  
23 for my $name (qw/common_name scientific_name aliases height width/)
24 {
25 $html .= "<td class = 'generic_border'>$$item{$name}</td>\n";
26 }
27  
28 $html .= "</tr>\n";
29  
30 return $html;
31  
32 } # End of format_details.
33  
34 # -----------------------------------------------
35  
36 sub format_errors
37 {
38 my($self, $params) = @_;
39  
40 $self -> app -> log -> debug('Flower.format_errors(...)');
41  
42 my($html) = '';
43  
44 my($errors);
45  
46 for my $name (sort keys %{$$params{errors} })
47 {
48 $errors = $$params{errors}{$name};
49 $html .= <<EOS;
50 <tr>
51 <td class = 'generic_border'>$name</td>
52 <td class = 'generic_border'>$$errors[0]</td>
53 <td class = 'generic_border'>$$errors[1]</td>
54 <td class = 'generic_border'>$$errors[2]</td>
55 </tr>
56 EOS
57 }
58  
59 return $html;
60  
61 } # End of format_errors.
62  
63 # -----------------------------------------------
64 # https://github.com/kraih/mojo/wiki/Request-data.
65  
66 sub process
67 {
68 my($self) = @_;
69  
70 $self -> app -> log -> debug('Flower.process()');
71  
72 my($defaults) = $self -> app -> defaults;
73 my($validator) = WWW::Garden::Design::Util::ValidateForm -> new;
74 my($params) = $validator -> flower_details($self, $defaults);
75  
76 if ($$params{success})
77 {
78 # $$defaults{db} -> add_flower($params);
79  
80 $self -> stash(error => undef);
81 $self -> stash(details => $self -> format_details($params) );
82 $self -> stash(message => $$params{message});
83 }
84 else
85 {
86 $self -> stash(error => $self -> format_errors($params) );
87 $self -> stash(details => undef);
88 $self -> stash(message => $$params{message});
89 $self -> app -> log -> error($$params{message});
90 }
91  
92 $self -> render;
93  
94 } # End of process.
95  
96 # -----------------------------------------------
97  
98 1;
99  
100 =pod
101  
102 =head1 NAME
103  
104 WWW::Garden::Design::Controller::Flower - Manage the 'flowers' database
105  
106 =head1 Machine-Readable Change Log
107  
108 The file Changes was converted into Changelog.ini by L<Module::Metadata::Changes>.
109  
110 =head1 Version Numbers
111  
112 Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions.
113  
114 =head1 Repository
115  
116 L<https://github.com/ronsavage/WWW-Garden-Design>
117  
118 =head1 Support
119  
120 Email the author, or log a bug on RT:
121  
122 L<https://rt.cpan.org/Public/Dist/Display.html?Name=WWW::Garden::Design>.
123  
124 =head1 Author
125  
126 L<WWW::Garden::Design> was written by Ron Savage I<E<lt>ron@savage.net.auE<gt>> in 2014.
127  
128 My homepage: L<https://savage.net.au/>.
129  
130 =head1 Copyright
131  
132 Australian copyright (c) 2018, Ron Savage.
133  
134 All Programs of mine are 'OSI Certified Open Source Software';
135 you can redistribute them and/or modify them under the terms of
136 The Perl License, a copy of which is available at:
137 http://dev.perl.org/licenses/
138  
139 =cut