Labyrinth/Plugin/CPAN/Preferences.pm

filter: Statementstmt 22.3% 59 / 264 Branchbran 2.7% 3 / 108 Conditioncond 0.0% 0 / 41 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 51.7% 15 / 29 Podpod 100% 13 / 13 totaltotal 18.7% 90 / 481 SCAR 82.7
CC
79
Cov
15%
Distros
600.0
_save_distprefs
90.0
XDropDownMultiList
72.0
CRAP 3910.1
↑ Summary CPAN/Testers/WWW/Preferences.pm »
1 package Labyrinth::Plugin::CPAN::Preferences;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 our $VERSION = '0.19';
7  
8 =head1 NAME
9  
10 Labyrinth::Plugin::CPAN::Preferences - Handles preferences pages.
11  
12 =cut
13  
14 #----------------------------------------------------------------------------
15 # Libraries
16  
17 4 ▶use base qw(Labyrinth::Plugin::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 4 ▶use Labyrinth::Audit;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use Labyrinth::DTUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶use Labyrinth::MLUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 ▶use Labyrinth::Mailer;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 ▶use Labyrinth::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 4 ▶use Labyrinth::Support;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 ▶use Labyrinth::Variables;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 4 ▶use Sort::Versions;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 4 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 #----------------------------------------------------------------------------
31 # Variables
32  
33 # The following distributions are considered exceptions from the norm and
34 # are to be added on a case by case basis.
35 4 my $EXCEPTIONS = 'Test.php|Net-ITE.pm|CGI.pm';
36  
37 4 my %date_fields = (
38 y => { type => 1, html => 1 },
39 m => { type => 1, html => 1 },
40 d => { type => 1, html => 1 },
41 );
42  
43 4 my (@date_man,@date_all);
44 4 for(keys %date_fields) {
45 12 ▶ push @date_man, $_ if($date_fields{$_}->{type});
Branch: 1 branch
BranchTrueFalseTotal
if $date_fields{$_}{"type"} 12 0 12
46 12 push @date_all, $_;
47 }
48  
49 4 my %pref_fields = (
50 dist => { type => 1, html => 1 },
51 active => { type => 1, html => 0 },
52 ignored => { type => 0, html => 0 },
53 report => { type => 1, html => 0 },
54 grade => { type => 1, html => 0 },
55 tuple => { type => 1, html => 1 },
56 version => { type => 1, html => 0 },
57 versions => { type => 0, html => 0 },
58 patches => { type => 0, html => 0 },
59 perl => { type => 1, html => 0 },
60 perls => { type => 0, html => 0 },
61 platform => { type => 1, html => 0 },
62 platforms => { type => 0, html => 0 },
63 );
64  
65 4 my (@pref_man,@pref_all);
66 4 for(keys %pref_fields) {
67 52 ▶ push @pref_man, $_ if($pref_fields{$_}->{type});
Branch: 1 branch
BranchTrueFalseTotal
if $pref_fields{$_}{"type"} 32 20 52
68 52 push @pref_all, $_;
69 }
70  
71 4 my %months = (
72 1 => 'January',
73 2 => 'February',
74 3 => 'March',
75 4 => 'April',
76 5 => 'May',
77 6 => 'June',
78 7 => 'July',
79 8 => 'August',
80 9 => 'September',
81 10 => 'October',
82 11 => 'November',
83 12 => 'December',
84 );
85  
86 #----------------------------------------------------------------------------
87 # Public Interface Functions
88  
89 =head1 METHODS
90  
91 =head2 Public Interface Methods
92  
93 =over 4
94  
95 =item Login
96  
97 Author Login mechanism. Uses the PAUSE authentication system.
98  
99 =item Logged
100  
101 Ensure correct user is logged in.
102  
103 =item Default
104  
105 Default preferences page.
106  
107 =item Distros
108  
109 Author distributions list page.
110  
111 =item Distro
112  
113 Single distribution preferences page.
114  
115 =item XDropDownMultiList
116  
117 Provide a drop down multi-select list, base on a list of strings.
118  
119 =item XDropDownMultiRows
120  
121 Provide a drop down multi-select list, base on a list of rows.
122  
123 =item DefSave
124  
125 Save default preferences.
126  
127 =item DistSave
128  
129 Save distribution preferences.
130  
131 =item Delete
132  
133 Delete the preferences for a distribution, and use the default preferences.
134  
135 =back
136  
137 =cut
138  
139 sub Login {
140 # if a regular login or no login, use the core login mechanism
141 0 ▶ if(!$cgiparams{pause} || !$cgiparams{eject} || $cgiparams{pause} =~ /\@/) {
Subroutine Login: not called CC=6 SCAR=31.7
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if (not $Labyrinth::Plugin::CPAN::Preferences::cgiparams{"pause"} && $Labyrinth::Plugin::CPAN::Preferences::cgiparams{"eject"} or $Labyrinth::Plugin::CPAN::Preferences::cgiparams{"pause"} =~ /\@/) 0 0 0
Condition0%0/6
not $Labyrinth::Plugin::CPAN::Preferences::cgiparams{"pause"} && $Labyrinth::Plugin::CPAN::Preferences::cgiparams{"eject"} or $Labyrinth::Plugin::CPAN::Preferences::cgiparams{"pause"} =~ /\@/
l!l&&r!l&&!r
000
$Labyrinth::Plugin::CPAN::Preferences::cgiparams{'pause'} && $Labyrinth::Plugin::CPAN::Preferences::cgiparams{'eject'}
!ll&&!rl&&r
000
MC/DC0%0/3
not $Labyrinth::Plugin::CPAN::Preferences::cgiparams{"pause"} && $Labyrinth::Plugin::CPAN::Preferences::cgiparams{"eject"} or $Labyrinth::Plugin::CPAN::Preferences::cgiparams{"pause"} =~ /\@/
$Labyrinth::Plugin::CPAN::Preferences::cgiparams{'pause'} $Labyrinth::Plugin::CPAN::Preferences::cgiparams{'eject'} $Labyrinth::Plugin::CPAN::Preferences::cgiparams{"pause"} =~ /\@/
Truth table0%0/4
not(A && B) or C
A= $Labyrinth::Plugin::CPAN::Preferences::cgiparams{'pause'}B= $Labyrinth::Plugin::CPAN::Preferences::cgiparams{'eject'}C= $Labyrinth::Plugin::CPAN::Preferences::cgiparams{"pause"} =~ /\@/
ABCresult
0XX1
10X1
1111
1100
142 0 $cgiparams{cause} = $cgiparams{pause};
143 0 $cgiparams{effect} = $cgiparams{eject};
144  
145 0 LogDebug("pause=$cgiparams{pause}, eject=$cgiparams{eject}");
146 0 LogDebug("cause=$cgiparams{cause}, effect=$cgiparams{effect}");
147  
148 0 $tvars{errcode} = 'NEXT';
149 0 $tvars{command} = 'user-logged';
150 0 return;
151 }
152  
153 4 ▶ use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
154 4 ▶ use Net::SSLeay qw(get_https make_headers);
Subroutine BEGIN: called CC=1 SCAR=0.0
155  
156 4 ▶ use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
157 0 my $result = LWP::UserAgent->new->get("https://pause.perl.org/pause/authenquery",
158 Authorization =>
159 'Basic ' . MIME::Base64::encode("$cgiparams{pause}:$cgiparams{eject}",'')
160 );
161  
162 0 ▶ if($result->code == 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->code == 200) { } 0 0 0
163 0 my @rows = $dbi->GetQuery('hash','CheckUser','PAUSE','PAUSE');
164  
165 # add entry to session table
166 0 my $session;
167 ( $session,
168 $tvars{user}{name},
169 $tvars{'loginid'},
170 $tvars{realm},
171 $tvars{langcode}
172 0 ) = Labyrinth::Session::_save_session(uc $cgiparams{pause},$rows[0]->{userid},$rows[0]->{realm},$rows[0]->{langcode});
173  
174 # set template variables
175 0 $tvars{'loggedin'} = 1;
176 0 $tvars{user}{folder} = 1;
177 0 $tvars{user}{option} = 0;
178 0 $tvars{user}{userid} = $tvars{'loginid'};
179 0 $tvars{user}{access} = VerifyUser($tvars{'loginid'});
180 0 ▶ $tvars{realm} ||= 'public';
Condition0%0/2
$Labyrinth::Plugin::CPAN::Preferences::tvars{"realm"} ||= "public"
l!l
00
MC/DC0%0/1
$Labyrinth::Plugin::CPAN::Preferences::tvars{"realm"} ||= "public"
$Labyrinth::Plugin::CPAN::Preferences::tvars{"realm"}
Truth table0%0/2
A
A= $Labyrinth::Plugin::CPAN::Preferences::tvars{"realm"}
Aresult
11
00
181  
182 # set login activity
183 0 $dbi->DoQuery('UpdateAuthorLogin',time(),$tvars{user}{name});
184  
185 } else {
186 0 $tvars{errmess} = 2;
187 0 $tvars{errcode} = 'ERROR';
188 }
189 }
190  
191 sub Logged {
192 0 ▶ return unless RealmCheck('author','admin');
Subroutine Logged: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("author", "admin") 0 0 0
193 }
194  
195 sub Default {
196 0 ▶ return unless RealmCheck('author','admin');
Subroutine Default: not called CC=4 SCAR=30.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("author", "admin") 0 0 0
197 0 ▶ my $author = $tvars{user}{author} || $tvars{user}{name};
Condition0%0/3
$Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'} || $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'} || $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
$Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'} $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
Truth table0%0/3
A || B
A= $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'}B= $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
ABresult
1X1
011
000
198 0 my @rows = $dbi->GetQuery('hash','GetAuthorDefault',$author);
199 0 ▶ $tvars{data} = $rows[0] if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
200  
201 0 my $cpan = Labyrinth::Plugin::CPAN->new();
202  
203 0 my @perls = sort {versioncmp($b->{perl},$a->{perl})} $dbi->GetQuery('hash','GetPerlVersions');
204  
205 0 $cpan->Configure();
206 0 my $archs = $cpan->osnames();
207 0 my @archs = map {{oscode => $_, osname => $archs->{$_}}} sort {lc $archs->{$a} cmp lc $archs->{$b}} keys %$archs;
208  
209 0 $tvars{data}{ddarch} = XDropDownMultiRows($tvars{data}{platform},'platforms','oscode','osname',5,@archs);
210 0 $tvars{data}{ddperl} = XDropDownMultiRows($tvars{data}{perl},'perls','perl','perl',5,@perls);
211 }
212  
213 sub Distros {
214 0 ▶ return unless RealmCheck('author','admin');
Subroutine Distros: not called CC=24 SCAR=64.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("author", "admin") 0 0 0
215  
216 0 ▶ my $author = $tvars{user}{author} || $tvars{user}{name};
Condition0%0/3
$Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'} || $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'} || $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
$Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'} $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
Truth table0%0/3
A || B
A= $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'}B= $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
ABresult
1X1
011
000
217  
218 0 my $cpan = Labyrinth::Plugin::CPAN->new();
219 0 my @rows = $dbi->GetQuery('array','GetAuthorDists',$author);
220 0 my @dists = map {$_->[0]} @rows;
221  
222 0 my @distros = $dbi->GetQuery('hash','GetAuthorDistros',$author);
223 0 my %distros = map {$_->{distribution} => $_} @distros;
224 0 for(keys %distros) {
225 0 $distros{$_}->{name} = $_;
226  
227 0 $distros{$_}->{grade} =~ s/PASS/P/;
228 0 $distros{$_}->{grade} =~ s/FAIL/F/;
229 0 $distros{$_}->{grade} =~ s/UNKNOWN/U/;
230 0 $distros{$_}->{grade} =~ s/NA/N/;
231 0 $distros{$_}->{grade} =~ s/,//g;
232  
233 0 $distros{$_}->{tuple} =~ s/ALL/A/;
234 0 $distros{$_}->{tuple} =~ s/FIRST/F/;
235  
236 0 $distros{$_}->{version} =~ s/ALL/A/;
237 0 $distros{$_}->{version} =~ s/LATEST/L/;
238 0 $distros{$_}->{version} =~ s/(NOT|INC).*/C/;
239  
240 0 $distros{$_}->{perl} =~ s/ALL/A/;
241 0 $distros{$_}->{perl} =~ s/(NOT|INC).*/C/;
242 0 ▶ $distros{$_}->{perl} .= '+P' if($distros{$_}->{perl} eq 'A' && $distros{$_}->{patches});
Branch: 1 branch
BranchTrueFalseTotal
if $distros{$_}{"perl"} eq "A" and $distros{$_}{"patches"} 0 0 0
Condition0%0/3
$distros{$_}{"perl"} eq "A" and $distros{$_}{"patches"}
!ll&&!rl&&r
000
MC/DC0%0/2
$distros{$_}{"perl"} eq "A" and $distros{$_}{"patches"}
$distros{$_}{"perl"} eq "A" $distros{$_}{"patches"}
Truth table0%0/3
A and B
A= $distros{$_}{"perl"} eq "A"B= $distros{$_}{"patches"}
ABresult
0X0
100
111
243  
244 0 $distros{$_}->{platform} =~ s/ALL/A/;
245 0 $distros{$_}->{platform} =~ s/(NOT|INC).*/C/;
246 }
247  
248 # check whether any distributions have had their ignore status altered
249 0 ▶ if($cgiparams{enable}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::CPAN::Preferences::cgiparams{"enable"}) 0 0 0
250 0 my $updated = 0;
251 0 my @check = CGIArray('dists');
252 0 ▶ my %check = @check ? map {$_=>1} @check : ();
Branch: 1 branch
BranchTrueFalseTotal
@check ? : 0 0 0
253 0 my @list;
254  
255 # ensure user checked are disabled in the DB
256 0 for(@check) {
257 0 ▶ next if($distros{$_} && $distros{$_}->{ignored} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $distros{$_} and $distros{$_}{"ignored"} == 1 0 0 0
Condition0%0/3
$distros{$_} and $distros{$_}{"ignored"} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$distros{$_} and $distros{$_}{"ignored"} == 1
$distros{$_} $distros{$_}{"ignored"} == 1
Truth table0%0/3
A and B
A= $distros{$_}B= $distros{$_}{"ignored"} == 1
ABresult
0X0
100
111
258 0 $updated = 1;
259 0 ▶ if(defined $distros{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $distros{$_}) { } 0 0 0
260 0 push @list, "'$_'";
261 0 $distros{$_}->{ignored} = 2;
262 } else {
263 0 $dbi->DoQuery('InsertDistroPrefs',1,1,'FAIL','FIRST','LATEST',0,'ALL','ALL',$author,$_);
264 0 $distros{$_}->{ignored} = 1;
265 }
266 }
267 0 ▶ $dbi->DoQuery('SetAuthorIgnore',{dists => join(',',@list)},2,$author) if(@list);
Branch: 1 branch
BranchTrueFalseTotal
if @list 0 0 0
268  
269 # ensure user unchecked are enabled in the DB
270 0 @list = ();
271 0 for(keys %distros) {
272 0 ▶ next if($check{$_});
Branch: 1 branch
BranchTrueFalseTotal
if $check{$_} 0 0 0
273 0 $updated = 1;
274 0 my @rows = $dbi->GetQuery('hash','GetAuthorDistro',$author,$_);
275 0 ▶ if(@rows) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rows) 0 0 0
276 0 ▶ if($rows[0]->{ignored} == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rows[0]{'ignored'} == 1) { } 0 0 0
277 0 $dbi->DoQuery('DeleteDistroPrefs', $author, $_);
278 0 delete $distros{$_};
279 } else {
280 0 push @list, "'$_'";
281 0 $distros{$_}->{ignored} = 0;
282 }
283 }
284 }
285 0 ▶ $dbi->DoQuery('SetAuthorIgnore',{dists => join(',',@list)},0,$author) if(@list);
Branch: 1 branch
BranchTrueFalseTotal
if @list 0 0 0
286  
287 0 ▶ $tvars{thanks} = 1 if($updated);
Branch: 1 branch
BranchTrueFalseTotal
if $updated 0 0 0
288 }
289  
290 0 @distros = ();
291 0 my %dists = map {$_ => 1} @dists;
292 0 for my $dist (sort keys %dists) {
293 0 ▶ next unless($dist =~ /^[A-Za-z0-9][A-Za-z0-9\-_]*$/
Branch: 1 branch
BranchTrueFalseTotal
unless $dist =~ /^[A-Za-z0-9][A-Za-z0-9\-_]*$/ or $dist =~ /$EXCEPTIONS/ 0 0 0
Condition0%0/3
$dist =~ /^[A-Za-z0-9][A-Za-z0-9\-_]*$/ or $dist =~ /$EXCEPTIONS/
l!l&&r!l&&!r
000
MC/DC0%0/2
$dist =~ /^[A-Za-z0-9][A-Za-z0-9\-_]*$/ or $dist =~ /$EXCEPTIONS/
$dist =~ /^[A-Za-z0-9][A-Za-z0-9\-_]*$/ $dist =~ /$EXCEPTIONS/
Truth table0%0/3
A or B
A= $dist =~ /^[A-Za-z0-9][A-Za-z0-9\-_]*$/B= $dist =~ /$EXCEPTIONS/
ABresult
1X1
011
000
294 || $dist =~ /$EXCEPTIONS/);
295 0 ▶ if(defined $distros{$dist}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $distros{$dist}) { } 0 0 0
296 0 ▶ if($distros{$dist}->{ignored}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distros{$dist}{'ignored'}) { } 0 0 0
297 0 push @distros, {name => $dist, ignored => $distros{$dist}->{ignored}};
298 } else {
299 0 push @distros, $distros{$dist}
300 }
301 } else {
302 0 push @distros, {name => $dist, ignored => 0};
303 }
304 }
305  
306 0 $tvars{data}{dists} = \@distros;
307 #$tvars{hash}{dists} = \%dists;
308 }
309  
310 sub Distro {
311 0 ▶ return unless RealmCheck('author','admin');
Subroutine Distro: not called CC=5 SCAR=34.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("author", "admin") 0 0 0
312  
313 0 ▶ my $author = $tvars{user}{author} || $tvars{user}{name};
Condition0%0/3
$Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'} || $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'} || $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
$Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'} $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
Truth table0%0/3
A || B
A= $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'}B= $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
ABresult
1X1
011
000
314 0 my $dist = $cgiparams{dist};
315 0 my $version = $cgiparams{version};
316  
317 0 my @rows = $dbi->GetQuery('hash','GetAuthorDistro',$author,$dist);
318 0 ▶ $tvars{data} = $rows[0] if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
319 0 $tvars{data}{dist} = $dist;
320  
321 0 my $cpan = Labyrinth::Plugin::CPAN->new();
322 0 my @vers = $dbi->GetQuery('array','GetAuthorDistVersions',$author,$dist);
323 0 my @versions = sort {versioncmp($b,$a)} map {$_->[0]} @vers;
324 0 $tvars{data}{ddversions} = XDropDownMultiList($version,'versions',5,@versions);
325  
326 0 my @perls = sort {versioncmp($b->{perl},$a->{perl})} $dbi->GetQuery('hash','GetPerlVersions');
327  
328 0 $cpan->Configure();
329 0 my $archs = $cpan->osnames();
330 0 my @archs = map {{oscode => $_, osname => $archs->{$_}}} sort {lc $archs->{$a} cmp lc $archs->{$b}} keys %$archs;
331  
332 0 $tvars{data}{ddarch} = XDropDownMultiRows($tvars{data}{platform},'platforms','oscode','osname',5,@archs);
333 0 $tvars{data}{ddperl} = XDropDownMultiRows($tvars{data}{perl},'perls','perl','perl',5,@perls);
334  
335 0 for(qw(version perl platform)) {
336 0 $tvars{data}{$_} =~ s/,/, /g;
337 0 $tvars{data}{$_} =~ s/(NOT|INC),/$1:/g;
338 }
339 }
340  
341 sub XDropDownMultiList {
342 0 ▶ my ($opts,$name,$count,@items) = @_;
Subroutine XDropDownMultiList: not called CC=8 SCAR=42.8
Pod documented
343 0 my %opts;
344  
345 0 ▶ if(defined $opts) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts) 0 0 0
346 0 ▶ if(ref($opts) eq 'ARRAY') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $opts eq 'ARRAY') { } 0 0 0
elsif ($opts =~ /,/) { } 0 0 0
elsif ($opts) { } 0 0 0
347 0 %opts = map {$_ => 1} @$opts;
348 } elsif($opts =~ /,/) {
349 0 %opts = map {$_ => 1} split(/,/,$opts);
350 } elsif($opts) {
351 0 %opts = ("$opts" => 1);
352 }
353 }
354  
355 0 my %hash = ( name => $name );
356 0 for(@items) {
357 0 ▶ push @{$hash{options}}, { index => $_,
Branch: 1 branch
BranchTrueFalseTotal
defined $opts && $opts{$_} ? : 0 0 0
Condition0%0/3
defined $opts and $opts{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts and $opts{$_}
defined $opts $opts{$_}
Truth table0%0/3
A and B
A= defined $optsB= $opts{$_}
ABresult
0X0
100
111
358 value => $_,
359 0 selected => (defined $opts && $opts{$_} ? 1 : 0)};
360 }
361  
362 0 return \%hash;
363 }
364  
365 sub XDropDownMultiRows {
366 0 ▶ my ($opts,$name,$index,$value,$count,@items) = @_;
Subroutine XDropDownMultiRows: not called CC=8 SCAR=42.8
Pod documented
367 0 my %opts;
368  
369 0 ▶ if(defined $opts) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts) 0 0 0
370 0 ▶ if(ref($opts) eq 'ARRAY') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $opts eq 'ARRAY') { } 0 0 0
elsif ($opts =~ /,/) { } 0 0 0
elsif ($opts) { } 0 0 0
371 0 %opts = map {$_ => 1} @$opts;
372 } elsif($opts =~ /,/) {
373 0 %opts = map {$_ => 1} split(/,/,$opts);
374 } elsif($opts) {
375 0 %opts = ("$opts" => 1);
376 }
377 }
378  
379 0 my %hash = ( name => $name );
380 0 for(@items) {
381 0 ▶ push @{$hash{options}}, { index => $_->{$index},
Branch: 1 branch
BranchTrueFalseTotal
defined $opts && $opts{$_->{$index}} ? : 0 0 0
Condition0%0/3
defined $opts and $opts{$_->{$index}}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts and $opts{$_->{$index}}
defined $opts $opts{$_->{$index}}
Truth table0%0/3
A and B
A= defined $optsB= $opts{$_->{$index}}
ABresult
0X0
100
111
382 value => $_->{$value},
383 0 selected => (defined $opts && $opts{$_->{$index}} ? 1 : 0)};
384 }
385  
386 0 return \%hash;
387 }
388  
389  
390 sub DefSave {
391 0 ▶ return unless RealmCheck('author','admin');
Subroutine DefSave: not called CC=8 SCAR=42.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("author", "admin") 0 0 0
392  
393 0 for(keys %pref_fields) {
394 0 ▶ if($pref_fields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}) }
Branch: 3 branches
BranchTrueFalseTotal
if ($pref_fields{$_}{'html'} == 1) { } 0 0 0
elsif ($pref_fields{$_}{'html'} == 2) { } 0 0 0
elsif ($pref_fields{$_}{'html'} == 3) { } 0 0 0
395 0 elsif($pref_fields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
396 0 elsif($pref_fields{$_}->{html} == 3) { $cgiparams{$_} = CleanLink($cgiparams{$_}) }
397 }
398  
399 0 ▶ return if FieldCheck(\@pref_all,\@pref_man);
Branch: 1 branch
BranchTrueFalseTotal
if FieldCheck(\@pref_all, \@pref_man) 0 0 0
400  
401 0 ▶ my $author = $tvars{user}{author} || $tvars{user}{name};
Condition0%0/3
$Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'} || $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'} || $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
$Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'} $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
Truth table0%0/3
A || B
A= $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'}B= $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
ABresult
1X1
011
000
402  
403 # change reporting activity
404 0 $dbi->DoQuery('UpdateAuthorActive',$tvars{data}{active},$author);
405  
406 0 _save_distprefs($author,'-');
407 }
408  
409 sub DistSave {
410 0 ▶ return unless RealmCheck('author','admin');
Subroutine DistSave: not called CC=8 SCAR=42.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("author", "admin") 0 0 0
411  
412 0 for(keys %pref_fields) {
413 0 ▶ if($pref_fields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}) }
Branch: 3 branches
BranchTrueFalseTotal
if ($pref_fields{$_}{'html'} == 1) { } 0 0 0
elsif ($pref_fields{$_}{'html'} == 2) { } 0 0 0
elsif ($pref_fields{$_}{'html'} == 3) { } 0 0 0
414 0 elsif($pref_fields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
415 0 elsif($pref_fields{$_}->{html} == 3) { $cgiparams{$_} = CleanLink($cgiparams{$_}) }
416 }
417  
418 0 ▶ return if FieldCheck(\@pref_all,\@pref_man);
Branch: 1 branch
BranchTrueFalseTotal
if FieldCheck(\@pref_all, \@pref_man) 0 0 0
419  
420 0 ▶ my $author = $tvars{user}{author} || $tvars{user}{name};
Condition0%0/3
$Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'} || $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'} || $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
$Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'} $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
Truth table0%0/3
A || B
A= $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'}B= $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
ABresult
1X1
011
000
421  
422 0 _save_distprefs($author,$tvars{data}{dist});
423 }
424  
425 sub _save_distprefs {
426 0 ▶ my ($author,$dist) = @_;
Subroutine _save_distprefs: not called CC=9 SCAR=45.0
427 0 my @fields;
428  
429 0 ▶ $tvars{data}{patches} = $tvars{data}{patches} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$Labyrinth::Plugin::CPAN::Preferences::tvars{'data'}{'patches'} ? : 0 0 0
430  
431 # save default settings
432 0 for(qw(grade versions perls platforms)) {
433 0 my @array = CGIArray($_);
434 #LogDebug("$_ => @array");
435 0 $tvars{data}{$_} = join(',',@array);
436 #LogDebug("tvars($_) => $tvars{data}{$_}");
437 }
438 0 for(qw(version perl platform)) {
439 0 ▶ next if($tvars{data}{$_} eq 'ALL');
Branch: 1 branch
BranchTrueFalseTotal
if $Labyrinth::Plugin::CPAN::Preferences::tvars{"data"}{$_} eq "ALL" 0 0 0
440 0 ▶ next if($tvars{data}{$_} eq 'LATEST'); # only applicable to version
Branch: 1 branch
BranchTrueFalseTotal
if $Labyrinth::Plugin::CPAN::Preferences::tvars{"data"}{$_} eq "LATEST" 0 0 0
441 0 ▶ next unless($tvars{data}{$_ . 's'});
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::CPAN::Preferences::tvars{"data"}{$_ . 's'} 0 0 0
442 0 $tvars{data}{$_} .= ',' . $tvars{data}{$_ . 's'};
443 }
444 0 push @fields, $tvars{data}{$_} for(qw(ignored report grade tuple version patches perl platform));
445  
446 0 my @rows = $dbi->GetQuery('hash','GetAuthorDistro',$author,$dist);
447 0 ▶ if(@rows) { $dbi->DoQuery('UpdateDistroPrefs',@fields, $author, $dist) }
Branch: 1 branch
BranchTrueFalseTotal
if (@rows) { } 0 0 0
448 0 else { $dbi->DoQuery('InsertDistroPrefs',@fields, $author, $dist) }
449  
450 0 $tvars{thanks} = 1;
451 }
452  
453 sub Delete {
454 0 ▶ return unless RealmCheck('author','admin');
Subroutine Delete: not called CC=4 SCAR=30.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("author", "admin") 0 0 0
455  
456 0 ▶ my $author = $tvars{user}{author} || $tvars{user}{name};
Condition0%0/3
$Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'} || $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'} || $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
$Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'} $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
Truth table0%0/3
A || B
A= $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'author'}B= $Labyrinth::Plugin::CPAN::Preferences::tvars{'user'}{'name'}
ABresult
1X1
011
000
457 0 my $dist = $cgiparams{dist};
458  
459 0 my @rows = $dbi->GetQuery('hash','GetAuthorDistro',$author,$dist);
460 0 ▶ $dbi->DoQuery('DeleteDistroPrefs', $author, $dist) if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
461 }
462  
463 =head2 Admin Interface Methods
464  
465 =over 4
466  
467 =item Admin
468  
469 Prepare Admin login as author.
470  
471 =item Imposter
472  
473 Allow Admin to login as named author.
474  
475 =item Clear
476  
477 Clear imposter status and return to Admin.
478  
479 =back
480  
481 =cut
482  
483 sub Admin {
484 0 ▶ return unless RealmCheck('admin');
Subroutine Admin: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("admin") 0 0 0
485 0 $tvars{where} = "AND u.realm='author' AND u.userid > 3";
486 }
487  
488 sub Imposter {
489 0 ▶ return unless RealmCheck('admin');
Subroutine Imposter: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("admin") 0 0 0
490 0 UpdateSession('name' => 'imposter:' . $cgiparams{pause});
491 0 $tvars{user}{author} = $cgiparams{pause};
492 }
493  
494 sub Clear {
495 0 ▶ return unless RealmCheck('admin');
Subroutine Clear: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("admin") 0 0 0
496 0 UpdateSession('name' => 'Admin');
497 0 $tvars{user}{name} = 'Admin';
498 0 delete $tvars{user}{author};
499 }
500  
501 4 1;
502  
503 __END__
504  
505 =head1 SEE ALSO
506  
507 Labyrinth
508  
509 =head1 AUTHOR
510  
511 Barbie, <barbie@missbarbell.co.uk> for
512 Miss Barbell Productions, L<http://www.missbarbell.co.uk/>
513  
514 =head1 COPYRIGHT & LICENSE
515  
516 Copyright (C) 2008-2015 Barbie for Miss Barbell Productions
517 All Rights Reserved.
518  
519 This module is free software; you can redistribute it and/or
520 modify it under the same terms as Perl itself.
521  
522 =cut
↑ Summary CPAN/Testers/WWW/Preferences.pm »