Skip to content

Commit

Permalink
Item11317: perltidy
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@14202 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Mar 4, 2012
1 parent 31b76b1 commit 11688be
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 57 deletions.
2 changes: 1 addition & 1 deletion UnitTestContrib/test/unit/Fn_SEARCH.pm
Expand Up @@ -808,7 +808,7 @@ HERE
%SEARCH{"---+" multiple="on" web="$this->{test_web}" topic="TestHINC" format="\$text" headingoffset="3"}%
HERE

$this->assert_str_equals(<<EXPECT, $result);
$this->assert_str_equals( <<EXPECT, $result );
<div class="foswikiSearchResultsHeader"><span>Searched: <b><noautolink>---+</noautolink></b></span><span id="foswikiNumberOfResultsContainer"></span></div>
<ho off="3">
---+ H4
Expand Down
62 changes: 35 additions & 27 deletions core/lib/Foswiki/Macros/INCLUDE.pm
Expand Up @@ -112,21 +112,21 @@ sub _includeWarning {
}

sub _includeProtocol {
my ($this, $handler, $control, $params) = @_;
my ( $this, $handler, $control, $params ) = @_;

eval 'use Foswiki::IncludeHandlers::' . $handler . ' ()';
if ($@) {
return $this->_includeWarning(
$control->{warn}, 'bad_include_path', $control->{_DEFAULT} );
return $this->_includeWarning( $control->{warn}, 'bad_include_path',
$control->{_DEFAULT} );
}
else {
$handler = 'Foswiki::IncludeHandlers::' . $handler;
return $handler->INCLUDE( $this, $control, $params );
$handler = 'Foswiki::IncludeHandlers::' . $handler;
return $handler->INCLUDE( $this, $control, $params );
}
}

