| 1 | package App::ZofCMS::Plugin::BoolSettingsManager; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '1.001010'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use base 'App::ZofCMS::Plugin::Base'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use HTML::Template; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use DBI; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub _key { 'plug_bool_settings_manager' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_key: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub _defaults { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_defaults: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 15 | dsn => "DBI:mysql:database=test;host=localhost", | ||||||||||||||||||||||||||||||||||||||||||
| 16 | user => '', | ||||||||||||||||||||||||||||||||||||||||||
| 17 | pass => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | opt => { RaiseError => 1, AutoCommit => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 19 | table => 'users', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | login_col => 'login', | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | login => sub { $_[0]->{d}{user}{login} }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | # settings => | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | submit_button => q|<input type="submit" class="input_submit"| | |||||||||||||||||||||||||||||||||||||||||
| 24 | . q| value="Save">|, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub _do { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_do: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my ( $self, $conf, $t, $q, $config ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | for ( qw/settings login/ ) { | |||||||||||||||||||||||||||||||||||||||||
| 31 | $conf->{$_} = $conf->{$_}->( $t, $q, $config ) | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if ref $conf->{$_} eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | return | ||||||||||||||||||||||||||||||||||||||||||
| 36 | unless defined $conf->{settings} | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | and @{ $conf->{settings} } | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | and defined $conf->{login}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $conf->{"settings"} and @{$conf->{"settings"};} and defined $conf->{"login"}
defined $conf->{"settings"} and @{$conf->{"settings"};}
MC/DC0%0/3
defined $conf->{"settings"} and @{$conf->{"settings"};} and defined $conf->{"login"}
defined $conf->{"settings"}
@{$conf->{"settings"};}
defined $conf->{"login"}
Truth table0%0/4
A and B and C
A= defined $conf->{"settings"}B= @{$conf->{"settings"};}C= defined $conf->{"login"}
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $self->{CONF} = $conf; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $self->{Q} = $q; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | $self->{Q_PAGE} = ( $q->{dir} || '' ) . ( $q->{page} || '' ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
$q->{'dir'} || ''
$q->{'page'} || ''
MC/DC0%0/1
$q->{'dir'} || ''
$q->{'dir'}
MC/DC0%0/1
$q->{'page'} || ''
$q->{'page'}
Truth table0%0/2
A
A= $q->{'dir'}
Truth table0%0/2
A
A= $q->{'page'}
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | $self->save_settings | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if $q->{pbsm_save_settings}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $t->{t}{plug_bool_settings_manager_form} = $self->make_form; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub save_settings { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save_settings: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $q = $self->{Q}; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $conf = $self->{CONF}; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my %settings = @{ $conf->{settings} || [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$conf->{'settings'} || []
MC/DC0%0/1
$conf->{'settings'} || []
$conf->{'settings'}
Truth table0%0/2
A
A= $conf->{'settings'}
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my @q_names = keys %settings; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | $dbh->do( | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 'UPDATE `' . $conf->{table} .'` SET' | ||||||||||||||||||||||||||||||||||||||||||
| 61 | . ( join ',', map "`$_` = ?", @q_names ) | ||||||||||||||||||||||||||||||||||||||||||
| 62 | . 'WHERE `' . $conf->{login_col} .'` = ?', | ||||||||||||||||||||||||||||||||||||||||||
| 63 | undef, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | ( map +( $q->{$_} ? 1 : 0 ), @q_names ), | ||||||||||||||||||||||||||||||||||||||||||
| 65 | $conf->{login}, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub make_form { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_form: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my $q = $self->{Q}; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $template = HTML::Template->new_scalar_ref( | |||||||||||||||||||||||||||||||||||||||||
| 74 | \ form_html_template(), | ||||||||||||||||||||||||||||||||||||||||||
| 75 | die_on_bad_params => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | $template->param( | ||||||||||||||||||||||||||||||||||||||||||
| 79 | ( $q->{pbsm_save_settings} ? ( save_success => 1 ) : () ), | ||||||||||||||||||||||||||||||||||||||||||
| 80 | page => $self->{Q_PAGE}, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | settings => $self->get_settings, | ||||||||||||||||||||||||||||||||||||||||||
| 82 | submit_button => $self->{CONF}{submit_button}, | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | return $template->output; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub get_settings { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_settings: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $conf = $self->{CONF}; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | my $user = ($dbh->selectall_arrayref( | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 'SELECT * FROM `' . $conf->{table} | ||||||||||||||||||||||||||||||||||||||||||
| 95 | . '` WHERE `' . $conf->{login_col} . '` = ?', | ||||||||||||||||||||||||||||||||||||||||||
| 96 | { Slice => {} }, | ||||||||||||||||||||||||||||||||||||||||||
| 97 | $conf->{login}, | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | ) || [])->[0] || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
+($dbh->selectall_arrayref('SELECT * FROM `' . $conf->{'table'} . '` WHERE `' . $conf->{'login_col'} . '` = ?', {'Slice', {}}, $conf->{'login'}) || [])->[0] || {}
$dbh->selectall_arrayref('SELECT * FROM `' . $conf->{'table'} . '` WHERE `' . $conf->{'login_col'} . '` = ?', {'Slice', {}}, $conf->{'login'}) || []
MC/DC0%0/1
+($dbh->selectall_arrayref('SELECT * FROM `' . $conf->{'table'} . '` WHERE `' . $conf->{'login_col'} . '` = ?', {'Slice', {}}, $conf->{'login'}) || [])->[0] || {}
$dbh->selectall_arrayref('SELECT * FROM `' . $conf->{'table'} . '` WHERE `' . $conf->{'login_col'} . '` = ?', {'Slice', {}}, $conf->{'login'})
Truth table0%0/2
A
A= $dbh->selectall_arrayref('SELECT * FROM `' . $conf->{'table'} . '` WHERE `' . $conf->{'login_col'} . '` = ?', {'Slice', {}}, $conf->{'login'})
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my @settings; | |||||||||||||||||||||||||||||||||||||||||
| 101 | my $key; | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | for ( 0 .. $#{ $conf->{settings} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ( $_ % 2 == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $key = $conf->{settings}[$_]; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 107 | push @settings, { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | id => $key, | ||||||||||||||||||||||||||||||||||||||||||
| 109 | value => $conf->{settings}[$_], | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | is_checked => ( $user->{$key} ? 1 : 0 ), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | return \@settings; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub dbh { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dbh: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | return $self->{DBH} | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if $self->{DBH}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | $self->{DBH} = DBI->connect_cached( | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | @{ $self->{CONF} }{ qw/dsn user pass opt/ }, | |||||||||||||||||||||||||||||||||||||||||
| 126 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | return $self->{DBH}; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub has_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_value: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my $v = shift; | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | return 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $v and length $v
MC/DC0%0/2
defined $v and length $v
defined $v
length $v
Truth table0%0/3
A and B
A= defined $vB= length $v
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | if defined $v and length $v; | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | sub form_html_template { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
form_html_template: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | return <<'END_HTML'; | |||||||||||||||||||||||||||||||||||||||||
| 142 | <tmpl_if name='save_success'> | ||||||||||||||||||||||||||||||||||||||||||
| 143 | <p class="success-message">Successfully saved</p> | ||||||||||||||||||||||||||||||||||||||||||
| 144 | </tmpl_if> | ||||||||||||||||||||||||||||||||||||||||||
| 145 | <form action="" method="POST" id="plug_bool_settings_manager_form"> | ||||||||||||||||||||||||||||||||||||||||||
| 146 | <div> | ||||||||||||||||||||||||||||||||||||||||||
| 147 | <input type="hidden" name="page" | ||||||||||||||||||||||||||||||||||||||||||
| 148 | value="<tmpl_var escape='html' name='page'>"> | ||||||||||||||||||||||||||||||||||||||||||
| 149 | <input type="hidden" name="pbsm_save_settings" value="1"> | ||||||||||||||||||||||||||||||||||||||||||
| 150 | <ul> | ||||||||||||||||||||||||||||||||||||||||||
| 151 | <tmpl_loop name='settings'> | ||||||||||||||||||||||||||||||||||||||||||
| 152 | <li id="pbsm_container_<tmpl_var escape='html' name='id'>"> | ||||||||||||||||||||||||||||||||||||||||||
| 153 | <input type="checkbox" | ||||||||||||||||||||||||||||||||||||||||||
| 154 | id="pbsm_<tmpl_var escape='html' name='id'>" | ||||||||||||||||||||||||||||||||||||||||||
| 155 | name="<tmpl_var escape='html' name='id'>" | ||||||||||||||||||||||||||||||||||||||||||
| 156 | <tmpl_if name='is_checked'>checked</tmpl_if> | ||||||||||||||||||||||||||||||||||||||||||
| 157 | ><label for="pbsm_<tmpl_var escape='html' name='id'>" | ||||||||||||||||||||||||||||||||||||||||||
| 158 | class="checkbox_label"> <tmpl_var escape='html' name='value'></label> | ||||||||||||||||||||||||||||||||||||||||||
| 159 | </li> | ||||||||||||||||||||||||||||||||||||||||||
| 160 | </tmpl_loop> | ||||||||||||||||||||||||||||||||||||||||||
| 161 | </ul> | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | <tmpl_var name="submit_button"> | ||||||||||||||||||||||||||||||||||||||||||
| 164 | </div> | ||||||||||||||||||||||||||||||||||||||||||
| 165 | </form> | ||||||||||||||||||||||||||||||||||||||||||
| 166 | END_HTML | ||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 170 | __END__ | ||||||||||||||||||||||||||||||||||||||||||