Recipes/Edit.pm

filter: Statementstmt 45.9% 17 / 37 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 45.2% 24 / 53 CC 4 SCAR 16.7
CC
4
Cov
40%
finalize
12.0
hash_common
6.0
BEGIN
1.0
CRAP 5.3
« Recipes/DBIx.pm ↑ Summary Recipes/Add.pm »
1 package CGI::Ex::Recipes::Edit;
2 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use CGI::Ex::Dump qw(debug dex_warn ctrace dex_trace);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use base qw(CGI::Ex::Recipes);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 our $VERSION = '0.03';
8  
9  
10 0 ▶sub hash_common {
Subroutine hash_common: not called CC=2 SCAR=17.9
Pod documented
11 0 my $self = shift;
12 0 ▶ return {} if $self->ready_validate;
Branch: 1 branch
BranchTrueFalseTotal
if $self->ready_validate 0 0 0
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 0 ▶sub finalize {
Subroutine finalize: not called CC=3 SCAR=24.8
Pod documented
21 0 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 ▶ if ($count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count) 0 0 0
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 $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 0 ▶ $form->{'id'}
Condition0%0/2
$form->{'is_category'} || 0
l!l
00
MC/DC0%0/1
$form->{'is_category'} || 0
$form->{'is_category'}
Truth table0%0/2
A
A= $form->{'is_category'}
Aresult
11
00
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 1; # End of CGI::Ex::Recipes::Edit
65  
66 __END__
« Recipes/DBIx.pm ↑ Summary Recipes/Add.pm »