Skip to content

Commit

Permalink
Item15323: fixed multiple errors found by perlcrit
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed May 21, 2024
1 parent 2ebff34 commit 67e910d
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 59 deletions.
5 changes: 3 additions & 2 deletions core/lib/Foswiki/Access/TopicACLAccess.pm
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ sub _getACL {

# Dump the users web specifier if userweb
my @list = grep { /\S/ } map {
s/^($Foswiki::cfg{UsersWebName}|%USERSWEB%|%MAINWEB%)\.//;
$_
my $tmp = $_;
$tmp =~ s/^($Foswiki::cfg{UsersWebName}|%USERSWEB%|%MAINWEB%)\.//;
$tmp
} split( /[,\s]+/, $text );

#print STDERR "getACL($mode): ".join(', ', @list)."\n" if MONITOR;
Expand Down
5 changes: 3 additions & 2 deletions core/lib/Foswiki/Access/TopicACLReadOnlyAccess.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ DENY any access except VIEW access - Admin permitted anythingeverything

package Foswiki::Access::TopicACLReadOnlyAccess;

use strict;
use warnings;

use Foswiki::Access::TopicACLAccess;
@ISA = qw(Foswiki::Access::TopicACLAccess);
use constant MONITOR => 0;

use strict;
use warnings;
use Assert;

BEGIN {
Expand Down
57 changes: 30 additions & 27 deletions core/lib/Foswiki/Logger/PlainFile.pm
Original file line number Diff line number Diff line change
@@ -1,30 +1,4 @@
# See bottom of file for license and copyright information
package Foswiki::Logger::PlainFile::EventIterator;
use strict;
use warnings;
use Assert;

use Fcntl qw(:flock);

BEGIN {
if ( $Foswiki::cfg{UseLocale} ) {
require locale;
import locale();
}
}

# Internal class for Logfile iterators.
# So we don't break encapsulation of file handles. Open / Close in same file.
our @ISA = qw/Foswiki::Iterator::EventIterator/;

# # Object destruction
# # Release locks and file
sub DESTROY {
my $this = shift;
flock( $this->{handle}, LOCK_UN )
if ( defined $this->{logLocked} );
close( delete $this->{handle} ) if ( defined $this->{handle} );
}

package Foswiki::Logger::PlainFile;

Expand Down Expand Up @@ -132,7 +106,9 @@ sub log {
# OK too.
unshift( @fields, "$time $level" );
my $message =
'| ' . join( ' | ', map { s/\|/&vbar;/g; $_ } @fields ) . ' |';
'| '
. join( ' | ', map { my $tmp = $_; $tmp =~ s/\|/&vbar;/g; $tmp } @fields )
. ' |';

my $file;
my $mode = '>>';
Expand Down Expand Up @@ -350,6 +326,33 @@ sub _rotate {

}

package Foswiki::Logger::PlainFile::EventIterator;
use strict;
use warnings;
use Assert;

use Fcntl qw(:flock);

BEGIN {
if ( $Foswiki::cfg{UseLocale} ) {
require locale;
import locale();
}
}

# Internal class for Logfile iterators.
# So we don't break encapsulation of file handles. Open / Close in same file.
our @ISA = qw/Foswiki::Iterator::EventIterator/;

# # Object destruction
# # Release locks and file
sub DESTROY {
my $this = shift;
flock( $this->{handle}, LOCK_UN )
if ( defined $this->{logLocked} );
close( delete $this->{handle} ) if ( defined $this->{handle} );
}

1;
__END__
Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Macros/FORMFIELD.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ sub FORMFIELD {
my $fdef = $topicObject->get( 'FIELD', $formField );
if ( $fdef && ( !defined $fdef->{value} || $fdef->{value} eq '' ) ) {

# SMELL: weird; ignores format=
# ignores format=
$text = $args->{default} // '';
$text =~ s/!($Foswiki::regex{wikiWordRegex})/<nop>$1/gs;
return $text;
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Macros/PERLDEPENDENCYREPORT.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# See bottom of file for license and copyright information
package Foswiki;
package Foswiki; ## no critic

# Detailed core and plugin dependency report - see
# System.VarPERLDEPENDENCYREPORT and System.PerlDependencyReport
Expand Down
14 changes: 8 additions & 6 deletions core/lib/Foswiki/Plugins.pm
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,12 @@ Initialisation that is done after the user is known.
=cut

sub enable {
my $this = shift;
my $prefs = $this->{session}->{prefs};
my $dissed = $prefs->getPreference('DISABLEDPLUGINS') || '';
my %disabled = map { s/^\s+//; s/\s+$//; $_ => 1 } split( /,/, $dissed );
my $this = shift;
my $prefs = $this->{session}->{prefs};
my $dissed = $prefs->getPreference('DISABLEDPLUGINS') || '';
my %disabled =
map { my $tmp = $_; $tmp =~ s/^\s+//; $tmp =~ s/\s+$//; $tmp => 1 }
split( /,/, $dissed );

# Set the session for this call stack
local $Foswiki::Plugins::SESSION = $this->{session};
Expand Down Expand Up @@ -319,7 +321,7 @@ sub enable {
foreach my $plugin ( @{ $this->{plugins} } ) {
my $sub = $plugin->{module} . "::lateInitPlugin";
if ( defined &$sub ) {
no strict 'refs';
no strict 'refs'; ## no critic
&$sub();
use strict 'refs';
}
Expand Down Expand Up @@ -387,7 +389,7 @@ sub dispatch {
ASSERT( $Foswiki::Plugins::SESSION->isa('Foswiki') ) if DEBUG;

# apply handler on the remaining list of args
no strict 'refs';
no strict 'refs'; ## no critic
my $status = $plugin->invoke( $handlerName, @_ );
use strict 'refs';
if ( $status && $onlyOnceHandlers{$handlerName} ) {
Expand Down
16 changes: 8 additions & 8 deletions core/lib/Foswiki/Render.pm
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ qr/<[Tt][Ee][Xx][Tt][Aa][Rr][Ee][Aa]\b.*?<\/[Tt][Ee][Xx][Tt][Aa][Rr][Ee][Aa]>/s,

# Indent pseudo-list
$line .= '&nbsp;'
if ( length($line) eq 28 )
if ( length($line) == 28 )
; # empty divs are not rendered, so make it non-empty.
_addListItem( $this, \@result, '', 'div', 'foswikiIndent', $1 );
$isList = 1;
Expand Down Expand Up @@ -1098,7 +1098,7 @@ sub getAnchorNames {
my $id = $topicObject->getPath();
my $a = $this->{_anchorNames}{$id};
unless ($a) {
$a = new Foswiki::Render::Anchors();
$a = Foswiki::Render::Anchors->new();
$this->{_anchorNames}{$id} = $a;
}
return $a;
Expand Down Expand Up @@ -1723,12 +1723,6 @@ sub _adjustH {

return $text unless scalar(@blocks) > 1;

sub _cap {
return 1 if ( $_[0] < 1 );
return 6 if ( $_[0] > 6 );
return $_[0];
}

my $off = 0;
my $out = '';
while ( scalar(@blocks) ) {
Expand All @@ -1745,6 +1739,12 @@ sub _adjustH {
return $out;
}

sub _cap {
return 1 if ( $_[0] < 1 );
return 6 if ( $_[0] > 6 );
return $_[0];
}

# _takeOutProtected( \$text, $re, $id, \%map ) -> $text
#
# * =$text= - Text to process
Expand Down
4 changes: 2 additions & 2 deletions core/lib/Foswiki/Request/Cache.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ sub save {
# passthrough file is only written to once, so if it already exists,
# suspect a security hack (O_EXCL)
my $F;
sysopen( $F, $this->_cacheFile($uid), O_RDWR | O_EXCL | O_CREAT, 0600 )
sysopen( $F, $this->_cacheFile($uid), O_RDWR | O_EXCL | O_CREAT, oct(600) )
|| die 'Unable to open '
. $this->_cacheFile($uid)
. ' for write; check the setting of {WorkingDir} in configure,'
Expand Down Expand Up @@ -255,7 +255,7 @@ sub _loadUpload {
my $data = <$F>;
$data = Foswiki::Sandbox::untaintUnchecked($data);
my $info = undef;
eval $data;
eval $data; ## no critic
$F->close();
unlink($ifn);

Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/UI/Manage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ sub manage {

if ( defined &$method ) {
$session->logger->log( { level => 'info', action => $action } );
no strict 'refs';
no strict 'refs'; ## no critic
&$method($session);
}
else {
Expand Down
9 changes: 5 additions & 4 deletions core/lib/Foswiki/UI/Register.pm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ sub register_cgi {
$session->enterContext('absolute_urls');

try {
no strict 'refs';
no strict 'refs'; ## no critic
&$handler($session);
use strict 'refs';
}
Expand Down Expand Up @@ -1953,12 +1953,13 @@ sub _validateRegistration {
}
catch Error with {
my $e = shift;
$e =~ s/ at .*//ms;
throw Foswiki::OopsException(
'register',
web => $data->{webName},
topic => $session->{topicName},
def => 'registration_invalid',
params => [ $e->stringify ]
params => [$e]
);

};
Expand Down Expand Up @@ -2073,10 +2074,10 @@ sub _clearPendingRegistrationsForUser {

# Remove the integer code to leave just the wikiname
$file =~ s/\.\d+$//;
foreach my $f (<$file.*>) {
foreach my $f ( glob("$file.*") ) {

# Read from disc, implictly validated
unlink( Foswiki::Sandbox::untaintUnchecked($f) );
unlink Foswiki::Sandbox::untaintUnchecked($f);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/UI/Rest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ sub rest {
my $error = 0;

try {
no strict 'refs';
no strict 'refs'; ## no critic
$result = &$function( $session, $subject, $verb, $session->{response} );
use strict 'refs';
}
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/UI/Save.pm
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ WARN
}

if ($attachments) {
foreach $a ( @{$attachments} ) {
foreach my $a ( @{$attachments} ) {
try {
$a->{tom}->copyAttachment( $a->{name}, $topicObject );
}
Expand Down
10 changes: 7 additions & 3 deletions core/lib/Foswiki/UI/Statistics.pm
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,15 @@ sub _getTopList {
if (@list) {

# Strip initial spaces
@list = map { s/^\s*//; $_ } @list;
@list = map { my $tmp = $_; $tmp =~ s/^\s*//; $tmp } @list;

@list = # Prepend spaces depending on no. of digits
map { s/^([0-9][0-9][^0-9])/\&nbsp\;$1/; $_ }
map { s/^([0-9][^0-9])/\&nbsp\;\&nbsp\;$1/; $_ }
map { my $tmp = $_; $tmp =~ s/^([0-9][0-9][^0-9])/\&nbsp\;$1/; $tmp }
map {
my $tmp = $_;
$tmp =~ s/^([0-9][^0-9])/\&nbsp\;\&nbsp\;$1/;
$tmp
}

# Sort numerically, descending order
sort { ( split / /, $b )[0] <=> ( split / /, $a )[0] } @list;
Expand Down

0 comments on commit 67e910d

Please sign in to comment.