From 11688be1e2afc0989e57fc3f85c88f4042283e7d Mon Sep 17 00:00:00 2001 From: CrawfordCurrie Date: Sun, 4 Mar 2012 11:25:10 +0000 Subject: [PATCH] Item11317: perltidy git-svn-id: http://svn.foswiki.org/trunk@14202 0b4bb1d4-4e5a-0410-9cc4-b2b747904278 --- UnitTestContrib/test/unit/Fn_SEARCH.pm | 2 +- core/lib/Foswiki/Macros/INCLUDE.pm | 62 +++++++++++++++----------- core/lib/Foswiki/Render.pm | 33 +++++++------- core/lib/Foswiki/Search.pm | 30 +++++++------ 4 files changed, 70 insertions(+), 57 deletions(-) diff --git a/UnitTestContrib/test/unit/Fn_SEARCH.pm b/UnitTestContrib/test/unit/Fn_SEARCH.pm index d213d6bc44..6cb7106678 100644 --- a/UnitTestContrib/test/unit/Fn_SEARCH.pm +++ b/UnitTestContrib/test/unit/Fn_SEARCH.pm @@ -808,7 +808,7 @@ HERE %SEARCH{"---+" multiple="on" web="$this->{test_web}" topic="TestHINC" format="\$text" headingoffset="3"}% HERE - $this->assert_str_equals(<assert_str_equals( <Searched: ---+ ---+ H4 diff --git a/core/lib/Foswiki/Macros/INCLUDE.pm b/core/lib/Foswiki/Macros/INCLUDE.pm index 63317fce01..c4d0129cac 100644 --- a/core/lib/Foswiki/Macros/INCLUDE.pm +++ b/core/lib/Foswiki/Macros/INCLUDE.pm @@ -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; @@ -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', @@ -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 { @@ -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 = "\n$text\n"; + if ( $hoff && $hoff =~ /^([-+]?\d+)$/ && $1 != 0 ) { + my ( $off, $noff ) = ( 0 + $1, 0 - $1 ); + $text = "\n$text\n"; } return $text; diff --git a/core/lib/Foswiki/Render.pm b/core/lib/Foswiki/Render.pm index 0ed22b20db..02b8939d16 100644 --- a/core/lib/Foswiki/Render.pm +++ b/core/lib/Foswiki/Render.pm @@ -451,8 +451,8 @@ sub _makeAnchorHeading { my $html = ' ' + . $level . ' ' . 'id="' + . $anchors->makeHTMLTarget($text) . '"> ' . $text . ' '; @@ -1086,27 +1086,28 @@ sub renderFORMFIELD { sub _adjustH { my ($text) = @_; - my @blocks = split(/()/i, $text); + my @blocks = split( /()/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 =~ /^$/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 =~ /^$/i && $1 ) { + $off += $1; + } + else { + $i =~ s/(<\/?h)(\d)((\s+.*?)?>)/$1 . _cap($2 + $off) . $3/gesi + if ($off); + $out .= $i; + } } return $out; } diff --git a/core/lib/Foswiki/Search.pm b/core/lib/Foswiki/Search.pm index 4a1a51ba88..2bd500992f 100644 --- a/core/lib/Foswiki/Search.pm +++ b/core/lib/Foswiki/Search.pm @@ -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() }; @@ -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 { - $_ =~ "\n$text\n" - } @multipleHitLines; - } else { - $text = "\n$text\n"; - } - } + # 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 { + $_ =~ "\n$text\n" + } @multipleHitLines; + } + else { + $text = "\n$text\n"; + } + } } $ntopics += 1; @@ -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 );