File Coverage

erecipes/perl/lib/CGI/Ex/Recipes/Add.pm
Criterion Covered Total %
statement 12 26 46.1
branch 0 2 0.0
condition 0 2 0.0
subroutine 4 7 57.1
pod 3 3 100.0
total 19 40 47.5


line stmt bran cond sub pod time code
1             package CGI::Ex::Recipes::Add;
2 1     1   1021 use utf8;
  1         1  
  1         6  
3 1     1   37 use warnings;
  1         2  
  1         24  
4 1     1   5 use strict;
  1         2  
  1         34  
5 1     1   4 use base qw(CGI::Ex::Recipes);
  1         2  
  1         473  
6             our $VERSION = sprintf "%d.%03d", q$Revision 0.001$ =~ /(\d+)/g;
7              
8              
9 0     0 1   sub skip { 0 }
10 0     0 1   sub name_step { 'edit' }
11              
12              
13             sub finalize {
14 0     0 1   my $self = shift;
15 0           my $form = $self->form;
16              
17 0           my $s = "SELECT COUNT(*) FROM recipes WHERE title = ?";
18 0           my ($count) = $self->dbh->selectrow_array($s, {}, $form->{'title'});
19 0 0         if ($count) {
20 0           $self->add_errors(title => 'A recipe by this title already exists');
21 0           return 0;
22             }
23              
24 0           $s = "INSERT INTO recipes (pid, is_category, title, problem, analysis, solution, sortorder, tstamp, date_added)
25             VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
26 0           my $tstamp = $self->now;
27 0   0       $self->dbh->prepare($s)->execute(
28             $form->{'pid'},
29             $form->{'is_category'}||0,
30             $form->{'title'},
31             $form->{'problem'},
32             $form->{'analysis'},
33             $form->{'solution'},
34             $form->{'sortorder'},
35             $tstamp,
36             $tstamp,);
37 0           $self->add_to_form(success => "Recipe added to the database");
38 0           return 1;
39             }
40              
41             1; # End of CGI::Ex::Recipes::Add
42              
43             __END__