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