1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
package Catalyst::Model::CDBI::CRUD;
use strict;
use base 'Catalyst::Model::CDBI';
use Class::DBI::AsForm;
use Class::DBI::FromForm;
use Class::DBI::Plugin::RetrieveAll;
our $VERSION = '0.04';
=head1 NAME
Catalyst::Model::CDBI::CRUD - CRUD CDBI Model Class
=head1 SYNOPSIS
# lib/MyApp/Model/CDBI.pm
package MyApp::Model::CDBI;
use base 'Catalyst::Model::CDBI::CRUD';
__PACKAGE__->config(
dsn => 'dbi:SQLite2:/tmp/myapp.db',
relationships => 1
);
1;
# lib/MyApp.pm
package MyApp;
use Catalyst 'FormValidator';
__PACKAGE__->config(
name => 'My Application',
root => '/home/joeuser/myapp/root'
);
sub table : Global {
my ( $self, $c ) = @_;
$c->form( optional => [ MyApp::Model::CDBI::Table->columns
] ); #see Data::FormValidator
$c->forward('MyApp::Model::CDBI::Table');
}
sub end : Private {
$c->forward('MyApp::V::TT');
}
1;
=head1 DESCRIPTION
This is a subclass of C<Catalyst::Model::CDBI> with additional CRUD
methods. Don't forget to copy the base templates to config->root!
*NOTE* This module has been deprecated. See BUGS section below!
=head2 METHODS
=head3 add
Does nothing by default.
=cut
sub add { }
=head3 destroy
Deletes a L<Class::DBI> object.
=cut
sub destroy {
my ( $self, $c ) = @_;
$c->stash->{item}->delete;
$c->res->redirect('../list');
}
=head3 do_add
Creates a new L<Class::DBI> object from $c->form.
=cut
sub do_add {
my ( $self, $c ) = @_;
$self->create_from_form( $c->form );
$c->res->redirect('list');
}
=head3 do_edit
Updates a L<Class::DBI> object from $c->form.
=cut
sub do_edit {
my ( $self, $c ) = @_;
$c->stash->{item}->update_from_form( $c->form );
$c->stash->{template} = 'edit';
}
=head3 edit
Does nothing by default.
=cut
sub edit { }
=head3 list
Does nothing by default.
=cut
sub list { }
=head3 process
Dispatches CRUD request to methods.
=cut
sub process {
my $self = shift;
my $c = shift;
my $method = shift || 'list';
$c->stash->{item} = $self->retrieve( $_[0] ) if defined( $_[0] );
$c->stash->{template} = $method;
$c->stash->{class} = ref $self || $self;
$self->$method( $c, @_ ) if $self->can($method);
}
=head3 view
Does nothing by default.
=cut
sub view { }
=head1 BUGS
This module is no longer supported by the Catalyst developers. We keep it
indexed for the sake of existing users, but highly recommend new users to
look at L<Catalyst::Helper::Controller::Scaffold>
=head1 SEE ALSO
L<Catalyst>, L<Catalyst::Model::CDBI>
=head1 AUTHOR
Sebastian Riedel, C<sri@cpan.org>
=head1 COPYRIGHT
This program is free software, you can redistribute it and/or modify it under
the same terms as Perl itself.
=cut
1;
|