File Coverage

erecipes/perl/lib/CGI/Ex/Recipes/Edit.pm
Criterion Covered Total %
statement 15 35 42.8
branch 0 4 0.0
condition 0 2 0.0
subroutine 5 7 71.4
pod 2 2 100.0
total 22 50 44.0


line stmt bran cond sub pod time code
1             package CGI::Ex::Recipes::Edit;
2 1     1   5377 use utf8;
  1         3  
  1         14  
3 1     1   38 use warnings;
  1         10  
  1         33  
4 1     1   6 use strict;
  1         2  
  1         41  
5 1     1   15 use CGI::Ex::Dump qw(debug dex_warn ctrace dex_trace);
  1         2  
  1         116  
6 1     1   5 use base qw(CGI::Ex::Recipes);
  1         2  
  1         521  
7             our $VERSION = '0.03';
8              
9              
10             sub hash_common {
11 0     0 1   my $self = shift;
12 0 0         return {} if $self->ready_validate;
13 0           my $sth = $self->dbh->prepare("SELECT * FROM recipes WHERE id = ?");
14 0           $sth->execute($self->form->{'id'});
15 0           $self->{hash_common} = $sth->fetchrow_hashref;
16 0           $self->{hash_common};
17             }
18              
19              
20             sub finalize {
21 0     0 1   my $self = shift;
22 0           my $form = $self->form;
23 0           my $s = "SELECT COUNT(*) FROM recipes WHERE title = ? AND id != ?";
24 0           my ($count) = $self->dbh->selectrow_array($s, {}, $form->{'title'}, $form->{'id'});
25 0 0         if ($count) {
26 0           $self->add_errors(title => 'A recipe by this title already exists');
27 0           return 0;
28             }
29              
30 0           $s = "UPDATE recipes
31             SET pid = ?, is_category = ?, title = ?, problem = ?, analysis = ?,solution = ?,
32             sortorder = ?, tstamp = ?
33             WHERE id = ?";
34 0   0       $self->dbh->prepare($s)->execute(
35             $form->{'pid'},
36             $form->{'is_category'}||0,
37             $form->{'title'},
38             $form->{'problem'},
39             $form->{'analysis'},
40             $form->{'solution'},
41             $form->{'sortorder'},
42             $self->now,
43             $form->{'id'}
44             );
45 0           $self->add_to_form(success => "Recipe updated in the database");
46             #make so default page displays the category in which this item is
47             #$form->{'id'} = $form->{'pid'};
48 0           $self->set_ready_validate(0);
49            
50             #CGI::Ex::App also has methods that allow for dynamic changing of the path,
51             #so that each step can determine which step to do next
52             #(see the jump, append_path, insert_path, and replace_path methods).
53 0           $self->append_path('view');
54 0           $self->cache->clear;
55 0           return 1;
56             }
57              
58             =pod
59              
60             sub next_step { 'view' }
61              
62             =cut
63              
64             1; # End of CGI::Ex::Recipes::Edit
65              
66             __END__