for my $subclass (@{$config->{classes}}) {
no strict 'refs';
push @{$subclass."::ISA"}, $class->config->{model};
+ $config->{model}->adopt($subclass)
+ if $config->{model}->can("adopt");
}
$class->view_object($class->config->{view}->new);
$class->init_done(1);
$self->{action} = shift @pi;
$self->{args} = \@pi;
- $self->{params} = $self->{ar}->content;
+ $self->{params} = { $self->{ar}->content };
}
sub is_applicable {
return $self->retrieve(shift @{$r->{args}});
}
+sub edit :Exported {
+ my ($self, $r) = @_;
+ return $self->retrieve(shift @{$r->{args}});
+}
+
+sub do_edit { die "This is an abstract method" }
+
sub list :Exported {
my ($self, $r) = @_;
return $self->retrieve_all;
use base 'Apache::MVC::Model::Base';
use Class::DBI::AsForm;
use Class::DBI::FromCGI;
+use CGI::Untaint;
sub description { "A poorly defined class" }
sub column_names { my $class = shift; map { $_ => ucfirst $_ } $class->columns }
+sub do_edit :Exported {
+ my ($self, $r) = @_;
+ my $h = CGI::Untaint->new(%{$r->{params}});
+ my $obj;
+ if (@{$r->{args}}) {
+ # We have something to edit
+ $obj = $self->retrieve($r->{args}[0]);
+ $obj->update_from_cgi($h);
+ warn "Updating an object ($obj) with ".Dumper($h); use Data::Dumper;
+ } else {
+ $obj = $self->create_from_cgi($h);
+ }
+ if (my %errors = $obj->cgi_update_errors) {
+ # Set it up as it was:
+ warn "There were errors: ".Dumper(\%errors)."\n";
+ $r->{template_args}{cgi_params} = \%params;
+ $r->{template_args}{errors} = \%errors;
+ $r->{template} = "edit";
+ } else {
+ $r->{template} = "view";
+ }
+ return $obj;
+}
+
+sub adopt {
+ my ($self, $child) = @_;
+ $child->autoupdate(1);
+ $child->columns( Stringify => qw/ name / );
+}
+
1;