| HTML-Shakan documentation | Contained in the HTML-Shakan distribution. |
HTML::Shakan::Model::DBIxSkinny - DBIx::Skinny binding for HTML::Shakan
# create form object
my $form = HTML::Shakan->new(
request => CGI->new(),
fields => [
TextField(
name => 'foo',
),
],
model => HTML::Shakan::Model::DBIxSkinny->new()
);
# fillin_form
$form->model->fill($row);
# insert
$form->model->create($skinny => $table);
# update
$form->model->update($row);
This is DBIx::Skinny binding for HTML::Shakan.You can easy to insert/fill/update by HTML::Shakan.
fill the $row data to form.$row is instance of row class of DBIx::Skinny.
insert form data to $table.
insert method is synonym of create method.
update $row by form data.
| HTML-Shakan documentation | Contained in the HTML-Shakan distribution. |
package HTML::Shakan::Model::DBIxSkinny; use Any::Moose; with 'HTML::Shakan::Role::Model'; sub fill { my ($self, $row) = @_; my $columns = $row->get_columns; while (my ($k, $v) = each %$columns) { $self->form->fillin_params->{$k} = $v; } } sub create { my ($self, $model, $name) = @_; my $row = {}; my $params = $self->form->params(); for my $column (@{ $model->schema->schema_info->{$name}->{columns} }) { next unless exists $params->{$column}; $row->{$column} = $params->{$column}; } $model->insert($name => $row); } sub insert { shift->create(@_) } sub update { my ($self, $row) = @_; my $dat = {}; my $columns = $row->get_columns; my $params = $self->form->params(); for my $column (keys %$columns) { next unless exists $params->{$column}; $dat->{$column} = $params->{$column}; } $row->update($dat); } no Any::Moose; __PACKAGE__->meta->make_immutable; __END__