ZofCMS/Plugin/BoolSettingsManager.pm

filter: Statementstmt 26.9% 17 / 63 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 33.3% 5 / 15 Podpod 0.0% 0 / 6 totaltotal 16.9% 22 / 130 CC 20 SCAR 35.4
CC
20
Cov
17%
_do
90.0
get_settings
42.0
save_settings
12.0
CRAP 34.4
« ZofCMS/Plugin/LinkifyText.pm ↑ Summary ZofCMS/Plugin/DirTreeBrowse.pm »
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
BranchTrueFalseTotal
if ref $conf->{$_} eq "CODE" 0 0 0
33 }
34  
35 return
36 unless defined $conf->{settings}
37 0 and @{ $conf->{settings} }
38 0 ▶ and defined $conf->{login};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $conf->{"settings"} and @{$conf->{"settings"};} and defined $conf->{"login"} 0 0 0
Condition0%0/6
defined $conf->{"settings"} and @{$conf->{"settings"};} and defined $conf->{"login"}
!ll&&!rl&&r
000
defined $conf->{"settings"} and @{$conf->{"settings"};}
!ll&&!rl&&r
000
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"}
ABCresult
0XX0
10X0
1100
1111
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'} || ''
l!l
00
$q->{'page'} || ''
l!l
00
MC/DC0%0/1
$q->{'dir'} || ''
$q->{'dir'}
MC/DC0%0/1
$q->{'page'} || ''
$q->{'page'}
Truth table0%0/2
A
A= $q->{'dir'}
Aresult
11
00
Truth table0%0/2
A
A= $q->{'page'}
Aresult
11
00
43  
44 $self->save_settings
45 0 ▶ if $q->{pbsm_save_settings};
Branch: 1 branch
BranchTrueFalseTotal
if $q->{"pbsm_save_settings"} 0 0 0
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'} || []
l!l
00
MC/DC0%0/1
$conf->{'settings'} || []
$conf->{'settings'}
Truth table0%0/2
A
A= $conf->{'settings'}
Aresult
11
00
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
BranchTrueFalseTotal
$q->{$_} ? : 0 0 0
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
BranchTrueFalseTotal
$q->{'pbsm_save_settings'} ? : 0 0 0
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] || {}
l!l
00
$dbh->selectall_arrayref('SELECT * FROM `' . $conf->{'table'} . '` WHERE `' . $conf->{'login_col'} . '` = ?', {'Slice', {}}, $conf->{'login'}) || []
l!l
00
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'})
Aresult
11
00
99  
100 0 my @settings;
101 my $key;
102 0 for ( 0 .. $#{ $conf->{settings} } ) {
103 0 ▶ if ( $_ % 2 == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ % 2 == 0) { } 0 0 0
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
BranchTrueFalseTotal
$user->{$key} ? : 0 0 0
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
BranchTrueFalseTotal
if $self->{"DBH"} 0 0 0
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
BranchTrueFalseTotal
if defined $v and length $v 0 0 0
Condition0%0/3
defined $v and length $v
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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__
« ZofCMS/Plugin/LinkifyText.pm ↑ Summary ZofCMS/Plugin/DirTreeBrowse.pm »