sub _includeTopic {
my ($this, $includingTopicObject, $control, $params) = @_;
my ( $this, $includingTopicObject, $control, $params ) = @_;

my $text = '';
my $includedWeb;
Expand Down Expand Up @@ -167,7 +167,8 @@ sub _includeTopic {
$this->{_INCLUDES}->{$key} = 1;

my $includedTopicObject =
Foswiki::Meta->load( $this, $includedWeb, $includedTopic, $control->{rev} );
Foswiki::Meta->load( $this, $includedWeb, $includedTopic,
$control->{rev} );
unless ( $includedTopicObject->haveAccess('VIEW') ) {
if ( isTrue( $control->{warn} ) ) {
return $this->inlineAlert( 'alerts', 'access_denied',
Expand Down Expand Up @@ -238,8 +239,9 @@ sub _includeTopic {

if ( $interesting and ( length($text) eq 0 ) ) {
$text =
_includeWarning( $this, $control->{warn}, 'topic_section_not_found',
$includedWeb, $includedTopic, $control->{section} );
_includeWarning( $this, $control->{warn},
'topic_section_not_found', $includedWeb, $includedTopic,
$control->{section} );
}
else {

Expand Down Expand Up @@ -329,39 +331,45 @@ sub INCLUDE {
$control{warn} ||= $this->{prefs}->getPreference('INCLUDEWARNING');

my $text;

# make sure we have something to include. If we don't do this, then
# normalizeWebTopicName will default to WebHome. TWikibug:Item2209.
unless ( $control{_DEFAULT} ) {
$text = $this->_includeWarning( $control{warn}, 'bad_include_path', '' );
$text =
$this->_includeWarning( $control{warn}, 'bad_include_path', '' );
}

# Filter out '..' from path to prevent includes of '../../file'
elsif ( $Foswiki::cfg{DenyDotDotInclude} && $control{_DEFAULT} =~ /\.\./ ) {
$text = $this->_includeWarning( $control{warn}, 'bad_include_path',
$text =
$this->_includeWarning( $control{warn}, 'bad_include_path',
$control{_DEFAULT} );
}

else {
# no sense in considering an empty string as an unfindable section
delete $control{section} if
( defined( $control{section} ) && $control{section} eq '' );
$control{raw} ||= '';
$control{inWeb} = $includingTopicObject->web;
$control{inTopic} = $includingTopicObject->topic;

# Protocol links e.g. http:, https:, doc:
if ( $control{_DEFAULT} =~ /^([a-z]+):/ ) {
$text = $this->_includeProtocol($1, \%control, $params);
} else {
$text = $this->_includeTopic($includingTopicObject, \%control, $params);
}

# no sense in considering an empty string as an unfindable section
delete $control{section}
if ( defined( $control{section} ) && $control{section} eq '' );
$control{raw} ||= '';
$control{inWeb} = $includingTopicObject->web;
$control{inTopic} = $includingTopicObject->topic;

# Protocol links e.g. http:, https:, doc:
if ( $control{_DEFAULT} =~ /^([a-z]+):/ ) {
$text = $this->_includeProtocol( $1, \%control, $params );
}
else {
$text =
$this->_includeTopic( $includingTopicObject, \%control, $params );
}
}

# Apply any heading offset
my $hoff = $params->{headingoffset};
if ($hoff && $hoff =~ /^([-+]?\d+)$/ && $1 != 0) {
my ($off, $noff) = (0 + $1, 0 - $1);
$text = "<ho off=\"$off\"/>\n$text\n<ho off=\"$noff\">";
if ( $hoff && $hoff =~ /^([-+]?\d+)$/ && $1 != 0 ) {
my ( $off, $noff ) = ( 0 + $1, 0 - $1 );
$text = "<ho off=\"$off\"/>\n$text\n<ho off=\"$noff\">";
}

return $text;
Expand Down
33 changes: 17 additions & 16 deletions core/lib/Foswiki/Render.pm
Expand Up @@ -451,8 +451,8 @@ sub _makeAnchorHeading {

my $html =
'<nop><h'
. $level . ' '
. 'id="' . $anchors->makeHTMLTarget($text) . '"> '
. $level . ' ' . 'id="'
. $anchors->makeHTMLTarget($text) . '"> '
. $text . ' </h'
. $level . '>';

Expand Down Expand Up @@ -1086,27 +1086,28 @@ sub renderFORMFIELD {
sub _adjustH {
my ($text) = @_;

my @blocks = split(/(<ho(?:\s+off="(?:[-+]?\d+)")?\s*\/?>)/i, $text);
my @blocks = split( /(<ho(?:\s+off="(?:[-+]?\d+)")?\s*\/?>)/i, $text );

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

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

my $off = 0;
my $out = '';
while (scalar(@blocks)) {
my $i = shift(@blocks);
if ($i =~ /^<ho(?:\s+off="([-+]?\d+)")?\s*\/?>$/i && $1) {
$off += $1;
} else {
$i =~ s/(<\/?h)(\d)((\s+.*?)?>)/$1 . _cap($2 + $off) . $3/gesi
if ($off);
$out .= $i;
}
while ( scalar(@blocks) ) {
my $i = shift(@blocks);
if ( $i =~ /^<ho(?:\s+off="([-+]?\d+)")?\s*\/?>$/i && $1 ) {
$off += $1;
}
else {
$i =~ s/(<\/?h)(\d)((\s+.*?)?>)/$1 . _cap($2 + $off) . $3/gesi
if ($off);
$out .= $i;
}
}
return $out;
}
Expand Down
30 changes: 17 additions & 13 deletions core/lib/Foswiki/Search.pm
Expand Up @@ -763,6 +763,7 @@ sub formatResults {
#TODO: should extract this somehow

if ( $doMultiple && !$query->isEmpty() ) {

#TODO: Sven wonders if this should be a HoistRE..
#TODO: well, um, and how does this work for query search?
my @tokens = @{ $query->tokens() };
Expand All @@ -781,18 +782,21 @@ sub formatResults {
}
}

# Apply heading offset - posibly to each hit result independently
if ($params->{headingoffset} && $params->{headingoffset} =~ /^([-+]?\d+)$/
&& $1 != 0) {
my ($off, $noff) = (0 + $1, 0 - $1);
if ( scalar(@multipleHitLines) ) {
@multipleHitLines = map {
$_ =~ "<ho off=\"$off\">\n$text\n<ho off=\"$noff\"/>"
} @multipleHitLines;
} else {
$text = "<ho off=\"$off\">\n$text\n<ho off=\"$noff\"/>";
}
}
# Apply heading offset - posibly to each hit result independently
if ( $params->{headingoffset}
&& $params->{headingoffset} =~ /^([-+]?\d+)$/
&& $1 != 0 )
{
my ( $off, $noff ) = ( 0 + $1, 0 - $1 );
if ( scalar(@multipleHitLines) ) {
@multipleHitLines = map {
$_ =~ "<ho off=\"$off\">\n$text\n<ho off=\"$noff\"/>"
} @multipleHitLines;
}
else {
$text = "<ho off=\"$off\">\n$text\n<ho off=\"$noff\"/>";
}
}
}

$ntopics += 1;
Expand Down Expand Up @@ -1085,7 +1089,7 @@ sub formatResults {
}

my $result = '';
if ( ! defined $params->{_callback} && $nhits >= 0 ) {
if ( !defined $params->{_callback} && $nhits >= 0 ) {
$result = join( '', @$cbdata );
}
return ( $ntopics, $result );
Expand Down

0 comments on commit 11688be

Please sign in to comment.