blib/lib/HTML/Shakan/Model/DBIxSkinny.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 52 CC 3 SCAR 12.8
CC
3
Cov
0%
create
6.0
update
6.0
fill
2.0
CRAP 3.6
1 package HTML::Shakan::Model::DBIxSkinny;
2 use strict;
3 use warnings;
4 use Mouse;
5 with 'HTML::Shakan::Role::Model';
6  
7 sub fill {
8 my ($self, $row) = @_;
9 my $columns = $row->get_columns;
10 while (my ($k, $v) = each %$columns) {
11 $self->form->fillin_params->{$k} = $v;
12 }
13 }
14  
15 sub create {
16 my ($self, $model, $name) = @_;
17 my $row = {};
18 my $params = $self->form->params();
19 for my $column (@{ $model->schema->schema_info->{$name}->{columns} }) {
20 next unless exists $params->{$column};
21 $row->{$column} = $params->{$column};
22 }
23 $model->insert($name => $row);
24 }
25  
26 sub insert { shift->create(@_) }
27  
28 sub update {
29 my ($self, $row) = @_;
30 my $dat = {};
31 my $columns = $row->get_columns;
32 my $params = $self->form->params();
33 for my $column (keys %$columns) {
34 next unless exists $params->{$column};
35 $dat->{$column} = $params->{$column};
36 }
37 $row->update($dat);
38 }
39  
40 no Mouse;
41 __PACKAGE__->meta->make_immutable;
42 __END__
43  
44 =head1 NAME
45  
46 HTML::Shakan::Model::DBIxSkinny - DBIx::Skinny 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::DBIxSkinny->new()
59 );
60  
61 # fillin_form
62 $form->model->fill($row);
63  
64 # insert
65 $form->model->create($skinny => $table);
66  
67 # update
68 $form->model->update($row);
69  
70 =head1 DESCRIPTION
71  
72 This is L<DBIx::Skinny> 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 $form->model->fill($row);
80  
81 fill the $row data to form.$row is instance of row class of DBIx::Skinny.
82  
83 =item my $row = $form->model->create($skinny, $table);
84  
85 insert form data to $table.
86  
87 =item my $row = $form->model->insert($skinny, $table);
88  
89 insert method is synonym of create method.
90  
91 =item $form->model->update($row);
92  
93 update $row by form data.
94  
95 =back
96  
97 =head1 SEE ALSO
98  
99 L<DBIx::Skinny>, L<HTML::Shakan>
100  
101 =cut
102