sub do_edit :Exported {
my ($self, $r) = @_;
my $h = CGI::Untaint->new(%{$r->{params}});
+ my $creating = 0;
my ($obj) = @{$r->objects || []};
if ($obj) {
# We have something to edit
$obj->update_from_cgi($h);
} else {
$obj = $self->create_from_cgi($h);
+ $creating++;
}
if (my %errors = $obj->cgi_update_errors) {
# Set it up as it was:
$r->{template_args}{cgi_params} = $r->{params};
$r->{template_args}{errors} = \%errors;
$r->{template} = "edit";
+ undef $obj if $creating; # Couldn't create
} else {
$r->{template} = "view";
}