| 1 | package App::ZofCMS::Plugin::CRUD; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '1.001010'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use DBI; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use HTML::Template; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use base 'App::ZofCMS::Plugin::Base'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub _key { 'plug_crud' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_key: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub _defaults { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_defaults: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | table => 'products', | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | file_dir => 'files', | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | can => 'CRUDL', | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | no_time_sort => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | opt => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | RaiseError => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | AutoCommit => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | mysql_enable_utf8 => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # These are plug's parameters, but with no defaults | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # dsn => 'DBI:mysql:database=zofdb;host=localhost', | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # user => db_login | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # pass => db_pass | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # opt => db_opt | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # items => CRUD items | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # list_sub => # sub for processing the list of output items | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub _do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_do: not called CC=21 SCAR=61.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my ( $self, $conf, $t, $q, $config ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | unless $conf->{items} and @{ $conf->{items} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$conf->{"items"} and @{$conf->{"items"} or [];}
$conf->{'items'} || []
MC/DC0%0/2
$conf->{"items"} and @{$conf->{"items"} or [];}
$conf->{"items"}
@{$conf->{"items"} or [];}
MC/DC0%0/1
$conf->{'items'} || []
$conf->{'items'}
Truth table0%0/3
A and B
A= $conf->{"items"}B= @{$conf->{"items"} or [];}
Truth table0%0/2
A
A= $conf->{'items'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ( ref $conf->{can} eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $conf->{can} = $conf->{can}->( $t, $q, $config ); | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | $conf->{can} = { | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | map +( $_ => 1 ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | grep /^[crudl]$/, map lc, split //, $conf->{can} | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | for ( keys %{ $conf->{can} } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $t->{t}{"crud_can_$_"} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | @$self{ qw/CONF T Q CONFIG/ } = ( $conf, $t, $q, $config ); | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | croak "Cannot have backticK(`) character in `table` parameter" | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if $conf->{table} =~ /`/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | croak "Cannot have backticK(`) character in `order_by` parameter" | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if $conf->{order_by} =~ /`/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $self->_prepare_items; | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ( $q->{crud_update_save} and $conf->{can}{u} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/3
$q->{"crud_update_save"} and $conf->{"can"}{"u"}
MC/DC0%0/2
$q->{"crud_update_save"} and $conf->{"can"}{"u"}
$q->{"crud_update_save"}
$conf->{"can"}{"u"}
Truth table0%0/3
A and B
A= $q->{"crud_update_save"}B= $conf->{"can"}{"u"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $self->_process_UPDATE_SAVE; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ▶ | elsif ( $q->{crud_update} and $conf->{can}{u} ) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$q->{"crud_update"} and $conf->{"can"}{"u"}
MC/DC0%0/2
$q->{"crud_update"} and $conf->{"can"}{"u"}
$q->{"crud_update"}
$conf->{"can"}{"u"}
Truth table0%0/3
A and B
A= $q->{"crud_update"}B= $conf->{"can"}{"u"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $self->_process_UPDATE_LOAD; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ▶ | elsif ( $q->{crud_delete} and $conf->{can}{d} ) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$q->{"crud_delete"} and $conf->{"can"}{"d"}
MC/DC0%0/2
$q->{"crud_delete"} and $conf->{"can"}{"d"}
$q->{"crud_delete"}
$conf->{"can"}{"d"}
Truth table0%0/3
A and B
A= $q->{"crud_delete"}B= $conf->{"can"}{"d"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $self->_process_DELETE; | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ▶ | elsif ( $q->{crud_create} and $conf->{can}{c} ) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$q->{"crud_create"} and $conf->{"can"}{"c"}
MC/DC0%0/2
$q->{"crud_create"} and $conf->{"can"}{"c"}
$q->{"crud_create"}
$conf->{"can"}{"c"}
Truth table0%0/3
A and B
A= $q->{"crud_create"}B= $conf->{"can"}{"c"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | $self->_process_CREATE; | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ( $conf->{can}{c} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
$conf->{"can"}{"c"} and not $q->{"crud_update"} and not $q->{"crud_update_save"}
$conf->{"can"}{"c"} and not $q->{"crud_update"}
MC/DC0%0/3
$conf->{"can"}{"c"} and not $q->{"crud_update"} and not $q->{"crud_update_save"}
$conf->{"can"}{"c"}
not $q->{"crud_update"}
not $q->{"crud_update_save"}
Truth table0%0/4
A and not(B) and not(C)
A= $conf->{"can"}{"c"}B= not $q->{"crud_update"}C= not $q->{"crud_update_save"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | and not $q->{crud_update} | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | and not $q->{crud_update_save} | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $t->{t}{crud_form} = $self->_create_CU_form('yes_is_create_form'); | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | elsif ( $conf->{can}{u} ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $t->{t}{crud_form} = $self->_create_CU_form; | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | $t->{t}{crud_list} = $self->_create_list | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if $conf->{can}{l}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub _process_UPDATE_SAVE { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_UPDATE_SAVE: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | for ( grep !$_->{el_auto_set} && !$_->{el_file}, | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_->{'el_auto_set'} || $_->{'el_file'}
MC/DC0%0/2
$_->{'el_auto_set'} || $_->{'el_file'}
$_->{'el_auto_set'}
$_->{'el_file'}
Truth table0%0/3
A || B
A= $_->{'el_auto_set'}B= $_->{'el_file'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | @{ $self->{ITEMS} || [] } | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'ITEMS'} || []
MC/DC0%0/1
$self->{'ITEMS'} || []
$self->{'ITEMS'}
Truth table0%0/2
A
A= $self->{'ITEMS'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | next if $_->{optional}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | push @errors, +{ error => "Parameter '$_->{text}' must be specified" } | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | unless defined $_->{value} and length $_->{value}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $_->{"value"} and length $_->{"value"}
MC/DC0%0/2
defined $_->{"value"} and length $_->{"value"}
defined $_->{"value"}
length $_->{"value"}
Truth table0%0/3
A and B
A= defined $_->{"value"}B= length $_->{"value"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ( @errors ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $self->{FORM_ERRORS} = \@errors; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $self->_update_UPDATE_in_the_db; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub _update_UPDATE_in_the_db { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_update_UPDATE_in_the_db: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | my %items = map +( @$_{qw/name value/} ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | grep !$_->{el_auto_set} && !$_->{el_file}, @{ $self->{ITEMS} }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_->{'el_auto_set'} || $_->{'el_file'}
MC/DC0%0/2
$_->{'el_auto_set'} || $_->{'el_file'}
$_->{'el_auto_set'}
$_->{'el_file'}
Truth table0%0/3
A || B
A= $_->{'el_auto_set'}B= $_->{'el_file'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | $self->_dbh->do( | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | "UPDATE `$self->{CONF}{table}` SET " . | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | join(',', map "`$_` = ?", keys %items ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | . ' WHERE `crud_id` = ?', | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | values %items, | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | $self->{Q}{crud_id}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | $self->{UPDATE_SUCCESS} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | sub _process_UPDATE_LOAD { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_UPDATE_LOAD: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | my $item = ($self->_dbh->selectall_arrayref( | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 'SELECT * FROM `' . $self->{CONF}{table}. '` WHERE `crud_id` = ?', | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | { Slice => {} }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | $self->{Q}{crud_id}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | ) || [])->[0] | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->_dbh->selectall_arrayref('SELECT * FROM `' . $self->{'CONF'}{'table'} . '` WHERE `crud_id` = ?', {'Slice', {}}, $self->{'Q'}{'crud_id'}) || []
MC/DC0%0/1
$self->_dbh->selectall_arrayref('SELECT * FROM `' . $self->{'CONF'}{'table'} . '` WHERE `crud_id` = ?', {'Slice', {}}, $self->{'Q'}{'crud_id'}) || []
$self->_dbh->selectall_arrayref('SELECT * FROM `' . $self->{'CONF'}{'table'} . '` WHERE `crud_id` = ?', {'Slice', {}}, $self->{'Q'}{'crud_id'})
Truth table0%0/2
A
A= $self->_dbh->selectall_arrayref('SELECT * FROM `' . $self->{'CONF'}{'table'} . '` WHERE `crud_id` = ?', {'Slice', {}}, $self->{'Q'}{'crud_id'})
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | or return $self->_set_error(q|Couldn't find the item to update|); | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | for ( @{ $self->{ITEMS} || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'ITEMS'} || []
MC/DC0%0/1
$self->{'ITEMS'} || []
$self->{'ITEMS'}
Truth table0%0/2
A
A= $self->{'ITEMS'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $_->{value} = $item->{ $_->{name} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub _create_list { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_list: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my $is_do_sort_by_time = grep $_->{name} eq 'time', @{ $self->{ITEMS} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | $is_do_sort_by_time = 0 | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if $self->{CONF}{no_time_sort}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | my $db_items = $self->_dbh->selectall_arrayref( | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | 'SELECT * FROM `' . $self->{CONF}{table} . '`' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->_dbh->selectall_arrayref('SELECT * FROM `' . $self->{'CONF'}{'table'} . '`' . ($is_do_sort_by_time ? ' ORDER BY `time`+0 DESC' : ''), {'Slice', {}}) || []
MC/DC0%0/1
$self->_dbh->selectall_arrayref('SELECT * FROM `' . $self->{'CONF'}{'table'} . '`' . ($is_do_sort_by_time ? ' ORDER BY `time`+0 DESC' : ''), {'Slice', {}}) || []
$self->_dbh->selectall_arrayref('SELECT * FROM `' . $self->{'CONF'}{'table'} . '`' . ($is_do_sort_by_time ? ' ORDER BY `time`+0 DESC' : ''), {'Slice', {}})
Truth table0%0/2
A
A= $self->_dbh->selectall_arrayref('SELECT * FROM `' . $self->{'CONF'}{'table'} . '`' . ($is_do_sort_by_time ? ' ORDER BY `time`+0 DESC' : ''), {'Slice', {}})
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | . ( $is_do_sort_by_time ? ' ORDER BY `time`+0 DESC' : '' ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | { Slice => {} }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | ) || [] ; | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $Dt = HTML::Template->new_scalar_ref( | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | \(_get_D_form_template()), | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | die_on_bad_params => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $Dt->param( page => $self->{Q}{page}, ); | |||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $Dt = $Dt->output; | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $Ut = HTML::Template->new_scalar_ref( | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | \(_get_U_form_template()), | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | die_on_bad_params => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $Ut->param( page => $self->{Q}{page}, ); | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $Ut = $Ut->output; | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | my $conf = $self->{CONF}; | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | for ( @$db_items ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | $_->{crud_can_u} = $conf->{can}{u}; | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $_->{crud_can_d} = $conf->{can}{d}; | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | $_->{crud_can_ud} = $_->{crud_can_u} || $_->{crud_can_d}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_->{'crud_can_u'} || $_->{'crud_can_d'}
MC/DC0%0/2
$_->{'crud_can_u'} || $_->{'crud_can_d'}
$_->{'crud_can_u'}
$_->{'crud_can_d'}
Truth table0%0/3
A || B
A= $_->{'crud_can_u'}B= $_->{'crud_can_d'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ( $_->{crud_d_form} = $Dt ) | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | =~ s/\[<<ITEM:ID>>]/$_->{crud_id}/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ( $_->{crud_u_form} = $Ut ) | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | =~ s/\[<<ITEM:ID>>]/$_->{crud_id}/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | if ( ref $self->{CONF}{list_sub} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $self->{CONF}{list_sub}->( $db_items, $self->{T}, $self->{Q} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | if ( @$db_items ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $self->{T}{t}{crud_has_items} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | $self->{T}{t}{crud_items} = $db_items; | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | sub _process_DELETE { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_DELETE: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | ### Delete all the files, if we have any | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | my @file_items = grep $_->{el_file}, @{ $self->{ITEMS} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'ITEMS'} || []
MC/DC0%0/1
$self->{'ITEMS'} || []
$self->{'ITEMS'}
Truth table0%0/2
A
A= $self->{'ITEMS'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | if ( @file_items ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | my $item = ($self->_dbh->selectall_arrayref( | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 'SELECT * FROM `' . $self->{CONF}{table}. '` WHERE `crud_id` = ?', | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | { Slice => {} }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | $self->{Q}{crud_id}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | ) || [])->[0] | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->_dbh->selectall_arrayref('SELECT * FROM `' . $self->{'CONF'}{'table'} . '` WHERE `crud_id` = ?', {'Slice', {}}, $self->{'Q'}{'crud_id'}) || []
MC/DC0%0/1
$self->_dbh->selectall_arrayref('SELECT * FROM `' . $self->{'CONF'}{'table'} . '` WHERE `crud_id` = ?', {'Slice', {}}, $self->{'Q'}{'crud_id'}) || []
$self->_dbh->selectall_arrayref('SELECT * FROM `' . $self->{'CONF'}{'table'} . '` WHERE `crud_id` = ?', {'Slice', {}}, $self->{'Q'}{'crud_id'})
Truth table0%0/2
A
A= $self->_dbh->selectall_arrayref('SELECT * FROM `' . $self->{'CONF'}{'table'} . '` WHERE `crud_id` = ?', {'Slice', {}}, $self->{'Q'}{'crud_id'})
| |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | or return $self->_set_error(q|Couldn't find the item to delete|); | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | for ( map $_->{name}, @file_items ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | unlink $item->{ $_ }; | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | $self->_dbh->do( | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 'DELETE FROM `' . $self->{CONF}{table} . '` WHERE `crud_id` = ?', | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | $self->{Q}{crud_id}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | $self->{T}{t}{crud_success_message} | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | = '<p class="success-message">Item was successfully deleted.</p>'; | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | sub _set_error { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_error: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my $error = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $self->{T}{t}{crud_error} = qq|<p class="error">$error</p>|; | |||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | sub _process_CREATE { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_CREATE: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | for ( grep !$_->{el_auto_set}, @{ $self->{ITEMS} || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'ITEMS'} || []
MC/DC0%0/1
$self->{'ITEMS'} || []
$self->{'ITEMS'}
Truth table0%0/2
A
A= $self->{'ITEMS'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | next if $_->{optional}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | push @errors, +{ error => "Parameter '$_->{text}' must be specified" } | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | unless defined $_->{value} and length $_->{value}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $_->{"value"} and length $_->{"value"}
MC/DC0%0/2
defined $_->{"value"} and length $_->{"value"}
defined $_->{"value"}
length $_->{"value"}
Truth table0%0/3
A and B
A= defined $_->{"value"}B= length $_->{"value"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | if ( @errors ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | $self->{FORM_ERRORS} = \@errors; | |||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | for my $item ( | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$_->{'el_file'} && defined $self->{'Q'}{$_->{'name'}} && length $self->{'Q'}{$_->{'name'}}
$_->{"el_file"} and defined $self->{"Q"}{$_->{"name"}}
MC/DC0%0/3
$_->{'el_file'} && defined $self->{'Q'}{$_->{'name'}} && length $self->{'Q'}{$_->{'name'}}
$_->{"el_file"}
defined $self->{"Q"}{$_->{"name"}}
length $self->{'Q'}{$_->{'name'}}
Truth table0%0/4
A and B && C
A= $_->{"el_file"}B= defined $self->{"Q"}{$_->{"name"}}C= length $self->{'Q'}{$_->{'name'}}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | grep $_->{el_file} | ||||||||||||||||||||||||||||||||||||||||||||||
| 249 | && defined $self->{Q}{ $_->{name} } | ||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | && length $self->{Q}{ $_->{name} }, @{ $self->{ITEMS} || [] } | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'ITEMS'} || []
MC/DC0%0/1
$self->{'ITEMS'} || []
$self->{'ITEMS'}
Truth table0%0/2
A
A= $self->{'ITEMS'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | push @errors, grep defined, $self->_process_file_upload( $item ); | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if ( @errors ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | $self->{FORM_ERRORS} = \@errors; | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | $self->_insert_CREATE_into_db; | |||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | sub _process_file_upload { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_file_upload: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my $item = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $cgi = $self->{CONFIG}{cgi}; | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my $fh = $cgi->upload( $item->{name} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | if ( not $fh and $cgi->cgi_error ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $fh and $cgi->cgi_error
MC/DC0%0/2
not $fh and $cgi->cgi_error
not $fh
$cgi->cgi_error
Truth table0%0/3
not(A) and B
A= not $fhB= $cgi->cgi_error
| |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | return +{ error => 'File upload error: ' . $cgi->cgi_error }; | |||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | return +{ error => q|File upload error (no error message available)| } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | unless $fh; | ||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ( my $filename = $item->{value} ) =~ s/[^\w.-]/_/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | while ( -e File::Spec->catdir( $self->{CONF}{file_dir}, $filename ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $filename = "_$filename"; | |||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | $filename = File::Spec->catdir( $self->{CONF}{file_dir}, $filename ); | |||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | return +{ error => "Failed to open local file $filename [$!]" } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | unless open my $fh_out, '>', $filename; | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | seek $fh, 0, 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | binmode $fh; | |||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | binmode $fh_out; | |||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | local $/ = \1024; | |||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | while ( <$fh> ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | print $fh_out $_; | |||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | close $fh_out; | |||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $item->{value} = $filename; | |||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | sub _insert_CREATE_into_db { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_insert_CREATE_into_db: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | my %items = map +( @$_{qw/name value/} ), @{ $self->{ITEMS} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | $self->_dbh->do( | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | "INSERT INTO `$self->{CONF}{table}` (" . | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | join(',', map "`$_`", keys %items ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | . ') VALUES (' . | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | join(', ', ('?') x (keys %items) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 317 | . ')', | ||||||||||||||||||||||||||||||||||||||||||||||
| 318 | undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | values %items, | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $self->{CREATE_SUCCESS} = 1 | |||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | sub _create_CU_form { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_CU_form: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | my $is_create = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my $ht = HTML::Template->new_scalar_ref( \(_get_CU_form_template()), | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | die_on_bad_params => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | my @items = @{ $self->{ITEMS} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'ITEMS'} || []
MC/DC0%0/1
$self->{'ITEMS'} || []
$self->{'ITEMS'}
Truth table0%0/2
A
A= $self->{'ITEMS'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | $ht->param( | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | is_create => $is_create, | ||||||||||||||||||||||||||||||||||||||||||||||
| 337 | id => $self->{Q}{crud_id}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | page => $self->{Q}{dir} . $self->{Q}{page}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | has_files => scalar( grep $_->{el_file}, @items ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 340 | elements => [ grep !$_->{el_auto_set}, @items ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 341 | create_success => $self->{CREATE_SUCCESS}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 342 | update_success => $self->{UPDATE_SUCCESS}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | hide_form => ($self->{CREATE_SUCCESS} || $self->{UPDATE_SUCCESS}), | ||||||||||||||||||||||||||||||||||||||||||||||
| 344 | ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | @{ $self->{FORM_ERRORS} || [] } | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'FORM_ERRORS'} || []
MC/DC0%0/1
$self->{'FORM_ERRORS'} || []
$self->{'FORM_ERRORS'}
Truth table0%0/2
A
A= $self->{'FORM_ERRORS'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 346 | ? ( errors => $self->{FORM_ERRORS}, ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | : (), | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{'CREATE_SUCCESS'} || $self->{'UPDATE_SUCCESS'}
MC/DC0%0/2
$self->{'CREATE_SUCCESS'} || $self->{'UPDATE_SUCCESS'}
$self->{'CREATE_SUCCESS'}
$self->{'UPDATE_SUCCESS'}
Truth table0%0/3
A || B
A= $self->{'CREATE_SUCCESS'}B= $self->{'UPDATE_SUCCESS'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 349 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | return $ht->output; | |||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | sub _prepare_items { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prepare_items: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $self->{ITEMS} = $self->{CONF}{items}; | |||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | for ( @{ $self->{ITEMS} || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'ITEMS'} || []
MC/DC0%0/1
$self->{'ITEMS'} || []
$self->{'ITEMS'}
Truth table0%0/2
A
A= $self->{'ITEMS'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | unless ( ref ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | $_ = +{ $_ => 'text' }, | |||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | my ( $text, $type ) = %$_; | |||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ( my $name = lc $text ) =~ s/\W/_/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | my %opts; | |||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | if ( ref $type eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ( $type, %opts ) = ( @$type ); | |||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 371 | elsif ( ref $type eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | $self->{Q}{ $name } = $type->( @{ $self }{ qw/T Q/ } ); | |||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | $type = 'auto_set'; | |||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | my $id = "crud_$name"; | |||||||||||||||||||||||||||||||||||||||||||||
| 376 | $_ = +{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | text => $text, | ||||||||||||||||||||||||||||||||||||||||||||||
| 378 | "el_$type" => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 380 | id => $id, | ||||||||||||||||||||||||||||||||||||||||||||||
| 381 | value => $self->{Q}{ $name }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 382 | is_create => !$self->{Q}{crud_update} | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | && !$self->{Q}{crud_update_save}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | %opts, | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'Q'}{'crud_update'} || $self->{'Q'}{'crud_update_save'}
MC/DC0%0/2
$self->{'Q'}{'crud_update'} || $self->{'Q'}{'crud_update_save'}
$self->{'Q'}{'crud_update'}
$self->{'Q'}{'crud_update_save'}
Truth table0%0/3
A || B
A= $self->{'Q'}{'crud_update'}B= $self->{'Q'}{'crud_update_save'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 385 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | sub _get_D_form_template { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_D_form_template: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | return <<'END_HTML'; | |||||||||||||||||||||||||||||||||||||||||||||
| 393 | <form class="delete_button_form delete_form" method="POST" action="" | ||||||||||||||||||||||||||||||||||||||||||||||
| 394 | ><div | ||||||||||||||||||||||||||||||||||||||||||||||
| 395 | ><input type="hidden" | ||||||||||||||||||||||||||||||||||||||||||||||
| 396 | name="page" | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | value="<tmpl_var escape='html' name='page'>" | ||||||||||||||||||||||||||||||||||||||||||||||
| 398 | ><input type="hidden" | ||||||||||||||||||||||||||||||||||||||||||||||
| 399 | name="crud_delete" | ||||||||||||||||||||||||||||||||||||||||||||||
| 400 | value="1" | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | ><input type="hidden" | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | name="crud_id" | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | value="[<<ITEM:ID>>]" | ||||||||||||||||||||||||||||||||||||||||||||||
| 404 | ><input type="image" | ||||||||||||||||||||||||||||||||||||||||||||||
| 405 | alt="Delete" | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | class="delete_button_no_style" | ||||||||||||||||||||||||||||||||||||||||||||||
| 407 | src="/pics/delete-button.png" | ||||||||||||||||||||||||||||||||||||||||||||||
| 408 | ></div></form> | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | END_HTML | ||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | sub _get_U_form_template { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_U_form_template: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | return <<'END_HTML'; | |||||||||||||||||||||||||||||||||||||||||||||
| 414 | <form class="update_button_form update_form" method="POST" action="" | ||||||||||||||||||||||||||||||||||||||||||||||
| 415 | ><div | ||||||||||||||||||||||||||||||||||||||||||||||
| 416 | ><input type="hidden" | ||||||||||||||||||||||||||||||||||||||||||||||
| 417 | name="page" | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | value="<tmpl_var escape='html' name='page'>" | ||||||||||||||||||||||||||||||||||||||||||||||
| 419 | ><input type="hidden" | ||||||||||||||||||||||||||||||||||||||||||||||
| 420 | name="crud_update" | ||||||||||||||||||||||||||||||||||||||||||||||
| 421 | value="1" | ||||||||||||||||||||||||||||||||||||||||||||||
| 422 | ><input type="hidden" | ||||||||||||||||||||||||||||||||||||||||||||||
| 423 | name="crud_id" | ||||||||||||||||||||||||||||||||||||||||||||||
| 424 | value="[<<ITEM:ID>>]" | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | ><input type="image" | ||||||||||||||||||||||||||||||||||||||||||||||
| 426 | alt="Update" | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | class="update_button" | ||||||||||||||||||||||||||||||||||||||||||||||
| 428 | src="/pics/update-button.png" | ||||||||||||||||||||||||||||||||||||||||||||||
| 429 | ></div></form> | ||||||||||||||||||||||||||||||||||||||||||||||
| 430 | END_HTML | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | sub _get_CU_form_template { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_CU_form_template: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | return <<'END_HTML'; | |||||||||||||||||||||||||||||||||||||||||||||
| 435 | <tmpl_if name='create_success'> | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | <p class="success-message">Item has been successfully added. <a href="<tmpl_var escape='html' name='page'>">Add another one</a></p> | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | </tmpl_if> | ||||||||||||||||||||||||||||||||||||||||||||||
| 438 | <tmpl_if name='update_success'> | ||||||||||||||||||||||||||||||||||||||||||||||
| 439 | <p class="success-message">Item has been successfully updated. <a href="<tmpl_var escape='html' name='page'>">Back to the form</a></p> | ||||||||||||||||||||||||||||||||||||||||||||||
| 440 | </tmpl_if> | ||||||||||||||||||||||||||||||||||||||||||||||
| 441 | <tmpl_unless name='hide_form'> | ||||||||||||||||||||||||||||||||||||||||||||||
| 442 | <form action="" method="POST" id="crud_<tmpl_if name='is_create'>c<tmpl_else>u</tmpl_if>form"<tmpl_if name='has_files'> enctype="multipart/form-data"</tmpl_if>> | ||||||||||||||||||||||||||||||||||||||||||||||
| 443 | <div> | ||||||||||||||||||||||||||||||||||||||||||||||
| 444 | <input type="hidden" name="page" | ||||||||||||||||||||||||||||||||||||||||||||||
| 445 | value="<tmpl_var escape='html' name='page'>"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 446 | <input type="hidden" name="crud_<tmpl_if name='is_create'>create<tmpl_else>update_save</tmpl_if>" value="1"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||
| 448 | <tmpl_unless name='is_create'> | ||||||||||||||||||||||||||||||||||||||||||||||
| 449 | <input type="hidden" name="crud_id" | ||||||||||||||||||||||||||||||||||||||||||||||
| 450 | value="<tmpl_var escape='html' name='id'>"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 451 | </tmpl_unless> | ||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||
| 453 | <tmpl_loop name='errors'> | ||||||||||||||||||||||||||||||||||||||||||||||
| 454 | <p class="error"><tmpl_var escape='html' name='error'></p> | ||||||||||||||||||||||||||||||||||||||||||||||
| 455 | </tmpl_loop> | ||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||
| 457 | <p class="crud_form_note">Fields marked with | ||||||||||||||||||||||||||||||||||||||||||||||
| 458 | an asterisk(*) are mandatory.</p> | ||||||||||||||||||||||||||||||||||||||||||||||
| 459 | <ul> | ||||||||||||||||||||||||||||||||||||||||||||||
| 460 | <tmpl_loop name='elements'> | ||||||||||||||||||||||||||||||||||||||||||||||
| 461 | <li> | ||||||||||||||||||||||||||||||||||||||||||||||
| 462 | <tmpl_if name='el_text'> | ||||||||||||||||||||||||||||||||||||||||||||||
| 463 | <label for="<tmpl_var escape='html' name='id'>"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 464 | <tmpl_unless name='optional'> | ||||||||||||||||||||||||||||||||||||||||||||||
| 465 | *</tmpl_unless><tmpl_var | ||||||||||||||||||||||||||||||||||||||||||||||
| 466 | escape='html' name='text'>:</label> | ||||||||||||||||||||||||||||||||||||||||||||||
| 467 | <input type="text" | ||||||||||||||||||||||||||||||||||||||||||||||
| 468 | class="input_text" | ||||||||||||||||||||||||||||||||||||||||||||||
| 469 | name="<tmpl_var escape='html' name='name'>" | ||||||||||||||||||||||||||||||||||||||||||||||
| 470 | value="<tmpl_var escape='html' name='value'>" | ||||||||||||||||||||||||||||||||||||||||||||||
| 471 | id="<tmpl_var escape='html' name='id'>"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 472 | </tmpl_if> | ||||||||||||||||||||||||||||||||||||||||||||||
| 473 | <tmpl_if name='el_textarea'> | ||||||||||||||||||||||||||||||||||||||||||||||
| 474 | <label for="<tmpl_var escape='html' name='id'>" | ||||||||||||||||||||||||||||||||||||||||||||||
| 475 | class="textarea_label" | ||||||||||||||||||||||||||||||||||||||||||||||
| 476 | ><tmpl_unless name='optional'> | ||||||||||||||||||||||||||||||||||||||||||||||
| 477 | *</tmpl_unless><tmpl_var | ||||||||||||||||||||||||||||||||||||||||||||||
| 478 | escape='html' name='text'>:</label> | ||||||||||||||||||||||||||||||||||||||||||||||
| 479 | <textarea cols="60" rows="5" | ||||||||||||||||||||||||||||||||||||||||||||||
| 480 | name="<tmpl_var escape='html' name='name'>" | ||||||||||||||||||||||||||||||||||||||||||||||
| 481 | id="<tmpl_var escape='html' name='id'>" | ||||||||||||||||||||||||||||||||||||||||||||||
| 482 | ><tmpl_var escape='html' name='value'></textarea> | ||||||||||||||||||||||||||||||||||||||||||||||
| 483 | </tmpl_if> | ||||||||||||||||||||||||||||||||||||||||||||||
| 484 | <tmpl_if name='el_file'> | ||||||||||||||||||||||||||||||||||||||||||||||
| 485 | <tmpl_if name='is_create'> | ||||||||||||||||||||||||||||||||||||||||||||||
| 486 | <label for="<tmpl_var escape='html' name='id'>" | ||||||||||||||||||||||||||||||||||||||||||||||
| 487 | ><tmpl_unless name='optional'> | ||||||||||||||||||||||||||||||||||||||||||||||
| 488 | *</tmpl_unless><tmpl_var | ||||||||||||||||||||||||||||||||||||||||||||||
| 489 | escape='html' name='text'>:</label> | ||||||||||||||||||||||||||||||||||||||||||||||
| 490 | <input type="file" | ||||||||||||||||||||||||||||||||||||||||||||||
| 491 | class="input_file" | ||||||||||||||||||||||||||||||||||||||||||||||
| 492 | name="<tmpl_var escape='html' name='name'>" | ||||||||||||||||||||||||||||||||||||||||||||||
| 493 | id="<tmpl_var escape='html' name='id'>"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 494 | <tmpl_else> | ||||||||||||||||||||||||||||||||||||||||||||||
| 495 | Can't change files. | ||||||||||||||||||||||||||||||||||||||||||||||
| 496 | </tmpl_if> | ||||||||||||||||||||||||||||||||||||||||||||||
| 497 | </tmpl_if> | ||||||||||||||||||||||||||||||||||||||||||||||
| 498 | </li> | ||||||||||||||||||||||||||||||||||||||||||||||
| 499 | </tmpl_loop> | ||||||||||||||||||||||||||||||||||||||||||||||
| 500 | </ul> | ||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||
| 502 | <input type="submit" value="Submit"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 503 | </div> | ||||||||||||||||||||||||||||||||||||||||||||||
| 504 | </form> | ||||||||||||||||||||||||||||||||||||||||||||||
| 505 | </tmpl_unless> | ||||||||||||||||||||||||||||||||||||||||||||||
| 506 | END_HTML | ||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 510 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||