-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] : []);
-}
-
-sub delete : Exported {
- return shift->SUPER::delete(@_) if caller ne "Maypole::Model::Base";
- my ( $self, $r ) = @_;
- $_->SUPER::delete for @{ $r->objects || [] };
- $r->objects( [ $self->retrieve_all ] );
- $r->{template} = "list";
- $self->list($r);
-}
-
-sub stringify_column {
- my $class = shift;
- return (
- $class->columns("Stringify"),
- ( grep { /^(name|title)$/i } $class->columns ),
- ( grep { /(name|title)/i } $class->columns ),
- ( grep { !/id$/i } $class->primary_columns ),
- )[0];
-}
-
-sub adopt {
- my ( $self, $child ) = @_;
- $child->autoupdate(1);
- if ( my $col = $child->stringify_column ) {
- $child->columns( Stringify => $col );
- }
-}