| 1 | package HTML::Shakan::Model::Teng; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Mouse; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | with 'HTML::Shakan::Role::Model'; | |||||||||
| 6 | |||||||||||
| 7 | sub fill { | ||||||||||
| 8 | 1 | ▶ | my ($self, $row) = @_; | ||||||||
|
Subroutine
fill: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 9 | 1 | my $columns = $row->get_columns; | |||||||||
| 10 | 1 | ▶ | while (my ($k, $v) = each %$columns) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 11 | 2 | $self->form->fillin_params->{$k} = $v; | |||||||||
| 12 | } | ||||||||||
| 13 | } | ||||||||||
| 14 | |||||||||||
| 15 | sub create { | ||||||||||
| 16 | 1 | ▶ | my ($self, $model, $name) = @_; | ||||||||
|
Subroutine
create: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 17 | 1 | my $row = {}; | |||||||||
| 18 | 1 | my $params = $self->form->params(); | |||||||||
| 19 | 1 | for my $column (@{ $model->schema->get_table($name)->columns() }) { | |||||||||
| 20 | 2 | ▶ | next unless exists $params->{$column}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 1 | $row->{$column} = $params->{$column}; | |||||||||
| 22 | } | ||||||||||
| 23 | 1 | $model->insert($name => $row); | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 0 | ▶ | sub insert { shift->create(@_) } | ||||||||
|
Subroutine
insert: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 27 | |||||||||||
| 28 | sub update { | ||||||||||
| 29 | 1 | ▶ | my ($self, $row) = @_; | ||||||||
|
Subroutine
update: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 30 | 1 | my $dat = {}; | |||||||||
| 31 | 1 | my $columns = $row->get_columns; | |||||||||
| 32 | 1 | my $params = $self->form->params(); | |||||||||
| 33 | 1 | for my $column (keys %$columns) { | |||||||||
| 34 | 2 | ▶ | next unless exists $params->{$column}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 1 | $dat->{$column} = $params->{$column}; | |||||||||
| 36 | } | ||||||||||
| 37 | 1 | $row->update($dat); | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 1 | ▶ | no Mouse; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 42 | __END__ | ||||||||||
| 43 | |||||||||||
| 44 | =head1 NAME | ||||||||||
| 45 | |||||||||||
| 46 | HTML::Shakan::Model::Teng - Teng binding for HTML::Shakan | ||||||||||
| 47 | |||||||||||
| 48 | =head1 SYNOPSIS | ||||||||||
| 49 | |||||||||||
| 50 | # create form object | ||||||||||
| 51 | my $form = HTML::Shakan->new( | ||||||||||
| 52 | request => CGI->new(), | ||||||||||
| 53 | fields => [ | ||||||||||
| 54 | TextField( | ||||||||||
| 55 | name => 'foo', | ||||||||||
| 56 | ), | ||||||||||
| 57 | ], | ||||||||||
| 58 | model => HTML::Shakan::Model::Teng->new() | ||||||||||
| 59 | ); | ||||||||||
| 60 | |||||||||||
| 61 | # fillin_form | ||||||||||
| 62 | $form->model->fill($row); | ||||||||||
| 63 | |||||||||||
| 64 | # insert | ||||||||||
| 65 | $form->model->create($teng => $table); | ||||||||||
| 66 | |||||||||||
| 67 | # update | ||||||||||
| 68 | $form->model->update($row); | ||||||||||
| 69 | |||||||||||
| 70 | =head1 DESCRIPTION | ||||||||||
| 71 | |||||||||||
| 72 | This is L<Teng> binding for L<HTML::Shakan>.You can easy to | ||||||||||
| 73 | insert/fill/update by L<HTML::Shakan>. | ||||||||||
| 74 | |||||||||||
| 75 | =head1 METHODS | ||||||||||
| 76 | |||||||||||
| 77 | =over 4 | ||||||||||
| 78 | |||||||||||
| 79 | =item C<< $form->model->fill($row); >> | ||||||||||
| 80 | |||||||||||
| 81 | fill the $row data to form.$row is instance of row class of Teng. | ||||||||||
| 82 | |||||||||||
| 83 | =item C<< my $row = $form->model->create($teng, $table); >> | ||||||||||
| 84 | |||||||||||
| 85 | insert form data to $table. | ||||||||||
| 86 | |||||||||||
| 87 | =item C<< my $row = $form->model->insert($teng, $table); >> | ||||||||||
| 88 | |||||||||||
| 89 | insert method is synonym of create method. | ||||||||||
| 90 | |||||||||||
| 91 | =item C<< $form->model->update($row); >> | ||||||||||
| 92 | |||||||||||
| 93 | update C<$row> by form data. | ||||||||||
| 94 | |||||||||||
| 95 | =back | ||||||||||
| 96 | |||||||||||
| 97 | =head1 SEE ALSO | ||||||||||
| 98 | |||||||||||
| 99 | L<Teng>, L<HTML::Shakan> | ||||||||||
| 100 | |||||||||||
| 101 | =cut | ||||||||||
| 102 | |||||||||||