| 1 | package Wcpancover::Admin; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Mojo::Base 'Mojolicious::Controller'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 0 | ▶ | sub change { shift->render } | ||||||||||||||||||||||||||
|
Subroutine
change: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 0 | ▶ | sub show { | ||||||||||||||||||||||||||
|
Subroutine
show: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 9 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 0 | print STDERR 'Admin::show()',"\n"; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | #my $table = $self->stash->{table}; | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | $self->render; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub save { | ||||||||||||||||||||||||||
|
Subroutine
save: not called CC=16 SCAR=56.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 20 | 0 | my $params = [$self->req->param()]; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | my $table = $self->stash->{table}; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | my $form = $self->form_handler($table); | |||||||||||||||||||||||||||
| 25 | 0 | $form->from_schema($self->schema, $table); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | my $data = {}; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | $data->{$_} = $self->req->param($_) ? $self->req->param($_) : 0 | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | for (@$params); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | for my $param (@$params) { | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ($form->elements->{$param}->{type} eq 'text' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | $data->{$param} = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | $self->req->param($param) ? $self->req->param($param) : ''; | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | elsif ($form->elements->{$param}->{type} eq 'number' ) { | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | $data->{$param} = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | $self->req->param($param) ? $self->req->param($param) : 0; | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | else { | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | $data->{$param} = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | $self->req->param($param) ? $self->req->param($param) : undef; | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | my @elements = @{$form->ordered_elements}; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | my @checkboxes = | ||||||||||||||||||||||||||||
| 50 | 0 | grep { $form->elements->{$_}->{type} eq 'checkbox' } @elements; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | for my $param (@checkboxes) { | |||||||||||||||||||||||||||
| 53 | $data->{$param} = | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | (exists $data->{$param} && $data->{$param} eq 'on') ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $data->{$param} and $data->{$param} eq "on"
MC/DC0%0/2
exists $data->{$param} and $data->{$param} eq "on"
exists $data->{$param}
$data->{$param} eq "on"
Truth table0%0/3
A and B
A= exists $data->{$param}B= $data->{$param} eq "on"
| |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | my $id_field = $form->id_field; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | say STDERR 'Admin::save() $id_field: ',$id_field if $self->app->app_debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if (exists $data->{$id_field} && !$data->{$id_field}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $data->{$id_field} and not $data->{$id_field}
MC/DC0%0/2
exists $data->{$id_field} and not $data->{$id_field}
exists $data->{$id_field}
not $data->{$id_field}
Truth table0%0/3
A and not(B)
A= exists $data->{$id_field}B= not $data->{$id_field}
| |||||||||||||||||||||||||||||
| 60 | 0 | delete $data->{$id_field}; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 0 | ▶ | say STDERR 'Admin::save() $data: ',Dumper($data) if $self->app->app_debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | my $rs = $self->schema->resultset($table); | |||||||||||||||||||||||||||
| 65 | 0 | $rs->update_or_create($data); | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | $self->redirect_to('/admin/show/' . $table); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 1 | 1; | |||||||||||||||||||||||||||