diff --git a/UnitTestContrib/lib/Unit/TestCase.pm b/UnitTestContrib/lib/Unit/TestCase.pm index bbbeb963f6..fd677a84df 100644 --- a/UnitTestContrib/lib/Unit/TestCase.pm +++ b/UnitTestContrib/lib/Unit/TestCase.pm @@ -263,7 +263,7 @@ sub assert { $mess ||= "Assertion failed"; $mess = join( "\n", @{ $this->annotations } ) . "\n" . $mess; $mess = Carp::longmess($mess); - die $mess; + Foswiki::Exception::ASSERT->throw( text => $mess, object => $this ); } =begin TML diff --git a/UnitTestContrib/lib/Unit/TestRunner.pm b/UnitTestContrib/lib/Unit/TestRunner.pm index 734fb81823..319c5e6f70 100644 --- a/UnitTestContrib/lib/Unit/TestRunner.pm +++ b/UnitTestContrib/lib/Unit/TestRunner.pm @@ -495,7 +495,7 @@ DIE eval "use $suite"; die $@ if $@; - my $tester = $suite->new($suite); + my $tester = $suite->new( testSuite => $suite ); my $log = "stdout.$$.log"; require Unit::Eavesdrop; diff --git a/UnitTestContrib/test/unit/Fn_QUERY.pm b/UnitTestContrib/test/unit/Fn_QUERY.pm index fb0d9b9efe..5c0af1e067 100644 --- a/UnitTestContrib/test/unit/Fn_QUERY.pm +++ b/UnitTestContrib/test/unit/Fn_QUERY.pm @@ -132,12 +132,12 @@ sub test_badQUERY { unless ($post11); foreach my $test (@tests) { - my $text = '%QUERY{"' . $test->test . '"}%'; + my $text = '%QUERY{"' . $test->{test} . '"}%'; my $result = $this->test_topicObject->expandMacros($text); $result =~ s/^.*foswikiAlert'>\s*//s; $result =~ s/\s*<\/span>\s*//s; $this->assert( $result =~ s/^.*}:\s*//s, $text ); - $this->assert_str_equals( $test->expect, $result ); + $this->assert_str_equals( $test->{expect}, $result ); } my $result = $this->test_topicObject->expandMacros('%QUERY%'); @@ -393,7 +393,7 @@ SMELL $topicObject0Att->save(); my $text = <test_topicObject->expandMacros($text); $this->assert_equals( <SUPER::new( 'QUERYPARAMS', @_ ); - return $self; -} - -sub set_up { - my $this = shift; - $this->SUPER::set_up(@_); -} +around BUILDARGS => sub { + my $orig = shift; + return $orig->( @_, testSuite => 'QUERYPARAMS' ); +}; sub test_default { my $this = shift; @@ -24,17 +19,17 @@ sub test_default { # test default parameter - $str = $this->{test_topicObject}->expandMacros('%QUERYPARAMS%'); + $str = $this->test_topicObject->expandMacros('%QUERYPARAMS%'); $this->assert_str_equals( '', "$str" ); - $this->{request}->param( -name => 'foo', -value => '\'"%' ); - $str = $this->{test_topicObject}->expandMacros('%QUERYPARAMS%'); + $this->request->param( -name => 'foo', -value => '\'"%' ); + $str = $this->test_topicObject->expandMacros('%QUERYPARAMS%'); $this->assert_str_equals( 'foo=<evil script>'"%', "$str" ); - $this->{request}->param( -name => 'foo', -value => '\'"%' ); - $this->{request}->param( -name => 'fee', -value => 'free' ); - $str = $this->{test_topicObject}->expandMacros('%QUERYPARAMS%'); + $this->request->param( -name => 'foo', -value => '\'"%' ); + $this->request->param( -name => 'fee', -value => 'free' ); + $str = $this->test_topicObject->expandMacros('%QUERYPARAMS%'); $this->assert_str_equals( "foo=<evil script>'"%\nfee=free", "$str" ); } @@ -46,17 +41,17 @@ sub test_multi { # test multiple parameters - $str = $this->{test_topicObject}->expandMacros('%QUERYPARAMS%'); + $str = $this->test_topicObject->expandMacros('%QUERYPARAMS%'); $this->assert_str_equals( '', "$str" ); - $this->{request}->param( -name => 'foo', -value => ( 'beer', 'free' ) ); - $str = $this->{test_topicObject}->expandMacros('%QUERYPARAMS%'); + $this->request->param( -name => 'foo', -value => ( 'beer', 'free' ) ); + $str = $this->test_topicObject->expandMacros('%QUERYPARAMS%'); $this->assert_matches( qr/foo=free/, "$str" ); $this->assert_matches( qr/foo=beer/, "$str" ); $this->assert_equals( length($str), 17 ); - $this->{request}->param( -name => 'foo', -value => ( 'beer', 'beer' ) ); - $str = $this->{test_topicObject}->expandMacros('%QUERYPARAMS%'); + $this->request->param( -name => 'foo', -value => ( 'beer', 'beer' ) ); + $str = $this->test_topicObject->expandMacros('%QUERYPARAMS%'); $this->assert_matches( qr/^foo=beer\nfoo=beer$/, "$str" ); } @@ -65,47 +60,55 @@ sub test_encode { my $str; - $this->{request} - ->param( -name => 'foo', -value => "\n&\'\"%*A" ); - $this->{request}->param( -name => 'fee', -value => 'free' ); + $this->request->param( + -name => 'foo', + -value => "\n&\'\"%*A" + ); + $this->request->param( -name => 'fee', -value => 'free' ); $str = - $this->{test_topicObject} - ->expandMacros('%QUERYPARAMS{encoding="entity"}%'); + $this->test_topicObject->expandMacros('%QUERYPARAMS{encoding="entity"}%'); $this->assert_str_equals( "foo=<evil script>\n&'"%*A\nfee=free", "$str" ); - $this->{request} - ->param( -name => 'foo', -value => "\n&\'\"%*A" ); - $this->{request}->param( -name => 'fee', -value => 'free' ); + $this->request->param( + -name => 'foo', + -value => "\n&\'\"%*A" + ); + $this->request->param( -name => 'fee', -value => 'free' ); $str = - $this->{test_topicObject}->expandMacros('%QUERYPARAMS{encoding="safe"}%'); + $this->test_topicObject->expandMacros('%QUERYPARAMS{encoding="safe"}%'); $this->assert_str_equals( "foo=<evil script>\n&'"%*A\nfee=free", "$str" ); - $this->{request} - ->param( -name => 'foo', -value => "\n&\'\"%*A" ); - $this->{request}->param( -name => 'fee', -value => 'free' ); + $this->request->param( + -name => 'foo', + -value => "\n&\'\"%*A" + ); + $this->request->param( -name => 'fee', -value => 'free' ); $str = - $this->{test_topicObject}->expandMacros('%QUERYPARAMS{encoding="html"}%'); + $this->test_topicObject->expandMacros('%QUERYPARAMS{encoding="html"}%'); $this->assert_str_equals( "foo=<evil script> &'"%*A\nfee=free", "$str" ); - $this->{request} - ->param( -name => 'foo', -value => "\n&\'\"%*A" ); - $this->{request}->param( -name => 'fee', -value => 'free' ); + $this->request->param( + -name => 'foo', + -value => "\n&\'\"%*A" + ); + $this->request->param( -name => 'fee', -value => 'free' ); $str = - $this->{test_topicObject} - ->expandMacros('%QUERYPARAMS{encoding="quotes"}%'); + $this->test_topicObject->expandMacros('%QUERYPARAMS{encoding="quotes"}%'); $this->assert_str_equals( "foo=\n&\'\\\"%*A\nfee=free", "$str" ); - $this->{request} - ->param( -name => 'foo', -value => "\n&\'\"%*A" ); - $this->{request}->param( -name => 'fee', -value => 'free' ); + $this->request->param( + -name => 'foo', + -value => "\n&\'\"%*A" + ); + $this->request->param( -name => 'fee', -value => 'free' ); $str = - $this->{test_topicObject}->expandMacros('%QUERYPARAMS{encoding="url"}%'); + $this->test_topicObject->expandMacros('%QUERYPARAMS{encoding="url"}%'); $this->assert_str_equals( "foo=%3cevil%20script%3e%0a%26%27%22%25*A\nfee=free", "$str" ); } @@ -115,11 +118,11 @@ sub test_format { my $str; - $this->{request}->param( -name => 'foo', -value => '\'"%' ); - $this->{request}->param( -name => 'fee', -value => 'free' ); + $this->request->param( -name => 'foo', -value => '\'"%' ); + $this->request->param( -name => 'fee', -value => 'free' ); $str = - $this->{test_topicObject} - ->expandMacros('%QUERYPARAMS{format="$name is equal to $value"}%'); + $this->test_topicObject->expandMacros( + '%QUERYPARAMS{format="$name is equal to $value"}%'); $this->assert_str_equals( "foo is equal to <evil script>'"%\nfee is equal to free", "$str" @@ -132,9 +135,9 @@ sub test_no_format_no_separator { my $str; - $this->{request}->param( -name => 'foo', -value => '\'"%' ); - $this->{request}->param( -name => 'fee', -value => 'free' ); - $str = $this->{test_topicObject}->expandMacros('%QUERYPARAMS{}%'); + $this->request->param( -name => 'foo', -value => '\'"%' ); + $this->request->param( -name => 'fee', -value => 'free' ); + $str = $this->test_topicObject->expandMacros('%QUERYPARAMS{}%'); $this->assert_str_equals( "foo=<evil script>'"%\nfee=free", "$str" ); } @@ -144,11 +147,10 @@ sub test_no_format_with_separator { my $str; - $this->{request}->param( -name => 'foo', -value => '\'"%' ); - $this->{request}->param( -name => 'fee', -value => 'free' ); + $this->request->param( -name => 'foo', -value => '\'"%' ); + $this->request->param( -name => 'fee', -value => 'free' ); $str = - $this->{test_topicObject} - ->expandMacros('%QUERYPARAMS{separator="NEXT"}%'); + $this->test_topicObject->expandMacros('%QUERYPARAMS{separator="NEXT"}%'); $this->assert_str_equals( "foo=<evil script>'"%NEXTfee=free", "$str" ); } @@ -158,10 +160,9 @@ sub test_no_format_empty_separator { my $str; - $this->{request}->param( -name => 'foo', -value => '\'"%' ); - $this->{request}->param( -name => 'fee', -value => 'free' ); - $str = - $this->{test_topicObject}->expandMacros('%QUERYPARAMS{separator=""}%'); + $this->request->param( -name => 'foo', -value => '\'"%' ); + $this->request->param( -name => 'fee', -value => 'free' ); + $str = $this->test_topicObject->expandMacros('%QUERYPARAMS{separator=""}%'); $this->assert_str_equals( "foo=<evil script>'"%fee=free", "$str" ); } @@ -171,11 +172,11 @@ sub test_with_format_no_separator { my $str; - $this->{request}->param( -name => 'foo', -value => '\'"%' ); - $this->{request}->param( -name => 'fee', -value => 'free' ); + $this->request->param( -name => 'foo', -value => '\'"%' ); + $this->request->param( -name => 'fee', -value => 'free' ); $str = - $this->{test_topicObject} - ->expandMacros('%QUERYPARAMS{format="$name is equal to $value"}%'); + $this->test_topicObject->expandMacros( + '%QUERYPARAMS{format="$name is equal to $value"}%'); $this->assert_str_equals( "foo is equal to <evil script>'"%\nfee is equal to free", "$str" @@ -187,10 +188,10 @@ sub test_with_format_with_separator { my $str; - $this->{request}->param( -name => 'foo', -value => '\'"%' ); - $this->{request}->param( -name => 'fee', -value => 'free' ); + $this->request->param( -name => 'foo', -value => '\'"%' ); + $this->request->param( -name => 'fee', -value => 'free' ); $str = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%QUERYPARAMS{format="$name is equal to $value" separator="NEXT"}%'); $this->assert_str_equals( "foo is equal to <evil script>'"%NEXTfee is equal to free", @@ -203,10 +204,9 @@ sub test_with_format_empty_separator { my $str; - $this->{request}->param( -name => 'foo', -value => '\'"%' ); - $this->{request}->param( -name => 'fee', -value => 'free' ); - $str = - $this->{test_topicObject}->expandMacros( + $this->request->param( -name => 'foo', -value => '\'"%' ); + $this->request->param( -name => 'fee', -value => 'free' ); + $str = $this->test_topicObject->expandMacros( '%QUERYPARAMS{format="$name is equal to $value" separator=""}%'); $this->assert_str_equals( "foo is equal to <evil script>'"%fee is equal to free", @@ -219,10 +219,10 @@ sub test_stdescapes_not_expanded { my $str; - $this->{request}->param( -name => 'percent', -value => '$percnt' ); - $this->{request}->param( -name => 'dollar', -value => '$dollar' ); + $this->request->param( -name => 'percent', -value => '$percnt' ); + $this->request->param( -name => 'dollar', -value => '$dollar' ); $str = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%QUERYPARAMS{format="$dollarname $name is equal to $dollarvalue $value" separator="$n"}%' ); my $expected = <<'FOO'; diff --git a/UnitTestContrib/test/unit/Fn_REVINFO.pm b/UnitTestContrib/test/unit/Fn_REVINFO.pm index c0b32ca607..13762d1921 100644 --- a/UnitTestContrib/test/unit/Fn_REVINFO.pm +++ b/UnitTestContrib/test/unit/Fn_REVINFO.pm @@ -1,47 +1,54 @@ # tests for the correct expansion of REVINFO package Fn_REVINFO; -use strict; -use warnings; -use FoswikiFnTestCase(); -our @ISA = qw( FoswikiFnTestCase ); +use v5.14; use Foswiki(); use Foswiki::Time(); -use Error qw( :try ); +use Try::Tiny; -sub new { - my ( $class, @args ) = @_; +use Moo; +use namespace::clean; +extends qw( FoswikiFnTestCase ); +has guest_wikiname => ( is => 'rw', ); +has test_user_wikiname => ( is => 'rw', ); + +around BUILDARGS => sub { + my $orig = shift; + + # SMELL Wouldn't it be better set in set_up and restored in tear_up? $Foswiki::cfg{Register}{AllowLoginName} = 1; - return $class->SUPER::new( 'REVINFO', @args ); -} + return $orig->( @_, testSuite => 'REVINFO' ); +}; -sub set_up { +around set_up => sub { + my $orig = shift; my $this = shift; - $this->SUPER::set_up(@_); - $this->{guest_wikiname} = Foswiki::Func::getWikiName(); - $this->{session}->{user} = $this->{test_user_cuid}; # OUCH + $orig->( $this, @_ ); + $this->guest_wikiname( Foswiki::Func::getWikiName() ); + $this->session->user( $this->test_user_cuid ); # OUCH my ($topicObject) = - Foswiki::Func::readTopic( $this->{users_web}, "GropeGroup" ); + Foswiki::Func::readTopic( $this->users_web, "GropeGroup" ); $topicObject->text(" * Set GROUP = ScumBag,WikiGuest\n"); $topicObject->save(); $topicObject->finish(); - ($topicObject) = Foswiki::Func::readTopic( $this->{test_web}, "GlumDrop" ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, "GlumDrop" ); $topicObject->text("Burble\n"); $topicObject->save(); $topicObject->finish(); return; -} +}; sub test_basic { my $this = shift; - my $ui = $this->{test_topicObject}->expandMacros('%REVINFO%'); + my $ui = $this->test_topicObject->expandMacros('%REVINFO%'); + my $users_web = $this->users_web; + my $guest_wikiname = $this->guest_wikiname; unless ( $ui =~ -m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $this->{users_web}\.$this->{guest_wikiname}$/ - ) + m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $users_web\.$guest_wikiname$/ ) { $this->assert( 0, $ui ); } @@ -52,12 +59,12 @@ m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $this->{users_web}\.$this->{guest_wikiname}$ sub test_basic2 { my $this = shift; - my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'GlumDrop' ); - my $ui = $topicObject->expandMacros('%REVINFO%'); + my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'GlumDrop' ); + my $ui = $topicObject->expandMacros('%REVINFO%'); + my $users_web = $this->users_web; + my $test_user_wikiname = $this->test_user_wikiname; unless ( $ui =~ -m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $this->{users_web}\.$this->{test_user_wikiname}$/ - ) + m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $users_web\.$test_user_wikiname$/ ) { $this->assert( 0, $ui ); } @@ -69,12 +76,12 @@ m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $this->{users_web}\.$this->{test_user_wikina sub test_basic3 { my $this = shift; - my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'GlumDrop' ); - my $ui = $topicObject->expandMacros('%REVINFO{topic="GlumDrop"}%'); + my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'GlumDrop' ); + my $ui = $topicObject->expandMacros('%REVINFO{topic="GlumDrop"}%'); + my $users_web = $this->users_web; + my $test_user_wikiname = $this->test_user_wikiname; unless ( $ui =~ -m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $this->{users_web}\.$this->{test_user_wikiname}$/ - ) + m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $users_web\.$test_user_wikiname$/ ) { $this->assert( 0, $ui ); } @@ -86,13 +93,13 @@ m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $this->{users_web}\.$this->{test_user_wikina sub test_thisWebVars { my $this = shift; - my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'GlumDrop' ); + my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'GlumDrop' ); my $ui = $topicObject->expandMacros('%REVINFO{topic="%BASEWEB%.GlumDrop"}%'); + my $users_web = $this->users_web; + my $test_user_wikiname = $this->test_user_wikiname; unless ( $ui =~ -m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $this->{users_web}\.$this->{test_user_wikiname}$/ - ) + m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $users_web\.$test_user_wikiname$/ ) { $this->assert( 0, $ui ); } @@ -105,12 +112,12 @@ m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $this->{users_web}\.$this->{test_user_wikina sub BROKENtest_thisTopicVars { my $this = shift; - my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'GlumDrop' ); + my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'GlumDrop' ); my $ui = $topicObject->expandMacros('%REVINFO{topic="%BASETOPIC%"}%'); + my $users_web = $this->users_web; + my $test_user_wikiname = $this->test_user_wikiname; unless ( $ui =~ -m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $this->{users_web}\.$this->{test_user_wikiname}$/ - ) + m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $users_web\.$test_user_wikiname$/ ) { $this->assert( 0, $ui ); } @@ -122,13 +129,13 @@ m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $this->{users_web}\.$this->{test_user_wikina sub BROKENtest_thisWebTopicVars { my $this = shift; - my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'GlumDrop' ); + my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'GlumDrop' ); my $ui = $topicObject->expandMacros('%REVINFO{topic="%BASEWEB%.%BASETOPIC%"}%'); + my $users_web = $this->users_web; + my $test_user_wikiname = $this->test_user_wikiname; unless ( $ui =~ -m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $this->{users_web}\.$this->{test_user_wikiname}$/ - ) + m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $users_web\.$test_user_wikiname$/ ) { $this->assert( 0, $ui ); } @@ -141,13 +148,14 @@ sub test_otherWeb { my $this = shift; my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); + Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); my $ui = $topicObject->expandMacros( - '%REVINFO{topic="GropeGroup" web="' . $this->{users_web} . '"}%', + '%REVINFO{topic="GropeGroup" web="' . $this->users_web . '"}%', ); + my $users_web = $this->users_web; + my $test_user_wikiname = $this->test_user_wikiname; unless ( $ui =~ -m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $this->{users_web}\.$this->{test_user_wikiname}$/ - ) + m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $users_web\.$test_user_wikiname$/ ) { $this->assert( 0, $ui ); } @@ -160,12 +168,13 @@ sub test_otherWeb2 { my $this = shift; my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); + Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); my $ui = $topicObject->expandMacros( - '%REVINFO{topic="' . $this->{users_web} . '.GropeGroup"}%' ); + '%REVINFO{topic="' . $this->users_web . '.GropeGroup"}%' ); + my $users_web = $this->users_web; + my $test_user_wikiname = $this->test_user_wikiname; unless ( $ui =~ -m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $this->{users_web}\.$this->{test_user_wikiname}$/ - ) + m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $users_web\.$test_user_wikiname$/ ) { $this->assert( 0, $ui ); } @@ -177,12 +186,14 @@ m/^r1 - \d+ \w+ \d+ - \d+:\d+:\d+ - $this->{users_web}\.$this->{test_user_wikina sub test_formatUser { my $this = shift; - my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'GlumDrop' ); + my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'GlumDrop' ); my $ui = $topicObject->expandMacros( '%REVINFO{format="$username $wikiname $wikiusername"}%'); $this->assert_str_equals( -"$this->{test_user_login} $this->{test_user_wikiname} $this->{users_web}\.$this->{test_user_wikiname}", + $this->test_user_login . " " + . $this->test_user_wikiname . " " + . $this->users_web . "." + . $this->test_user_wikiname, $ui ); $topicObject->finish(); @@ -193,12 +204,14 @@ sub test_formatUser { sub test_std_escapes { my $this = shift; - my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'GlumDrop' ); + my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'GlumDrop' ); my $ui = $topicObject->expandMacros( '%REVINFO{format="$username$comma $wikiname $lt$wikiusername$gt"}%'); $this->assert_str_equals( -"$this->{test_user_login}, $this->{test_user_wikiname} <$this->{users_web}\.$this->{test_user_wikiname}>", + $this->test_user_login . ", " + . $this->test_user_wikiname . " <" + . $this->users_web . "." + . $this->test_user_wikiname . ">", $ui ); $topicObject->finish(); @@ -218,7 +231,7 @@ sub test_compatibility1 { return; } my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'CrikeyMoses' ); + Foswiki::Func::readTopic( $this->test_web, 'CrikeyMoses' ); $topicObject->put( 'TOPICINFO', { @@ -230,8 +243,7 @@ sub test_compatibility1 { ); $topicObject->save(); $topicObject->finish(); - ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'CrikeyMoses' ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'CrikeyMoses' ); my $ui = $topicObject->expandMacros('%REVINFO{format="$username $wikiname"}%'); $this->assert_str_equals( "scum ScumBag", $ui ); @@ -251,7 +263,7 @@ sub test_compatibility2 { return; } my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'CrikeyMoses' ); + Foswiki::Func::readTopic( $this->test_web, 'CrikeyMoses' ); $topicObject->put( 'TOPICINFO', { @@ -263,8 +275,7 @@ sub test_compatibility2 { ); $topicObject->save(); $topicObject->finish(); - ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'CrikeyMoses' ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'CrikeyMoses' ); my $ui = $topicObject->expandMacros('%REVINFO{format="$username $wikiname"}%'); $this->assert_str_equals( "scum ScumBag", $ui ); @@ -286,7 +297,7 @@ sub test_5873 { $this->assert( open( my $F, '>', - "$Foswiki::cfg{DataDir}/$this->{test_web}/GeeWillikins.txt" + "$Foswiki::cfg{DataDir}/" . $this->test_web . "/GeeWillikins.txt" ) ); print $F <<'HERE'; @@ -295,7 +306,7 @@ HERE $this->assert( close($F) ); $Foswiki::cfg{RenderLoggedInButUnknownUsers} = 0; my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'GeeWillikins' ); + Foswiki::Func::readTopic( $this->test_web, 'GeeWillikins' ); my $ui = $topicObject->expandMacros( '%REVINFO{format="$username $wikiname $wikiusername"}%'); $this->assert_str_equals( "eltonjohn eltonjohn eltonjohn", $ui ); @@ -311,15 +322,15 @@ HERE sub test_42 { my $this = shift; my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, "HappyPill" ); + Foswiki::Func::readTopic( $this->test_web, "HappyPill" ); $topicObject->text(" * Set ALLOWTOPICVIEW = CarlosCastenada\n"); $topicObject->save(); $topicObject->finish(); $this->createNewFoswikiSession(); - ($topicObject) = Foswiki::Func::readTopic( $this->{test_web}, 'GlumDrop' ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'GlumDrop' ); my $ui = $topicObject->expandMacros( '%REVINFO{topic="' - . $this->{test_web} + . $this->test_web . '.HappyPill" format="$username $wikiname $wikiusername"}%', ); $this->assert( $ui =~ m/No permission to view/ ); @@ -335,8 +346,7 @@ sub test_42 { sub test_CaseSensitiveFormatString { my $this = shift; - my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'GlumDrop' ); + my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'GlumDrop' ); my $ui = $topicObject->expandMacros( '%REVINFO{format="$DATE"}%', ); $this->assert_str_equals( '$DATE', $ui ); $topicObject->finish(); @@ -350,7 +360,8 @@ sub test_Item9538 { my ($topicObject) = $this->_createHistory(); - my $ui = $topicObject->expandMacros(<<'OFNIVER'); + my $test_web = $this->test_web; + my $ui = $topicObject->expandMacros(<<'OFNIVER'); %REVINFO{"$rev" rev="1"}% %REVINFO{"$rev" rev="1.2"}% %REVINFO{"$rev" topic="BlessMySoul" rev="3"}% @@ -366,7 +377,7 @@ OFNIVER 3 4 4 -$this->{test_web} 4 +$test_web 4 BlessMySoul 4 4 OFNIVER @@ -419,7 +430,7 @@ sub _createHistory { $topic ||= 'BlessMySoul'; $num ||= 4; - my ($topicObject) = Foswiki::Func::readTopic( $this->{test_web}, $topic ); + my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, $topic ); $topicObject->save(); # rev 1 my @texts = [ diff --git a/UnitTestContrib/test/unit/Fn_SCRIPTURL.pm b/UnitTestContrib/test/unit/Fn_SCRIPTURL.pm index a38a4d99e8..e7ec30cd4a 100644 --- a/UnitTestContrib/test/unit/Fn_SCRIPTURL.pm +++ b/UnitTestContrib/test/unit/Fn_SCRIPTURL.pm @@ -3,17 +3,19 @@ use strict; # tests for the correct expansion of SCRIPTURL package Fn_SCRIPTURL; - -use FoswikiFnTestCase; -our @ISA = qw( FoswikiFnTestCase ); +use v5.14; use Foswiki; -use Error qw( :try ); +use Try::Tiny; -sub new { - my $self = shift()->SUPER::new( 'SCRIPTURL', @_ ); - return $self; -} +use Moo; +use namespace::clean; +extends qw( FoswikiFnTestCase ); + +around BUILDARGS => sub { + my $orig = shift; + return $orig->( @_, testSuite => 'SCRIPTURL' ); +}; sub test_SCRIPTURL { my $this = shift; @@ -22,15 +24,15 @@ sub test_SCRIPTURL { undef $Foswiki::cfg{ScriptUrlPaths}{view}; $Foswiki::cfg{ScriptSuffix} = ".dot"; - my $result = $this->{test_topicObject}->expandMacros("%SCRIPTURL%"); + my $result = $this->test_topicObject->expandMacros("%SCRIPTURL%"); $this->assert_str_equals( "$Foswiki::cfg{DefaultUrlHost}$Foswiki::cfg{ScriptUrlPath}", $result ); - $result = $this->{test_topicObject}->expandMacros("%SCRIPTURLPATH{view}%"); + $result = $this->test_topicObject->expandMacros("%SCRIPTURLPATH{view}%"); $this->assert_str_equals( "$Foswiki::cfg{ScriptUrlPath}/view.dot", $result ); - $result = $this->{test_topicObject}->expandMacros("%SCRIPTURLPATH{snarf}%"); + $result = $this->test_topicObject->expandMacros("%SCRIPTURLPATH{snarf}%"); $this->assert_str_equals( "sausages", $result ); } diff --git a/UnitTestContrib/test/unit/Fn_SEARCH.pm b/UnitTestContrib/test/unit/Fn_SEARCH.pm index bec72ba485..d2066e0bd5 100644 --- a/UnitTestContrib/test/unit/Fn_SEARCH.pm +++ b/UnitTestContrib/test/unit/Fn_SEARCH.pm @@ -13,71 +13,69 @@ # converted to "verify" - just in case! # package Fn_SEARCH; - +use v5.14; use utf8; -use strict; -use warnings; - -use FoswikiFnTestCase(); -our @ISA = qw( FoswikiFnTestCase ); - -use Assert; use Foswiki(); use Foswiki::Func(); use Foswiki::Search(); use Foswiki::Search::InfoCache(); use English qw( -no_match_vars ); -use Error qw( :try ); +use Try::Tiny; use HTML::Entities; use File::Spec qw(case_tolerant) ; #TODO: this really should be in the Store somehow - but its not worth doing now, as we should really obliterate the issue -sub new { - my ( $class, @args ) = @_; - my $self = $class->SUPER::new( 'SEARCH', @args ); +use Moo; +use namespace::clean; +extends qw( FoswikiFnTestCase ); - return $self; -} +use Assert; + +around BUILDARGS => sub { + my $orig = shift; + return $orig->( @_, testSuite => 'SEARCH' ); +}; # This particular test makes perl chew several hundred megabytes underl 5.10.0 # Devel::Leak::Object does not report any particular problems with this test. # This test is run in a separate process to be able to reclaim that memory # after the test is complete. sub run_in_new_process { - return 1; + return 0; } our $AElig; -sub set_up { +around set_up => sub { + my $orig = shift; my ($this) = shift; - $this->SUPER::set_up(@_); + $orig->( $this, @_ ); my $timestamp = time(); $AElig = $this->toSiteCharSet('OkÆTopic'); - my ($topicObject) = Foswiki::Func::readTopic( $this->{test_web}, $AElig ); + my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, $AElig ); $topicObject->text("BLEEGLE blah/matchme.blah"); $topicObject->save( forcedate => $timestamp + 120 ); $topicObject->finish(); - ($topicObject) = Foswiki::Func::readTopic( $this->{test_web}, 'OkATopic' ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'OkATopic' ); $topicObject->text("BLEEGLE dontmatchme.blah"); $topicObject->save( forcedate => $timestamp + 240 ); $topicObject->finish(); - ($topicObject) = Foswiki::Func::readTopic( $this->{test_web}, 'OkBTopic' ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'OkBTopic' ); $topicObject->text("BLEEGLE dont.matchmeblah"); $topicObject->save( forcedate => $timestamp + 480 ); $topicObject->finish(); ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, + Foswiki::Func::readTopic( $this->test_web, $this->toSiteCharSet('SomeOtherÆØÅTopic') ); $topicObject->text("forrin speak"); $topicObject->save( forcedate => $timestamp + 720 ); $topicObject->finish(); ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'InvisibleTopic' ); + Foswiki::Func::readTopic( $this->test_web, 'InvisibleTopic' ); $topicObject->text("BLEEGLE dont.matchmeblah"); $topicObject->putKeyed( 'PREFERENCE', { name => 'ALLOWTOPICVIEW', value => 'OnlySuperman' } ); @@ -85,7 +83,7 @@ sub set_up { $topicObject->finish(); return; -} +}; sub skip { my ( $this, $test ) = @_; @@ -181,8 +179,7 @@ sub loadExtraConfig { {'Foswiki::Plugins::MongoDBPlugin::Listener'} = 1; require Foswiki::Plugins::MongoDBPlugin; Foswiki::Plugins::MongoDBPlugin::getMongoDB() - ->remove( $this->{test_web}, 'current', - { '_web' => $this->{test_web} } ); + ->remove( $this->test_web, 'current', { '_web' => $this->test_web } ); } return; @@ -199,8 +196,7 @@ sub tear_down { { require Foswiki::Plugins::MongoDBPlugin; Foswiki::Plugins::MongoDBPlugin::getMongoDB() - ->remove( $this->{test_web}, 'current', - { '_web' => $this->{test_web} } ); + ->remove( $this->test_web, 'current', { '_web' => $this->test_web } ); } return; @@ -209,7 +205,7 @@ sub tear_down { sub verify_simple { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( $this->toSiteCharSet( '%SEARCH{"BLEEGLE" topic="OkATopic,OkBTopic,OkÆTopic" nonoise="on" format="$topic"}%' ) @@ -226,7 +222,7 @@ sub verify_Item4692 { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"BLEEGLE" topic="NonExistant" nonoise="on" format="$topic"}%'); $this->assert_str_equals( '', $result ); @@ -239,7 +235,7 @@ sub verify_b { # Test regex with \b, used in rename searches my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"\bmatc[h]me\b" type="regex" topic="OkATopic,OkBTopic,OkÆTopic" nonoise="on" format="$topic"}%' ); @@ -254,8 +250,8 @@ sub verify_stop_word_Item13383 { my $this = shift; my $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"a" type="word" pager="on"}%'); + $this->test_topicObject->expandMacros( + '%SEARCH{"a" type="word" pager="on"}%'); $this->assert_matches( qr#Number of topics: 0#, $result ); @@ -268,7 +264,7 @@ sub verify_topicName { # Test topic name search my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Ok.*" type="regex" scope="topic" nonoise="on" format="$topic"}%' ); @@ -283,7 +279,7 @@ sub verify_regex_trivial { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"blah" type="regex" scope="text" nonoise="on" format="$topic"}%' ); @@ -300,7 +296,7 @@ sub verify_literal { # literal my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"blah" type="literal" scope="text" nonoise="on" format="$topic"}%' ); @@ -317,7 +313,7 @@ sub verify_keyword { # keyword my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"blah" type="keyword" scope="text" nonoise="on" format="$topic"}%' ); @@ -334,7 +330,7 @@ sub verify_word { # word my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"blah" type="word" scope="text" nonoise="on" format="$topic"}%' ); @@ -351,28 +347,27 @@ sub verify_scope_all_type_word { my $this = shift; my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'VirtualBeer' ); + Foswiki::Func::readTopic( $this->test_web, 'VirtualBeer' ); $topicObject->text("There are alot of Virtual Beers to go around"); $topicObject->save(); $topicObject->finish(); - ($topicObject) = Foswiki::Func::readTopic( $this->{test_web}, 'RealBeer' ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'RealBeer' ); $topicObject->text("There are alot of Virtual Beer to go around"); $topicObject->save(); $topicObject->finish(); ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'FamouslyBeered' ); + Foswiki::Func::readTopic( $this->test_web, 'FamouslyBeered' ); $topicObject->text( "Virtually speaking there could be alot of famous Beers"); $topicObject->save(); $topicObject->finish(); - ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'VirtualLife' ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'VirtualLife' ); $topicObject->text("In a all life, I would expect to find fine Beer"); $topicObject->save(); $topicObject->finish(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Virtual Beer" type="word" scope="all" nonoise="on" format="$topic"}%' ); @@ -390,28 +385,27 @@ sub verify_scope_all_type_keyword { my $this = shift; my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'VirtualBeer' ); + Foswiki::Func::readTopic( $this->test_web, 'VirtualBeer' ); $topicObject->text("There are alot of Virtual Beers to go around"); $topicObject->save(); $topicObject->finish(); - ($topicObject) = Foswiki::Func::readTopic( $this->{test_web}, 'RealBeer' ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'RealBeer' ); $topicObject->text("There are alot of Virtual Beer to go around"); $topicObject->save(); $topicObject->finish(); ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'FamouslyBeered' ); + Foswiki::Func::readTopic( $this->test_web, 'FamouslyBeered' ); $topicObject->text( "Virtually speaking there could be alot of famous Beers"); $topicObject->save(); $topicObject->finish(); - ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'VirtualLife' ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'VirtualLife' ); $topicObject->text("In a all life, I would expect to find fine Beer"); $topicObject->save(); $topicObject->finish(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Virtual Beer" type="keyword" scope="all" nonoise="on" format="$topic"}%' ); @@ -430,28 +424,27 @@ sub verify_scope_all_type_literal { my $this = shift; my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'VirtualBeer' ); + Foswiki::Func::readTopic( $this->test_web, 'VirtualBeer' ); $topicObject->text("There are alot of Virtual Beers to go around"); $topicObject->save(); $topicObject->finish(); - ($topicObject) = Foswiki::Func::readTopic( $this->{test_web}, 'RealBeer' ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'RealBeer' ); $topicObject->text("There are alot of Virtual Beer to go around"); $topicObject->save(); $topicObject->finish(); ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'FamouslyBeered' ); + Foswiki::Func::readTopic( $this->test_web, 'FamouslyBeered' ); $topicObject->text( "Virtually speaking there could be alot of famous Beers"); $topicObject->save(); $topicObject->finish(); - ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'VirtualLife' ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'VirtualLife' ); $topicObject->text("In a all life, I would expect to find fine Beer"); $topicObject->save(); $topicObject->finish(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Virtual Beer" type="literal" scope="all" nonoise="on" format="$topic"}%' ); @@ -489,7 +482,7 @@ sub _expect_with_deps { # topic= parameters sub verify_default_alpha_order_query { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "1" type="query" @@ -530,7 +523,7 @@ FOSWIKI11 sub verify_default_alpha_order_search { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "." type="regex" @@ -576,7 +569,7 @@ sub _septic { $head = $head ? 'header="HEAD"' : ''; $foot = $foot ? 'footer="FOOT"' : ''; $sep = defined $sep ? "separator=\"$sep\"" : ''; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( $this->toSiteCharSet( "%SEARCH{\"name~'$str'\" type=\"query\" nosearch=\"on\" nosummary=\"on\" nototal=\"on\" excludetopic=\"Some*\" format=\"\$topic\" $head $foot $sep}%" ) @@ -826,8 +819,7 @@ EXPECT sub test_headingoffset { my ( $this, $query, $web ) = @_; - my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'TestHINC' ); + my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'TestHINC' ); $topicObject->text(< @@ -841,10 +833,11 @@ sub test_headingoffset { HERE $topicObject->save(); $topicObject->finish(); - my $result = $this->{test_topicObject}->expandMacros(<test_web; + my $result = $this->test_topicObject->expandMacros(<assert_str_equals( <{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"match" type="regex" scope="text" nonoise="on" format="$topic"}%' ); @@ -900,7 +893,7 @@ sub verify_literal_match { # literal my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"match" type="literal" scope="text" nonoise="on" format="$topic"}%' ); @@ -918,7 +911,7 @@ sub verify_keyword_match { # keyword my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"match" type="keyword" scope="text" nonoise="on" format="$topic"}%' ); @@ -936,7 +929,7 @@ sub verify_word_match { # word my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"match" type="word" scope="text" nonoise="on" format="$topic"}%' ); @@ -956,7 +949,7 @@ sub verify_regex_matchme { # regex my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"matchme" type="regex" scope="text" nonoise="on" format="$topic"}%' ); @@ -974,7 +967,7 @@ sub verify_literal_matchme { # literal my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"matchme" type="literal" scope="text" nonoise="on" format="$topic"}%' ); @@ -992,7 +985,7 @@ sub verify_keyword_matchme { # keyword my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"matchme" type="keyword" scope="text" nonoise="on" format="$topic"}%' ); @@ -1010,7 +1003,7 @@ sub verify_word_matchme { # word my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"matchme" type="word" scope="text" nonoise="on" format="$topic"}%' ); @@ -1030,7 +1023,7 @@ sub verify_minus_regex { # regex my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"matchme -dont" type="regex" scope="text" nonoise="on" format="$topic"}%' ); @@ -1048,7 +1041,7 @@ sub verify_minus_literal { # literal my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"matchme -dont" type="literal" scope="text" nonoise="on" format="$topic"}%' ); @@ -1066,7 +1059,7 @@ sub verify_minus_keyword { # keyword my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"matchme -dont" type="keyword" scope="text" nonoise="on" format="$topic"}%' ); @@ -1083,7 +1076,7 @@ sub verify_minus_word { # word my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"matchme -dont" type="word" scope="text" nonoise="on" format="$topic"}%' ); @@ -1102,7 +1095,7 @@ sub verify_slash_regex { # regex my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"blah/matchme.blah" type="regex" scope="text" nonoise="on" format="$topic"}%' ); @@ -1119,7 +1112,7 @@ sub verify_slash_literal { # literal my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"blah/matchme.blah" type="literal" scope="text" nonoise="on" format="$topic"}%' ); @@ -1136,7 +1129,7 @@ sub verify_slash_keyword { # keyword my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"blah/matchme.blah" type="keyword" scope="text" nonoise="on" format="$topic"}%' ); @@ -1153,7 +1146,7 @@ sub verify_slash_word { # word my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"blah/matchme.blah" type="word" scope="text" nonoise="on" format="$topic"}%' ); @@ -1172,7 +1165,7 @@ sub verify_quote_regex { # regex my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"\"BLEEGLE dont\"" type="regex" scope="text" nonoise="on" format="$topic"}%' ); @@ -1189,7 +1182,7 @@ sub verify_quote_literal { # literal my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"\"BLEEGLE dont\"" type="literal" scope="text" nonoise="on" format="$topic"}%' ); @@ -1206,7 +1199,7 @@ sub verify_quote_keyword { # keyword my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"\"BLEEGLE dont\"" type="keyword" scope="text" nonoise="on" format="$topic"}%' ); @@ -1222,7 +1215,7 @@ sub verify_quote_word { # word my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"\"BLEEGLE dont\"" type="word" scope="text" nonoise="on" format="$topic"}%' ); $this->assert_does_not_match( qr/${AElig}/, $result ); @@ -1236,17 +1229,17 @@ sub verify_SEARCH_3860 { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( $this->toSiteCharSet(<<'HERE') ); + $this->test_topicObject->expandMacros( $this->toSiteCharSet(<<'HERE') ); %SEARCH{"BLEEGLE" topic="OkÆTopic" format="$wikiname $wikiusername" nonoise="on" }% HERE - my $wn = $this->{session}->{users}->getWikiName( $this->{session}->{user} ); - $this->assert_str_equals( "$wn $this->{users_web}.$wn\n", $result ); + my $wn = $this->session->users->getWikiName( $this->session->user ); + $this->assert_str_equals( "$wn " . $this->users_web . ".$wn\n", $result ); $result = - $this->{test_topicObject}->expandMacros( $this->toSiteCharSet(<<'HERE') ); + $this->test_topicObject->expandMacros( $this->toSiteCharSet(<<'HERE') ); %SEARCH{"BLEEGLE" topic="OkÆTopic" format="$createwikiname $createwikiusername" nonoise="on" }% HERE - $this->assert_str_equals( "$wn $this->{users_web}.$wn\n", $result ); + $this->assert_str_equals( "$wn " . $this->users_web . ".$wn\n", $result ); return; } @@ -1255,7 +1248,7 @@ sub verify_search_empty_regex { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"" type="regex" scope="text" nonoise="on" format="$topic"}%'); $this->assert_str_equals( "", $result ); @@ -1266,7 +1259,7 @@ sub verify_search_empty_literal { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"" type="literal" scope="text" nonoise="on" format="$topic"}%' ); $this->assert_str_equals( "", $result ); @@ -1278,7 +1271,7 @@ sub verify_search_empty_keyword { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"" type="keyword" scope="text" nonoise="on" format="$topic"}%' ); $this->assert_str_equals( "", $result ); @@ -1290,7 +1283,7 @@ sub verify_search_empty_word { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"" type="word" scope="text" nonoise="on" format="$topic"}%'); $this->assert_str_equals( "", $result ); @@ -1301,7 +1294,7 @@ sub verify_search_numpty_regex { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"something.Very/unLikelyTo+search-for;-\)" type="regex" scope="text" nonoise="on" format="$topic"}%' ); $this->assert_str_equals( "", $result ); @@ -1313,7 +1306,7 @@ sub verify_search_numpty_literal { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"something.Very/unLikelyTo+search-for;-)" type="literal" scope="text" nonoise="on" format="$topic"}%' ); $this->assert_str_equals( "", $result ); @@ -1325,7 +1318,7 @@ sub verify_search_numpty_keyword { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"something.Very/unLikelyTo+search-for;-)" type="keyword" scope="text" nonoise="on" format="$topic"}%' ); $this->assert_str_equals( "", $result ); @@ -1337,7 +1330,7 @@ sub verify_search_numpty_word { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"something.Very/unLikelyTo+search-for;-)" type="word" scope="text" nonoise="on" format="$topic"}%' ); $this->assert_str_equals( "", $result ); @@ -1360,7 +1353,7 @@ This text is fill in text which is there to ensure that the unique word below do HERE # Create the form - Foswiki::Func::saveTopic( $this->{test_web}, "FormattedSearchForm", undef, + Foswiki::Func::saveTopic( $this->test_web, "FormattedSearchForm", undef, <{test_web}, 'FormattedSearchTopic1' ); + Foswiki::Func::readTopic( $this->test_web, 'FormattedSearchTopic1' ); $topicObject->put( 'TOPICPARENT', { name => "TestCaseAutoFormattedSearch" } ); $topicObject->put( 'FORM', { name => "FormattedSearchForm" } ); @@ -1410,7 +1403,7 @@ sub test_footer_with_ntopics { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"name~\'*Topic\'" type="query" nonoise="on" footer="Total found: $ntopics" format="$topic" excludetopic="SomeOther*"}%' ); @@ -1431,7 +1424,7 @@ sub test_multiple_and_footer_with_ntopics_and_nhits { $this->set_up_for_formatted_search(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Bullet" type="regex" multiple="on" nonoise="on" footer="Total found: $ntopics, Hits: $nhits" format="$text - $nhits"}%' ); @@ -1447,7 +1440,7 @@ sub test_footer_with_ntopics_empty_format { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"name~\'*Topic\'" type="query" nonoise="on" footer="Total found: $ntopics" format="" separator=""}%' ); @@ -1460,7 +1453,7 @@ sub test_nofinalnewline { my $this = shift; # nofinalnewline="off" - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( $this->toSiteCharSet( '%SEARCH{"name~\'OkÆTopic\'" type="query" nonoise="on" format="$topic" nofinalnewline="off"}%' ) @@ -1469,7 +1462,7 @@ sub test_nofinalnewline { $this->assert_str_equals( "${AElig}\n", $result ); # nofinalnewline="on" - $result = $this->{test_topicObject}->expandMacros( + $result = $this->test_topicObject->expandMacros( $this->toSiteCharSet( '%SEARCH{"name~\'OkÆTopic\'" type="query" nonoise="on" format="$topic" nofinalnewline="on"}%' ) @@ -1479,7 +1472,7 @@ sub test_nofinalnewline { # nofinalnewline should default be on $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"name~\'OkÆTopic\'" type="query" nonoise="on" format="$topic"}%' ); @@ -1490,25 +1483,25 @@ sub test_nofinalnewline { sub test_formatted_search_summary_with_exclamation_marks { my $this = shift; - my $session = $this->{session}; + my $session = $this->session; $this->set_up_for_formatted_search(); my $actual, my $expected; $actual = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Anna" topic="FormattedSearchTopic1" type="regex" multiple="on" casesensitive="on" nosearch="on" noheader="on" nototal="on" format="$summary"}%' ); - $actual = $this->{test_topicObject}->renderTML($actual); + $actual = $this->test_topicObject->renderTML($actual); $expected = 'MichaelAnchor, One/WIKI.NET and AnnaAnchor lived in Skagen in DenmarkEurope!. There is a very nice museum you can visit!'; $this->assert_str_equals( $expected, $actual ); $actual = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Anna" topic="FormattedSearchTopic1" type="regex" multiple="on" casesensitive="on" nosearch="on" noheader="on" nototal="on" format="$formfield(Name)"}%' ); - $actual = $this->{test_topicObject}->renderTML($actual); + $actual = $this->test_topicObject->renderTML($actual); $expected = 'AnnaAnchor'; $this->assert_str_equals( $expected, $actual ); @@ -1518,16 +1511,16 @@ sub test_formatted_search_summary_with_exclamation_marks { # Item8718 sub test_formatted_search_with_exclamation_marks_inside_bracket_link { my $this = shift; - my $session = $this->{session}; + my $session = $this->session; $this->set_up_for_formatted_search(); my $actual, my $expected; $actual = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Anna" topic="FormattedSearchTopic1" type="regex" multiple="on" casesensitive="on" nosearch="on" noheader="on" nototal="on" format="[[$web.$topic][$formfield(Name)]]"}%' ); - $actual = $this->{test_topicObject}->renderTML($actual); + $actual = $this->test_topicObject->renderTML($actual); $actual = _cut_the_crap($actual); $expected = 'AnnaAnchor'; @@ -1542,7 +1535,7 @@ sub test_format_tokens_topic_truncated { $this->set_up_for_formatted_search(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Bullet" type="regex" multiple="on" nonoise="on" format="I found $topic(5,...)" excludetopic="SomeOther*"}%' ); @@ -1560,7 +1553,7 @@ sub test_format_tokens_dont_expand { $this->set_up_for_formatted_search(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Bullet" type="regex" nonoise="on" format="$topic $email $html $time"}%' ); @@ -1576,7 +1569,7 @@ sub test_format_displayed_value { $this->set_up_for_formatted_search(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Bullet" type="regex" nonoise="on" format="$formfield(Groupe, display) $formfield(Groupe):$formfield(Groupe, display, 3)"}%' ); @@ -1586,7 +1579,7 @@ sub test_format_displayed_value { ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Bullet" type="regex" nonoise="on" format="$formfield(Chinese, display) $formfield(Chinese)"}%' ); @@ -1597,26 +1590,26 @@ sub test_format_displayed_value { sub test_METASEARCH { my $this = shift; - my $session = $this->{session}; + my $session = $this->session; $this->set_up_for_formatted_search(); my $actual, my $expected; $actual = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%METASEARCH{type="topicmoved" topic="FormattedSearchTopic1" title="This topic used to exist and was moved to: "}%' ); - $actual = $this->{test_topicObject}->renderTML($actual); + $actual = $this->test_topicObject->renderTML($actual); $expected = 'This topic used to exist and was moved to: '; $this->assert_str_equals( $expected, $actual ); $actual = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%METASEARCH{type="parent" topic="TestCaseAutoFormattedSearch" title="Children: "}%' ); - $actual = $this->{test_topicObject}->renderTML($actual); + $actual = $this->test_topicObject->renderTML($actual); $expected = - $this->{test_topicObject}->renderTML('Children: FormattedSearchTopic1 '); + $this->test_topicObject->renderTML('Children: FormattedSearchTopic1 '); $this->assert_str_equals( $expected, $actual ); return; @@ -1630,7 +1623,7 @@ This is QueryTopic FURTLE somethig after HERE my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'QueryTopic' ); + Foswiki::Func::readTopic( $this->test_web, 'QueryTopic' ); $topicObject->put( 'TOPICINFO', { @@ -1702,7 +1695,7 @@ This is QueryTopicTwo SMONG third line HERE ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'QueryTopicTwo' ); + Foswiki::Func::readTopic( $this->test_web, 'QueryTopicTwo' ); $topicObject->text($text); $topicObject->put( 'TOPICPARENT', { name => "QueryTopic" } ); $topicObject->put( @@ -1793,10 +1786,10 @@ HERE $topicObject->finish(); my $query = Unit::Request->new(''); - $query->path_info("/$this->{test_web}/$this->{test_topic}"); + $query->path_info( "/" . $this->test_web . "/" . $this->test_topic ); $this->createNewFoswikiSession( undef, $query ); - $this->assert_str_equals( $this->{test_web}, $this->{session}->{webName} ); + $this->assert_str_equals( $this->test_web, $this->session->webName ); return; } @@ -1812,8 +1805,8 @@ sub verify_parentQuery { $this->set_up_for_queries(); my $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"parent.name=\'WebHome\'"' . $stdCrap ); + $this->test_topicObject->expandMacros( + '%SEARCH{"parent.name=\'WebHome\'"' . $stdCrap ); $this->assert_str_equals( 'QueryTopic', $result ); return; @@ -1825,8 +1818,8 @@ sub verify_attachmentSizeQuery1 { $this->set_up_for_queries(); my $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"attachments[size > 0]"' . $stdCrap ); + $this->test_topicObject->expandMacros( + '%SEARCH{"attachments[size > 0]"' . $stdCrap ); $this->assert_str_equals( 'QueryTopic QueryTopicTwo', $result ); return; @@ -1838,7 +1831,7 @@ sub verify_attachmentSizeQuery2 { $this->set_up_for_queries(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"META:FILEATTACHMENT[size > 10000]"' . $stdCrap ); $this->assert_str_equals( 'QueryTopicTwo', $result ); @@ -1851,8 +1844,8 @@ sub verify_indexQuery { $this->set_up_for_queries(); my $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"attachments[name=\'flib.xml\']"' . $stdCrap ); + $this->test_topicObject->expandMacros( + '%SEARCH{"attachments[name=\'flib.xml\']"' . $stdCrap ); $this->assert_str_equals( 'QueryTopicTwo', $result ); return; @@ -1864,8 +1857,8 @@ sub verify_gropeQuery { $this->set_up_for_queries(); my $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"Lastname=\'Peel\'"' . $stdCrap ); + $this->test_topicObject->expandMacros( + '%SEARCH{"Lastname=\'Peel\'"' . $stdCrap ); $this->assert_str_equals( 'QueryTopic QueryTopicTwo', $result ); return; @@ -1877,7 +1870,7 @@ sub verify_4580Query1 { $this->set_up_for_queries(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"text ~ \'*SMONG*\' AND Lastname=\'Peel\'"' . $stdCrap ); $this->assert_str_equals( 'QueryTopicTwo', $result ); @@ -1890,7 +1883,7 @@ sub verify_4580Query2 { $this->set_up_for_queries(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"text ~ \'*FURTLE*\' AND Lastname=\'Peel\'"' . $stdCrap ); $this->assert_str_equals( 'QueryTopic', $result ); @@ -1903,8 +1896,8 @@ sub verify_gropeQuery2 { $this->set_up_for_queries(); my $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"Lastname=\'Peel\'"' . $stdCrap ); + $this->test_topicObject->expandMacros( + '%SEARCH{"Lastname=\'Peel\'"' . $stdCrap ); $this->assert_str_equals( 'QueryTopic QueryTopicTwo', $result ); return; @@ -1916,8 +1909,8 @@ sub verify_formQuery { $this->set_up_for_queries(); my $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"form.name=\'TestyForm\'"' . $stdCrap ); + $this->test_topicObject->expandMacros( + '%SEARCH{"form.name=\'TestyForm\'"' . $stdCrap ); $this->assert_str_equals( 'QueryTopicTwo', $result ); return; @@ -1930,8 +1923,7 @@ sub verify_formQuery2 { $this->set_up_for_queries(); my $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"TestForm"' . $stdCrap ); + $this->test_topicObject->expandMacros( '%SEARCH{"TestForm"' . $stdCrap ); my $expected = $this->_expect_with_deps( '', 'Foswiki,<,1.2' => 'QueryTopic' ); @@ -1946,7 +1938,7 @@ sub verify_formQuery3 { $this->set_up_for_queries(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"TestForm[name=\'Field1\'].value=\'A Field\'"' . $stdCrap ); $this->assert_str_equals( 'QueryTopic', $result ); @@ -1964,8 +1956,8 @@ sub verify_formQuery4 { $this->set_up_for_queries(); my $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"TestForm.Field1=\'A Field\'"' . $stdCrap ); + $this->test_topicObject->expandMacros( + '%SEARCH{"TestForm.Field1=\'A Field\'"' . $stdCrap ); $this->assert_str_equals( 'QueryTopic', $result ); return; @@ -1982,12 +1974,12 @@ sub verify_formQuery5 { $this->set_up_for_queries(); my $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"TestyForm.form=\'form good\'"' . $stdCrap ); + $this->test_topicObject->expandMacros( + '%SEARCH{"TestyForm.form=\'form good\'"' . $stdCrap ); $this->assert_str_equals( 'QueryTopicTwo', $result ); $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"TestyForm.FORM=\'FORM GOOD\'"' . $stdCrap ); + $this->test_topicObject->expandMacros( + '%SEARCH{"TestyForm.FORM=\'FORM GOOD\'"' . $stdCrap ); $this->assert_str_equals( 'QueryTopicTwo', $result ); return; @@ -1999,7 +1991,7 @@ sub verify_refQuery { $this->set_up_for_queries(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"parent.name/(Firstname ~ \'*mm?\' AND Field2=2)"' . $stdCrap ); $this->assert_str_equals( 'QueryTopicTwo', $result ); @@ -2013,8 +2005,8 @@ sub verify_lc_field_short { $this->set_up_for_queries(); my $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"lc(Firstname) ~ lc(\'Emma\')"' . $stdCrap ); + $this->test_topicObject->expandMacros( + '%SEARCH{"lc(Firstname) ~ lc(\'Emma\')"' . $stdCrap ); $this->assert_str_equals( 'QueryTopic', $result ); } @@ -2024,7 +2016,7 @@ sub verify_lc_field_qualified { $this->set_up_for_queries(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"lc(TestForm.Firstname) ~ lc(\'Emma\')"' . $stdCrap ); $this->assert_str_equals( 'QueryTopic', $result ); } @@ -2035,7 +2027,7 @@ sub verify_lc_field_fully_qualified { $this->set_up_for_queries(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"lc(TestForm[name=\'Firstname\'].value) ~ lc(\'Emma\')"' . $stdCrap ); $this->assert_str_equals( 'QueryTopic', $result ); @@ -2050,7 +2042,7 @@ sub verify_badQuery1 { $this->set_up_for_queries(); my $result = - $this->{test_topicObject}->expandMacros( '%SEARCH{"A ¬ B"' . $stdCrap ); + $this->test_topicObject->expandMacros( '%SEARCH{"A ¬ B"' . $stdCrap ); $this->assert_matches( qr/Error was: Syntax error in 'A ¬ B' at ' ¬ B'/s, $result ); @@ -2095,7 +2087,7 @@ We have committed to enable customer-centric supply-chains and our mega-channels We have committed to take steps towards $vE reinventing our cyber-key players and harnessing frictionless net-communities so that hopefully we may better serve our customers. HERE my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, "QueryTopic$n", ); + Foswiki::Func::readTopic( $this->test_web, "QueryTopic$n", ); $topicObject->put( 'TOPICINFO', { @@ -2156,7 +2148,7 @@ HERE my $start = Benchmark->new(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"^[%]META:FIELD\{name=\"FieldA\".*\bvalue=\"A\";^[%]META:FIELD\{name=\"FieldB\".*\bvalue=\"A\";^[%]META:FIELD\{name=\"FieldC\".*\bvalue=\"A\";^[%]META:FIELD\{name=\"FieldD\".*\bvalue=\"A\"|^[%]META:FIELD\{name=\"FieldE\".*\bvalue=\"A\"" type="regex" nonoise="on" format="$topic" separator=" "}%' ); my $retime = Benchmark::timediff( Benchmark->new(), $start ); @@ -2165,7 +2157,7 @@ HERE # Repeat using a query $start = Benchmark->new; $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"FieldA=\'A\' AND FieldB=\'A\' AND FieldC=\'A\' AND (FieldD=\'A\' OR FieldE=\'A\')" type="query" nonoise="on" format="$topic" separator=" "}%' ); my $querytime = Benchmark::timediff( new Benchmark, $start ); @@ -2180,8 +2172,9 @@ sub test_4347 { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( -"%SEARCH{\"$this->{test_topic}\" scope=\"topic\" nonoise=\"on\" format=\"\$formfield(Blah)\"}%" + $this->test_topicObject->expandMacros( "%SEARCH{\"" + . $this->test_topic + . "\" scope=\"topic\" nonoise=\"on\" format=\"\$formfield(Blah)\"}%" ); $this->assert_str_equals( '', $result ); @@ -2194,24 +2187,24 @@ sub verify_likeQuery { $this->set_up_for_queries(); my $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"text ~ \'*SMONG*\'" ' . $stdCrap ); + $this->test_topicObject->expandMacros( + '%SEARCH{"text ~ \'*SMONG*\'" ' . $stdCrap ); $this->assert_str_equals( 'QueryTopicTwo', $result ); $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"text ~ \'*QueryTopicTwo*\'" ' . $stdCrap ); + $this->test_topicObject->expandMacros( + '%SEARCH{"text ~ \'*QueryTopicTwo*\'" ' . $stdCrap ); $this->assert_str_equals( 'QueryTopicTwo', $result ); my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'QueryTopicTwo' ); + Foswiki::Func::readTopic( $this->test_web, 'QueryTopicTwo' ); $result = $topicObject->expandMacros( '%SEARCH{"text ~ \'*SMONG*\'" ' . $stdCrap ); $this->assert_str_equals( 'QueryTopicTwo', $result ); $topicObject->finish(); ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'QueryTopicTwo' ); + Foswiki::Func::readTopic( $this->test_web, 'QueryTopicTwo' ); $result = $topicObject->expandMacros( '%SEARCH{"text ~ \'*QueryTopicTwo*\'" ' . $stdCrap ); $this->assert_str_equals( 'QueryTopicTwo', $result ); @@ -2226,23 +2219,27 @@ sub test_metacache_madness { This is QueryTopicTwo SMONG HERE my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'QueryTopicTwo' ); + Foswiki::Func::readTopic( $this->test_web, 'QueryTopicTwo' ); $topicObject->text($text); $topicObject->save(); $topicObject->finish(); my $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"text ~ \'*QueryTopicTwo*\'" ' . $stdCrap ); + $this->test_topicObject->expandMacros( + '%SEARCH{"text ~ \'*QueryTopicTwo*\'" ' . $stdCrap ); ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'QueryTopicTwo' ); + Foswiki::Func::readTopic( $this->test_web, 'QueryTopicTwo' ); - $this->assert( $this->{session} - ->search->metacache->hasCached( $this->{test_web}, 'QueryTopicTwo' ) + $this->assert( + $this->session->search->metacache->hasCached( + $this->test_web, 'QueryTopicTwo' + ) ); $topicObject->finish(); - $this->assert( !$this->{session} - ->search->metacache->hasCached( $this->{test_web}, 'QueryTopicTwo' ) + $this->assert( + !$this->session->search->metacache->hasCached( + $this->test_web, 'QueryTopicTwo' + ) ); =begin note @@ -2276,7 +2273,7 @@ Assertion (this is not a topic object) failed! =cut ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'QueryTopicTwo' ); + Foswiki::Func::readTopic( $this->test_web, 'QueryTopicTwo' ); $topicObject->finish(); return; @@ -2288,50 +2285,50 @@ sub verify_likeQuery2 { $this->set_up_for_queries(); my $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"text ~ \'*SMONG*\'" web="' - . $this->{test_web} . '" ' + $this->test_topicObject->expandMacros( + '%SEARCH{"text ~ \'*SMONG*\'" web="' + . $this->test_web . '" ' . $stdCrap ); $this->assert_str_equals( 'QueryTopicTwo', $result ); $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"text ~ \'*QueryTopicTwo*\'" web="' - . $this->{test_web} . '" ' + $this->test_topicObject->expandMacros( + '%SEARCH{"text ~ \'*QueryTopicTwo*\'" web="' + . $this->test_web . '" ' . $stdCrap ); $this->assert_str_equals( 'QueryTopicTwo', $result ); my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'QueryTopicTwo' ); + Foswiki::Func::readTopic( $this->test_web, 'QueryTopicTwo' ); $result = $topicObject->expandMacros( '%SEARCH{"text ~ \'*SMONG*\'" web="' - . $this->{test_web} . '" ' + . $this->test_web . '" ' . $stdCrap ); $this->assert_str_equals( 'QueryTopicTwo', $result ); $topicObject->finish(); ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'QueryTopicTwo' ); + Foswiki::Func::readTopic( $this->test_web, 'QueryTopicTwo' ); $result = $topicObject->expandMacros( '%SEARCH{"text ~ \'*QueryTopicTwo*\'" web="' - . $this->{test_web} . '" ' + . $this->test_web . '" ' . $stdCrap ); $this->assert_str_equals( 'QueryTopicTwo', $result ); $topicObject->finish(); ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'QueryTopicTwo' ); + Foswiki::Func::readTopic( $this->test_web, 'QueryTopicTwo' ); $result = $topicObject->expandMacros( '%SEARCH{"text ~ \'*Notinthetopics*\'" web="' - . $this->{test_web} . '" ' + . $this->test_web . '" ' . $stdCrap ); $this->assert_str_equals( '', $result ); $topicObject->finish(); $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"text ~ \'*before. Another*\'" web="' - . $this->{test_web} . '" ' + $this->test_topicObject->expandMacros( + '%SEARCH{"text ~ \'*before. Another*\'" web="' + . $this->test_web . '" ' . $stdCrap ); $this->assert_str_equals( 'QueryTopic', $result ); @@ -2342,7 +2339,7 @@ sub test_pattern { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"BLEEGLE" topic="OkATopic,OkBTopic,OkÆTopic" nonoise="on" format="X$pattern(.*?BLEEGLE (.*?)blah.*)Y"}%' ); $this->assert_matches( qr/Xdontmatchme\.Y/, $result ); @@ -2356,13 +2353,13 @@ sub test_extract { my $this = shift; my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'ExtractTopic' ); + Foswiki::Func::readTopic( $this->test_web, 'ExtractTopic' ); $topicObject->text("BLEEGLE \"<>&%\$\"blah"); $topicObject->save(); $topicObject->finish(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"BLEEGLE" topic="ExtractTopic" nonoise="on" format="X$percentENCODE{$extract(.*?BLEEGLE (.*?)blah.*)}$percentY"}%' ); $this->assert_matches( qr/X%3c%3e%26%25%24Y/, $result ); @@ -2375,7 +2372,7 @@ sub test_badpattern { # The (??{ pragma cannot be run at runtime since perl 5.5 my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"BLEEGLE" topic="OkATopic,OkBTopic,OkÆTopic" nonoise="on" format="X$pattern(.*?BL(??{\'E\' x 2})GLE( .*?)blah.*)Y"}%' ); @@ -2432,8 +2429,7 @@ sub test_validatepattern { sub test_formatOfLinks { my $this = shift; - my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'Item977' ); + my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'Item977' ); $topicObject->text( $this->toSiteCharSet(<<'HERE') ); ---+ Apache @@ -2443,7 +2439,7 @@ HERE $topicObject->finish(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Item977" scope="topic" nonoise="on" format="$summary"}%'); $this->assert_str_equals( 'Apache Apache is the well known web server.', @@ -2453,7 +2449,7 @@ HERE #extractFormat feature $this->assert_str_equals( 'Apache is the well known web server.', - $this->{session}->{renderer}->TML2PlainText( + $this->session->renderer->TML2PlainText( 'Apache is the [[http://www.apache.org/httpd/][well known web server]].' ) ); @@ -2461,23 +2457,27 @@ HERE #test a few others to try to not break things $this->assert_matches( qr/Apache is the\s+http:\/\/www\.apache\.org\/httpd\/ well known web server\s*\./, - $this->{session}->{renderer}->TML2PlainText( + $this->session->renderer->TML2PlainText( 'Apache is the [[http://www.apache.org/httpd/ well known web server]].' ) ); $this->assert_str_equals( 'Apache is the well known web server.', - $this->{session}->{renderer}->TML2PlainText( + $this->session->renderer->TML2PlainText( 'Apache is the [[ApacheServer][well known web server]].') ); #SMELL: an unexpected result :/ - $this->assert_str_equals( 'Apache is the well known web server .', - $this->{session}->{renderer} - ->TML2PlainText('Apache is the [[well known web server]].') ); - $this->assert_str_equals( 'Apache is the well known web server.', - $this->{session}->{renderer} - ->TML2PlainText('Apache is the well known web server.') ); + $this->assert_str_equals( + 'Apache is the well known web server .', + $this->session->renderer->TML2PlainText( + 'Apache is the [[well known web server]].') + ); + $this->assert_str_equals( + 'Apache is the well known web server.', + $this->session->renderer->TML2PlainText( + 'Apache is the well known web server.') + ); return; } @@ -2499,7 +2499,7 @@ sub _getTopicList { my $webObject = $this->getWebObject($web); # Run the search on topics in this web - my $search = $this->{session}->search(); + my $search = $this->session->search(); my $iter = Foswiki::Search::InfoCache::getTopicListIterator( $webObject, $options ); @@ -2522,7 +2522,7 @@ sub verify_getTopicList { #no topics specified.. $this->_getTopicList( - $this->{test_web}, + $this->test_web, {}, 'no filters, all topics in test_web', [ @@ -2547,7 +2547,7 @@ sub verify_getTopicList { #use wildcards $this->_getTopicList( - $this->{test_web}, + $this->test_web, { includeTopics => 'Ok*' }, 'comma separated list', [ 'OkATopic', 'OkBTopic', 'OkÆTopic' ], @@ -2568,7 +2568,7 @@ sub verify_getTopicList { #comma separated list specifed for inclusion $this->_getTopicList( - $this->{test_web}, + $this->test_web, { includeTopics => 'TestTopicSEARCH,OkÆTopic,NoSuchTopic' }, 'comma separated list', [ 'OkÆTopic', 'TestTopicSEARCH' ], @@ -2584,7 +2584,7 @@ sub verify_getTopicList { #excludes $this->_getTopicList( - $this->{test_web}, + $this->test_web, { excludeTopics => 'NoSuchTopic,OkBTopic,SomeOtherÆØÅTopic' }, 'no filters, all topics in test_web', [ 'OkATopic', 'OkÆTopic', 'TestTopicSEARCH', 'WebPreferences' ], @@ -2605,7 +2605,7 @@ sub verify_getTopicList { #Talk about missing alot of tests $this->_getTopicList( - $this->{test_web}, + $this->test_web, { includeTopics => '*' }, 'all topics, using wildcard', [ @@ -2615,13 +2615,13 @@ sub verify_getTopicList { ], ); $this->_getTopicList( - $this->{test_web}, + $this->test_web, { includeTopics => 'Ok*' }, 'Ok* topics, using wildcard', [ 'OkATopic', 'OkBTopic', 'OkÆTopic' ], ); $this->_getTopicList( - $this->{test_web}, + $this->test_web, { includeTopics => 'ok*', casesensitive => 1 @@ -2630,7 +2630,7 @@ sub verify_getTopicList { [], ); $this->_getTopicList( - $this->{test_web}, + $this->test_web, { includeTopics => 'ok*', casesensitive => 0 @@ -2646,7 +2646,7 @@ sub verify_getTopicList { # this test won't work on Mac OS X or windows. $this->_getTopicList( - $this->{test_web}, + $this->test_web, { includeTopics => 'okatopic', casesensitive => 1 @@ -2657,7 +2657,7 @@ sub verify_getTopicList { } $this->_getTopicList( - $this->{test_web}, + $this->test_web, { includeTopics => 'okatopic', casesensitive => 0 @@ -2667,7 +2667,7 @@ sub verify_getTopicList { ); ##### same again, with excludes. $this->_getTopicList( - $this->{test_web}, + $this->test_web, { includeTopics => '*', excludeTopics => 'web*' @@ -2680,7 +2680,7 @@ sub verify_getTopicList { ], ); $this->_getTopicList( - $this->{test_web}, + $this->test_web, { includeTopics => 'Ok*', excludeTopics => 'okatopic' @@ -2689,7 +2689,7 @@ sub verify_getTopicList { [ 'OkATopic', 'OkBTopic', 'OkÆTopic' ], ); $this->_getTopicList( - $this->{test_web}, + $this->test_web, { includeTopics => 'ok*', excludeTopics => 'WebPreferences', @@ -2699,7 +2699,7 @@ sub verify_getTopicList { [], ); $this->_getTopicList( - $this->{test_web}, + $this->test_web, { includeTopics => 'ok*', excludeTopics => '', @@ -2710,7 +2710,7 @@ sub verify_getTopicList { ); $this->_getTopicList( - $this->{test_web}, + $this->test_web, { includeTopics => 'Ok*', excludeTopics => '*ATopic', @@ -2721,7 +2721,7 @@ sub verify_getTopicList { ); $this->_getTopicList( - $this->{test_web}, + $this->test_web, { includeTopics => 'Ok*', excludeTopics => '*atopic', @@ -2732,7 +2732,7 @@ sub verify_getTopicList { ); $this->_getTopicList( - $this->{test_web}, + $this->test_web, { includeTopics => 'ok*topic', excludeTopics => 'okatopic', @@ -2747,75 +2747,75 @@ sub verify_getTopicList { sub verify_casesensitivesetting { my $this = shift; - my $session = $this->{session}; + my $session = $this->session; my $actual, my $expected; $actual = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"BLEEGLE" type="regex" multiple="on" casesensitive="on" nosearch="on" noheader="on" nototal="on" format="$topic" separator=","}%' ); - $actual = $this->{test_topicObject}->renderTML($actual); + $actual = $this->test_topicObject->renderTML($actual); $expected = 'OkATopic,OkBTopic,OkÆTopic,TestTopicSEARCH'; $this->assert_str_equals( $expected, $actual ); $actual = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"bleegle" type="regex" multiple="on" casesensitive="on" nosearch="on" noheader="on" nototal="on" format="$topic" separator=","}%' ); - $actual = $this->{test_topicObject}->renderTML($actual); + $actual = $this->test_topicObject->renderTML($actual); $expected = ''; $this->assert_str_equals( $expected, $actual ); $actual = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"BLEEGLE" type="regex" multiple="on" casesensitive="off" nosearch="on" noheader="on" nototal="on" format="$topic" separator=","}%' ); - $actual = $this->{test_topicObject}->renderTML($actual); + $actual = $this->test_topicObject->renderTML($actual); $expected = 'OkATopic,OkBTopic,OkÆTopic,TestTopicSEARCH'; $this->assert_str_equals( $expected, $actual ); $actual = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"bleegle" type="regex" multiple="on" casesensitive="off" nosearch="on" noheader="on" nototal="on" format="$topic" separator=","}%' ); - $actual = $this->{test_topicObject}->renderTML($actual); + $actual = $this->test_topicObject->renderTML($actual); $expected = 'OkATopic,OkBTopic,OkÆTopic,TestTopicSEARCH'; $this->assert_str_equals( $expected, $actual ); #topic scope $actual = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Ok" type="regex" scope="topic" multiple="on" casesensitive="on" nosearch="on" noheader="on" nototal="on" format="$topic" separator=","}%' ); - $actual = $this->{test_topicObject}->renderTML($actual); + $actual = $this->test_topicObject->renderTML($actual); $expected = 'OkATopic,OkBTopic,OkÆTopic'; $this->assert_str_equals( $expected, $actual ); $actual = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"ok" type="regex" scope="topic" multiple="on" casesensitive="on" nosearch="on" noheader="on" nototal="on" format="$topic" separator=","}%' ); - $actual = $this->{test_topicObject}->renderTML($actual); + $actual = $this->test_topicObject->renderTML($actual); $expected = ''; $this->assert_str_equals( $expected, $actual ); $actual = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Ok" type="regex" scope="topic" multiple="on" casesensitive="off" nosearch="on" noheader="on" nototal="on" format="$topic" separator=","}%' ); - $actual = $this->{test_topicObject}->renderTML($actual); + $actual = $this->test_topicObject->renderTML($actual); $expected = 'OkATopic,OkBTopic,OkÆTopic'; $this->assert_str_equals( $expected, $actual ); $actual = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"ok" type="regex" scope="topic" multiple="on" casesensitive="off" nosearch="on" noheader="on" nototal="on" format="$topic" separator=","}%' ); - $actual = $this->{test_topicObject}->renderTML($actual); + $actual = $this->test_topicObject->renderTML($actual); $expected = 'OkATopic,OkBTopic,OkÆTopic'; $this->assert_str_equals( $expected, $actual ); @@ -2825,8 +2825,7 @@ sub verify_casesensitivesetting { sub verify_Item6082_Search { my $this = shift; - my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'TestForm' ); + my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'TestForm' ); $topicObject->text(<<'FORM'); | *Name* | *Type* | *Size* | *Value* | *Tooltip message* | *Attributes* | | Why | text | 32 | | Mandatory field | M | @@ -2834,8 +2833,7 @@ sub verify_Item6082_Search { FORM $topicObject->save(); $topicObject->finish(); - ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'SplodgeOne' ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'SplodgeOne' ); $topicObject->put( 'FORM', { name => "TestForm" } ); $topicObject->putKeyed( 'FIELD', { name => "Ecks", title => "X", value => "Blah" } ); @@ -2854,8 +2852,7 @@ FORM sub verify_quotemeta { my $this = shift; - my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'TestForm' ); + my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'TestForm' ); $topicObject->text( <<'FORM'); | *Name* | *Type* | *Size* | *Value* | *Tooltip message* | *Attributes* | | Why | text | 32 | | Mandatory field | M | @@ -2863,8 +2860,7 @@ sub verify_quotemeta { FORM $topicObject->save(); $topicObject->finish(); - ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'SplodgeOne' ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'SplodgeOne' ); $topicObject->put( 'FORM', { name => "TestForm" } ); $topicObject->putKeyed( 'FIELD', { name => "Ecks", title => "X", value => "Blah" } ); @@ -2886,7 +2882,7 @@ sub verify_Search_expression { my $this = shift; my $actual = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"TestForm.Ecks~\'Bl>ah*\'" type="query" nototal="on"}%'); my $expected = $this->toSiteCharSet(<<'HERE');
Searched: TestForm.Ecks~'Bl>ah*'
@@ -2895,7 +2891,7 @@ HERE $this->assert_str_equals( $expected, $actual ); $actual = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"TestForm.Ecks = \'B/lah*\'" type="query" nototal="on"}%'); $expected = $this->toSiteCharSet(<<'HERE');
Searched: TestForm.Ecks = 'B/lah*'
@@ -2919,7 +2915,7 @@ sub _multiWebSeptic { $format = '$topic' unless ( defined($format) ); my $expected = $this->_expect_with_deps( $default, %expectations ); - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( "%SEARCH{\"name~'$str'\" web=\"System,Main\" type=\"query\" @@ -3245,7 +3241,7 @@ FOSWIKI12 #Item1992: calling Foswiki::Search::_makeTopicPattern repeatedly made a big mess. sub test_web_and_topic_expansion { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -3286,7 +3282,7 @@ FOSWIKI11 # PAGING sub test_paging_three_webs_first_page { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -3327,7 +3323,7 @@ FOSWIKI11 sub test_paging_three_webs_second_page { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -3368,7 +3364,7 @@ FOSWIKI11 sub test_paging_three_webs_third_page { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -3403,7 +3399,7 @@ FOSWIKI11 sub test_paging_three_webs_fourth_page { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -3429,7 +3425,7 @@ EXPECT sub test_paging_three_webs_way_too_far { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -3456,7 +3452,7 @@ EXPECT #----------------------------------- sub test_paging_three_webs_first_page_zeroresultsset { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -3498,7 +3494,7 @@ FOSWIKI11 sub test_paging_three_webs_second_page_zeroresultsset { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -3540,7 +3536,7 @@ FOSWIKI11 sub test_paging_three_webs_third_page_zeroresultsset { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -3578,7 +3574,7 @@ sub test_paging_three_webs_fourth_page_zeroresultsset { $this->expect_failure( 'Item11860 needs to be fixed!', with_dep => 'Foswiki,<,1.2' ); - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -3608,7 +3604,7 @@ sub test_paging_three_webs_way_too_far_zeroresultsset { $this->expect_failure( 'Item11860 needs to be fixed!', with_dep => 'Foswiki,<,1.2' ); - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -3639,7 +3635,7 @@ EXPECT sub verify_non_paging_with_limit { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ ".*" type="regex" @@ -3681,7 +3677,7 @@ FOSWIKI11 sub test_paging_with_limit_first_page { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -3719,7 +3715,7 @@ FOSWIKI11 sub test_paging_with_limit_second_page { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -3757,7 +3753,7 @@ FOSWIKI11 sub test_paging_with_limit_third_page { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -3795,7 +3791,7 @@ FOSWIKI11 sub test_paging_with_limit_fourth_page { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -3822,7 +3818,7 @@ EXPECT sub test_paging_with_limit_way_too_far { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -3856,30 +3852,29 @@ EXPECT sub test_groupby_none_using_subwebs { my $this = shift; - my $webObject = $this->populateNewWeb("$this->{test_web}/A"); + my $test_web = $this->test_web; + my $webObject = $this->populateNewWeb( $this->test_web . "/A" ); $webObject->finish(); my ($topicObject) = - Foswiki::Func::readTopic( "$this->{test_web}/A", 'TheTopic' ); + Foswiki::Func::readTopic( $test_web . "/A", 'TheTopic' ); $topicObject->put( 'FORM', { name => "TestForm" } ); $topicObject->putKeyed( 'FIELD', { name => "Order", title => "Order", value => "3" } ); $topicObject->save( forcedate => 1000 ); $topicObject->finish(); - $webObject = $this->populateNewWeb("$this->{test_web}/B"); + $webObject = $this->populateNewWeb( $test_web . "/B" ); $webObject->finish(); - ($topicObject) = - Foswiki::Func::readTopic( "$this->{test_web}/B", 'TheTopic' ); + ($topicObject) = Foswiki::Func::readTopic( $test_web . "/B", 'TheTopic' ); $topicObject->put( 'FORM', { name => "TestForm" } ); $topicObject->putKeyed( 'FIELD', { name => "Order", title => "Order", value => "1" } ); $topicObject->save( forcedate => 100 ); $topicObject->finish(); - $webObject = $this->populateNewWeb("$this->{test_web}/C"); + $webObject = $this->populateNewWeb( $test_web . "/C" ); $webObject->finish(); - ($topicObject) = - Foswiki::Func::readTopic( "$this->{test_web}/C", 'TheTopic' ); + ($topicObject) = Foswiki::Func::readTopic( $test_web . "/C", 'TheTopic' ); $topicObject->put( 'FORM', { name => "TestForm" } ); $topicObject->putKeyed( 'FIELD', { name => "Order", title => "Order", value => "2" } ); @@ -3888,10 +3883,10 @@ sub test_groupby_none_using_subwebs { my $result; #order by formfield, with groupby=none - $result = $this->{test_topicObject}->expandMacros( <<"GNURF" ); + $result = $this->test_topicObject->expandMacros( <<"GNURF" ); %SEARCH{"Order!=''" type="query" - web="$this->{test_web}" + web="$test_web" topic="TheTopic" recurse="on" nonoise="on" @@ -3901,15 +3896,13 @@ sub test_groupby_none_using_subwebs { groupby="none" }% GNURF - $this->assert_equals( - "$this->{test_web}/B,$this->{test_web}/C,$this->{test_web}/A\n", - $result ); + $this->assert_equals( "$test_web/B,$test_web/C,$test_web/A\n", $result ); #order by modified date, reverse=off, with groupby=none - $result = $this->{test_topicObject}->expandMacros( <<"GNURF" ); + $result = $this->test_topicObject->expandMacros( <<"GNURF" ); %SEARCH{"Order!=''" type="query" - web="$this->{test_web}" + web="$test_web" topic="TheTopic" recurse="on" nonoise="on" @@ -3921,15 +3914,15 @@ GNURF }% GNURF $this->assert_equals( -"$this->{test_web}/B 01 Jan 1970 - 00:01, $this->{test_web}/C 01 Jan 1970 - 00:08, $this->{test_web}/A 01 Jan 1970 - 00:16\n", +"$test_web/B 01 Jan 1970 - 00:01, $test_web/C 01 Jan 1970 - 00:08, $test_web/A 01 Jan 1970 - 00:16\n", $result ); #order by modified date, reverse=n, with groupby=none - $result = $this->{test_topicObject}->expandMacros( <<"GNURF" ); + $result = $this->test_topicObject->expandMacros( <<"GNURF" ); %SEARCH{"Order!=''" type="query" - web="$this->{test_web}" + web="$test_web" topic="TheTopic" recurse="on" nonoise="on" @@ -3941,16 +3934,16 @@ GNURF }% GNURF $this->assert_equals( -"$this->{test_web}/A 01 Jan 1970 - 00:16, $this->{test_web}/C 01 Jan 1970 - 00:08, $this->{test_web}/B 01 Jan 1970 - 00:01\n", +"$test_web/A 01 Jan 1970 - 00:16, $test_web/C 01 Jan 1970 - 00:08, $test_web/B 01 Jan 1970 - 00:01\n", $result ); #and the same again, this time using header&footer, as that is what really shows the issue. #order by formfield, with groupby=none - $result = $this->{test_topicObject}->expandMacros( <<"GNURF" ); + $result = $this->test_topicObject->expandMacros( <<"GNURF" ); %SEARCH{"Order!=''" type="query" - web="$this->{test_web}" + web="$test_web" topic="TheTopic" recurse="on" nonoise="on" @@ -3962,16 +3955,14 @@ GNURF groupby="none" }% GNURF - $this->assert_equals( -"HEADER$this->{test_web}/B, $this->{test_web}/C, $this->{test_web}/AFOOTER\n", - $result - ); + $this->assert_equals( "HEADER$test_web/B, $test_web/C, $test_web/AFOOTER\n", + $result ); #order by modified date, reverse=off, with groupby=none - $result = $this->{test_topicObject}->expandMacros( <<"GNURF" ); + $result = $this->test_topicObject->expandMacros( <<"GNURF" ); %SEARCH{"Order!=''" type="query" - web="$this->{test_web}" + web="$test_web" topic="TheTopic" recurse="on" nonoise="on" @@ -3985,15 +3976,15 @@ GNURF }% GNURF $this->assert_equals( -"HEADER$this->{test_web}/B 01 Jan 1970 - 00:01, $this->{test_web}/C 01 Jan 1970 - 00:08, $this->{test_web}/A 01 Jan 1970 - 00:16FOOTER\n", +"HEADER$test_web/B 01 Jan 1970 - 00:01, $test_web/C 01 Jan 1970 - 00:08, $test_web/A 01 Jan 1970 - 00:16FOOTER\n", $result ); #order by modified date, reverse=n, with groupby=none - $result = $this->{test_topicObject}->expandMacros( <<"GNURF" ); + $result = $this->test_topicObject->expandMacros( <<"GNURF" ); %SEARCH{"Order!=''" type="query" - web="$this->{test_web}" + web="$test_web" topic="TheTopic" recurse="on" nonoise="on" @@ -4007,7 +3998,7 @@ GNURF }% GNURF $this->assert_equals( -"HEADER$this->{test_web}/A 01 Jan 1970 - 00:16, $this->{test_web}/C 01 Jan 1970 - 00:08, $this->{test_web}/B 01 Jan 1970 - 00:01FOOTER\n", +"HEADER$test_web/A 01 Jan 1970 - 00:16, $test_web/C 01 Jan 1970 - 00:08, $test_web/B 01 Jan 1970 - 00:01FOOTER\n", $result ); @@ -4029,10 +4020,10 @@ CRUD $ltopicObject->finish(); } - $result = $this->{test_topicObject}->expandMacros( <<"GNURF" ); + $result = $this->test_topicObject->expandMacros( <<"GNURF" ); %SEARCH{"1" type="query" - web="$this->{test_web}/A,Main,System,Sandbox," + web="$test_web/A,Main,System,Sandbox," topic="TheTopic" recurse="on" nonoise="on" @@ -4068,9 +4059,10 @@ sub _cut_the_crap { sub test_no_format_no_junk { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros('%SEARCH{"BLEEGLE"}%'); + my $test_web = $this->test_web; + my $result = $this->test_topicObject->expandMacros('%SEARCH{"BLEEGLE"}%'); $this->assert_html_equals( <<"CRUD", _cut_the_crap($result) ); -Searched: BLEEGLEResults from $this->{test_web} web retrieved at TIME +Searched: BLEEGLEResults from $test_web web retrieved at TIME OkATopic BLEEGLE dontmatchme.blah @@ -4092,7 +4084,7 @@ Number of topics: 4 CRUD # Now we create the WikiGuest user topic, to test both outputs - my $session = $this->{session}; + my $session = $this->session; if ( !$session->topicExists( 'TemporarySEARCHUsersWeb', 'WikiGuest' ) ) { my ($userTopic) = Foswiki::Func::readTopic( 'TemporarySEARCHUsersWeb', 'WikiGuest' ); @@ -4106,10 +4098,10 @@ CRUD ); $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"BLEEGLE" nosummary="on"}%'); + $this->test_topicObject->expandMacros( + '%SEARCH{"BLEEGLE" nosummary="on"}%'); $this->assert_html_equals( <<"CRUD", _cut_the_crap($result) ); -Searched: BLEEGLEResults from $this->{test_web} web retrieved at TIME +Searched: BLEEGLEResults from $test_web web retrieved at TIME OkATopic NEW - DATE - TIME by [[TemporarySEARCHUsersWeb.WikiGuest][WikiGuest]] @@ -4126,10 +4118,10 @@ NEW - DATE - TIME by [[TemporarySEARCHUsersWeb.WikiGuest][WikiGue Number of topics: 4 CRUD $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"BLEEGLE" nosearch="on"}%'); + $this->test_topicObject->expandMacros( + '%SEARCH{"BLEEGLE" nosearch="on"}%'); $this->assert_html_equals( <<"CRUD", _cut_the_crap($result) ); -Results from $this->{test_web} web retrieved at TIME +Results from $test_web web retrieved at TIME OkATopic BLEEGLE dontmatchme.blah @@ -4151,11 +4143,10 @@ NEW - DATE - TIME by [[TemporarySEARCHUsersWeb.WikiGuest][WikiGue Number of topics: 4 CRUD $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"BLEEGLE" nototal="on"}%'); + $this->test_topicObject->expandMacros('%SEARCH{"BLEEGLE" nototal="on"}%'); $this->assert_html_equals( <<"CRUD", _cut_the_crap($result) ); Searched: BLEEGLE -Results from $this->{test_web} web retrieved at TIME +Results from $test_web web retrieved at TIME OkATopic BLEEGLE dontmatchme.blah @@ -4177,8 +4168,8 @@ NEW - DATE - TIME by [[TemporarySEARCHUsersWeb.WikiGuest][WikiGue CRUD $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"BLEEGLE" noheader="on"}%'); + $this->test_topicObject->expandMacros( + '%SEARCH{"BLEEGLE" noheader="on"}%'); $this->assert_html_equals( <<"CRUD", _cut_the_crap($result) ); Searched: BLEEGLE OkATopic @@ -4200,11 +4191,10 @@ NEW - DATE - TIME by [[TemporarySEARCHUsersWeb.WikiGuest][WikiGue Number of topics: 4 CRUD $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"BLEEGLE" noempty="on"}%'); + $this->test_topicObject->expandMacros('%SEARCH{"BLEEGLE" noempty="on"}%'); $this->assert_html_equals( <<"CRUD", _cut_the_crap($result) ); Searched: BLEEGLE -Results from $this->{test_web} web retrieved at TIME +Results from $test_web web retrieved at TIME @@ -4228,11 +4218,11 @@ NEW - DATE - TIME by [[TemporarySEARCHUsersWeb.WikiGuest][WikiGue Number of topics: 4 CRUD $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"BLEEGLE" zeroresults="on"}%'); + $this->test_topicObject->expandMacros( + '%SEARCH{"BLEEGLE" zeroresults="on"}%'); $this->assert_html_equals( <<"CRUD", _cut_the_crap($result) ); Searched: BLEEGLE -Results from $this->{test_web} web retrieved at TIME +Results from $test_web web retrieved at TIME @@ -4257,12 +4247,12 @@ Number of topics: 4 CRUD $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"BLEEGLE" nosummary="on" nosearch="on" nototal="on" zeroresults="off" noheader="on" noempty="on"}%' ); my $result2 = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"BLEEGLE" nosummary="on" nonoise="on"}%'); + $this->test_topicObject->expandMacros( + '%SEARCH{"BLEEGLE" nosummary="on" nonoise="on"}%'); $result = HTML::Entities::encode_entities( $result, '^\n\x20-\x25\x27-\x7e' ); $result2 = @@ -4277,7 +4267,7 @@ sub verify_search_type_word { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"dont" scope="all" nonoise="on" format="$topic" separator="," type="word"}%' ); $this->assert_str_equals( 'OkBTopic', $result ); @@ -4286,7 +4276,7 @@ sub verify_search_type_word { $this->assert( $dontcount == 0 ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"+dont" scope="all" nonoise="on" format="$topic" separator="," type="word"}%' ); @list = split( /,/, $result ); @@ -4296,7 +4286,7 @@ sub verify_search_type_word { $this->assert( $plus_dontcount == $dontcount ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"-dont" scope="all" nonoise="on" format="$topic" separator="," type="word" excludetopic="SomeOther*"}%' ); $this->assert_str_equals( @@ -4308,7 +4298,7 @@ sub verify_search_type_word { #$this->assert( $minus_dontcount == ($alltopics - $dontcount ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"!dont" scope="all" nonoise="on" format="$topic" separator="," type="word" excludetopic="SomeOther*"}%' ); $this->assert_str_equals( @@ -4318,7 +4308,7 @@ sub verify_search_type_word { $this->assert( $bang_dontcount == 3 ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"\"-dont\"" scope="all" nonoise="on" format="$topic" separator="," type="word"}%' ); $this->assert_str_equals( '', $result ); @@ -4327,7 +4317,7 @@ sub verify_search_type_word { $this->assert( $quote_dontcount == -1 ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"!\"-dont\"" scope="all" nonoise="on" format="$topic" separator="," type="word" excludetopic="Some*"}%' ); $this->assert_str_equals( @@ -4343,7 +4333,7 @@ sub verify_search_type_keyword { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"dont" scope="all" nonoise="on" format="$topic" separator="," type="keyword"}%' ); $this->assert_str_equals( 'OkATopic,OkBTopic', $result ); @@ -4352,7 +4342,7 @@ sub verify_search_type_keyword { $this->assert( $dontcount == 1 ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"+dont" scope="all" nonoise="on" format="$topic" separator="," type="keyword"}%' ); @list = split( /,/, $result ); @@ -4362,7 +4352,7 @@ sub verify_search_type_keyword { $this->assert( $plus_dontcount == $dontcount ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"-dont" scope="all" nonoise="on" format="$topic" separator="," type="keyword" excludetopic="SomeOther*"}%' ); $this->assert_str_equals( 'OkÆTopic,TestTopicSEARCH,WebPreferences', @@ -4374,7 +4364,7 @@ sub verify_search_type_keyword { #$this->assert( $minus_dontcount == ($alltopics - $dontcount ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"!dont" scope="all" nonoise="on" format="$topic" separator="," type="keyword" excludetopic="SomeOther*"}%' ); $this->assert_str_equals( 'OkÆTopic,TestTopicSEARCH,WebPreferences', @@ -4384,7 +4374,7 @@ sub verify_search_type_keyword { $this->assert( $bang_dontcount == 2 ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"\"-dont\"" scope="all" nonoise="on" format="$topic" separator="," type="keyword"}%' ); $this->assert_str_equals( '', $result ); @@ -4393,7 +4383,7 @@ sub verify_search_type_keyword { $this->assert( $quote_dontcount == -1 ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"!\"-dont\"" scope="all" nonoise="on" format="$topic" separator="," type="keyword" excludetopic="SomeOther*"}%' ); $this->assert_str_equals( @@ -4409,7 +4399,7 @@ sub verify_search_type_literal { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"dont" scope="all" nonoise="on" format="$topic" separator="," type="literal" excludetopic="SomeOther*"}%' ); $this->assert_str_equals( 'OkATopic,OkBTopic', $result ); @@ -4418,7 +4408,7 @@ sub verify_search_type_literal { $this->assert( $dontcount == 1 ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"+dont" scope="all" nonoise="on" format="$topic" separator="," type="literal" excludetopic="SomeOther*"}%' ); @list = split( /,/, $result ); @@ -4428,7 +4418,7 @@ sub verify_search_type_literal { $this->assert( $plus_dontcount != $dontcount ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"-dont" scope="all" nonoise="on" format="$topic" separator="," type="literal" excludetopic="SomeOther*"}%' ); $this->assert_str_equals( '', $result ); @@ -4437,7 +4427,7 @@ sub verify_search_type_literal { $this->assert( $minus_dontcount == -1 ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"!dont" scope="all" nonoise="on" format="$topic" separator="," type="literal" excludetopic="SomeOther*"}%' ); $this->assert_str_equals( 'OkÆTopic,TestTopicSEARCH,WebPreferences', @@ -4447,7 +4437,7 @@ sub verify_search_type_literal { $this->assert( $bang_dontcount == 2 ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"\"-dont\"" scope="all" nonoise="on" format="$topic" separator="," type="literal" excludetopic="SomeOther*"}%' ); $this->assert_str_equals( '', $result ); @@ -4456,7 +4446,7 @@ sub verify_search_type_literal { $this->assert( $quote_dontcount == -1 ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"!\"-dont\"" scope="all" nonoise="on" format="$topic" separator="," type="literal" excludetopic="SomeOther*"}%' ); $this->assert_str_equals( @@ -4472,7 +4462,7 @@ sub verify_search_type_regex { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"dont" scope="all" nonoise="on" format="$topic" separator="," type="regex" excludetopic="SomeOther*"}%' ); $this->assert_str_equals( 'OkATopic,OkBTopic', $result ); @@ -4482,7 +4472,7 @@ sub verify_search_type_regex { #this causes regex search to throw an error due to the '+' # $result = -# $this->{test_topicObject}->expandMacros( +# $this->test_topicObject->expandMacros( # '%SEARCH{"+dont" scope="all" nonoise="on" format="$topic" separator="," type="regex"}%'); # @list = split(/,/, $result); # $this->assert_str_equals( '', $result ); @@ -4491,7 +4481,7 @@ sub verify_search_type_regex { # $this->assert( $plus_dontcount != $dontcount ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"-dont" scope="all" nonoise="on" format="$topic" separator="," type="regex" excludetopic="SomeOther*"}%' ); $this->assert_str_equals( '', $result ); @@ -4500,7 +4490,7 @@ sub verify_search_type_regex { $this->assert( $minus_dontcount == -1 ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"!dont" scope="all" nonoise="on" format="$topic" separator="," type="regex" excludetopic="Some*"}%' ); $this->assert_str_equals( 'OkÆTopic,TestTopicSEARCH,WebPreferences', @@ -4510,7 +4500,7 @@ sub verify_search_type_regex { $this->assert( $bang_dontcount == 2 ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"\"-dont\"" scope="all" nonoise="on" format="$topic" separator="," type="regex" excludetopic="SomeOther*"}%' ); $this->assert_str_equals( '', $result ); @@ -4519,7 +4509,7 @@ sub verify_search_type_regex { $this->assert( $quote_dontcount == -1 ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"!\"-dont\"" scope="all" nonoise="on" format="$topic" separator="," type="regex" excludetopic="SomeOther*"}%' ); $this->assert_str_equals( @@ -4543,25 +4533,25 @@ sub verify_stop_words_regex_meta_search_word { my $TEST_TEXT = "xxx i.e. Shamira IEEE a(b)"; my $TEST_TOPIC = 'StopWordTestTopic'; my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, $TEST_TOPIC ); + Foswiki::Func::readTopic( $this->test_web, $TEST_TOPIC ); $topicObject->text($TEST_TEXT); $topicObject->save(); $topicObject->finish(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"IEEE" type="word" scope="text" nonoise="on" format="$topic"}%' ); $this->assert_matches( qr/$TEST_TOPIC/, $result ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"a(b)" type="word" scope="text" nonoise="on" format="$topic"}%' ); $this->assert_str_equals( '', $result ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"i.e." type="word" scope="text" nonoise="on" format="$topic"}%' ); $this->assert_str_equals( '', $result ); @@ -4582,31 +4572,31 @@ sub verify_stop_words_search_word { my $TEST_TEXT = "xxx Shamira"; my $TEST_TOPIC = 'StopWordTestTopic'; my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, $TEST_TOPIC ); + Foswiki::Func::readTopic( $this->test_web, $TEST_TOPIC ); $topicObject->text($TEST_TEXT); $topicObject->save(); $topicObject->finish(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Shamira" type="word" scope="text" nonoise="on" format="$topic"}%' ); $this->assert_matches( qr/$TEST_TOPIC/, $result ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"xxx" type="word" scope="text" nonoise="on" format="$topic"}%' ); $this->assert_str_equals( '', $result ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"+xxx" type="word" scope="text" nonoise="on" format="$topic"}%' ); $this->assert_str_equals( '', $result ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"+xxx" type="word" topic="$TEST_TOPIC" scope="text" nonoise="on" format="$summary(searchcontext)"}%' ); @@ -4623,18 +4613,17 @@ sub createSummaryTestTopic { my $TEST_SUMMARY_TEXT = "Alan says: 'I was on a landing; there were banisters'. He pauses before describing the exact shape and details of the banisters. 'There was a thin man there. I was toppling him over the banisters. He said to me: 'When you have lost the 4 stone and the 14 stone, then you might topple over.' That's all I can remember.' Alan is thoughtful a while then talks about the 'toppling over'. He thinks that the sense was that the man might get unbalanced and topple over. He considers whether he might be pushing him over in the dream. He thought there was a way in which the man was suggesting that when Alan had lost the 4 stone and the 14 stone then he might topple over too; might lose his balance. - As Alan thought about different parts of his dream he let his mind follow the thoughts, images and memories which came to him. He thought about his weight loss programme. He couldn't think why he was dreaming about 4 and 14 stone, but it didn't bother him that he couldn't understand that part, something would probably come up later. Perhaps it's because his next goal is 18 stone, he muses. He remembers being thin as a young man at school. In particular in athletics, competing against an arch-rival in running. He remembers something else which happened at that time too. He smiles with surprise, saying that he hasn't thought of it for 30 years until this moment. But now he notices that thinking about this memory makes him feel anxious. + As Alan thought about different parts of his dream he let his mind follow the thoughts, images and memories which came to him. He thought about his weight loss programme. He couldn't think why he was dreaming about 4 and 14 stone, but it didn't bother him that he couldn't understand that part, something would probably come up later. Perhaps it's because his next goal is 18 stone, he muses. He remembers being thin as a young man at school. In particular in athletics, competing against an arch-rival in running. He remembers something else which happened at that time too. He smiles with surprise, saying that he hasn't thought of it for 30 years until this moment. But now he notices that thinking about this memory makes him feel anxious. - Just as he's saying this, his analyst notices that as she begins to think of what she might say about the dream she finds herself feeling she'll have to be very careful not to say it insensitively and provoke a fight. Subtly and imperceptibly the atmosphere has become tense. He remembers fighting this rival; really fighting as if to the death. He thinks that he might have completely lost control and killed him if this strange thing hadn't happened at that point. He'd just gone like jelly; he got up and walked away. + Just as he's saying this, his analyst notices that as she begins to think of what she might say about the dream she finds herself feeling she'll have to be very careful not to say it insensitively and provoke a fight. Subtly and imperceptibly the atmosphere has become tense. He remembers fighting this rival; really fighting as if to the death. He thinks that he might have completely lost control and killed him if this strange thing hadn't happened at that point. He'd just gone like jelly; he got up and walked away. - After dwelling a little more on the fears he'd suffered as a young thin man about losing control and being violent, he remembers his father's sudden death from a heart attack when he was a boy. What his analyst knows is that this death, so traumatic for Alan, had precipitated his disturbance as a child. He had developed obsessional routines involving checking and re-checking that he had turned off the taps and secured the locks on the windows at night, as if he believed that in some way he was culpable for the death of his father. + After dwelling a little more on the fears he'd suffered as a young thin man about losing control and being violent, he remembers his father's sudden death from a heart attack when he was a boy. What his analyst knows is that this death, so traumatic for Alan, had precipitated his disturbance as a child. He had developed obsessional routines involving checking and re-checking that he had turned off the taps and secured the locks on the windows at night, as if he believed that in some way he was culpable for the death of his father. - Alan interrupts himself to say: 'I went to the doctor yesterday, by the way, to discuss coming off all the pills.' He reminds his analyst that he is currently taking four different pills. He reminds her what each is for: an antipsychotic, an antidepressant, a beta blocker and a blood pressure pill. They speak a bit about the visit to the GP and Alan stresses both his desire to give up all his medication now that he is improving with the help of his analysis and his need to do it very carefully. He knows someone who came off antidepressants suddenly, all at once, and nearly died because the doctors hadn't bothered to warn him that it was dangerous. He checked this out with the GP and is stopping at the rate of half a pill per fortnight. His analyst says: 'Perhaps this helps us understand the 4 and the 14 in the dream. While you very much want to be healthy and be doing well in your analysis, and to manage without taking the 4 pills by giving up more every 14 days, you are also afraid that without the pills and the fat jelly you've covered yourself with, you might get unbalanced and be compelled to fight and be violent. Perhaps you fear your violence towards me, your thin analyst, too. The banisters made me think of those outside the consulting room which you see as you come in.' + Alan interrupts himself to say: 'I went to the doctor yesterday, by the way, to discuss coming off all the pills.' He reminds his analyst that he is currently taking four different pills. He reminds her what each is for: an antipsychotic, an antidepressant, a beta blocker and a blood pressure pill. They speak a bit about the visit to the GP and Alan stresses both his desire to give up all his medication now that he is improving with the help of his analysis and his need to do it very carefully. He knows someone who came off antidepressants suddenly, all at once, and nearly died because the doctors hadn't bothered to warn him that it was dangerous. He checked this out with the GP and is stopping at the rate of half a pill per fortnight. His analyst says: 'Perhaps this helps us understand the 4 and the 14 in the dream. While you very much want to be healthy and be doing well in your analysis, and to manage without taking the 4 pills by giving up more every 14 days, you are also afraid that without the pills and the fat jelly you've covered yourself with, you might get unbalanced and be compelled to fight and be violent. Perhaps you fear your violence towards me, your thin analyst, too. The banisters made me think of those outside the consulting room which you see as you come in.' - Alan says: 'Oh yes; I knew I'd seen them somewhere before! But how do I know I won't go mad and do something to you? I just thought of something, just then.' Alan is now very agitated. 'It makes my blood boil the way analysts never defend themselves when they are attacked in the press. You hear one slander after another about Freud and psychoanalysis, and what do your lot do? Nothing!'"; + Alan says: 'Oh yes; I knew I'd seen them somewhere before! But how do I know I won't go mad and do something to you? I just thought of something, just then.' Alan is now very agitated. 'It makes my blood boil the way analysts never defend themselves when they are attacked in the press. You hear one slander after another about Freud and psychoanalysis, and what do your lot do? Nothing!'"; - my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, $topicName ); + my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, $topicName ); $topicObject->text($TEST_SUMMARY_TEXT); $topicObject->save(); $topicObject->finish(); @@ -4654,7 +4643,7 @@ sub test_summary_default_word_search { $this->createSummaryTestTopic('TestSummaryTopic'); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Alan" type="word" topic="TestSummaryTopic" scope="text" nonoise="on" format="$summary"}%' ); @@ -4677,7 +4666,7 @@ sub test_summary_short_word_search { $this->createSummaryTestTopic('TestSummaryTopic'); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Alan" type="word" topic="TestSummaryTopic" scope="text" nonoise="on" format="$summary(12)"}%' ); @@ -4700,7 +4689,7 @@ sub test_summary_searchcontext_default_word_search { $this->createSummaryTestTopic('TestSummaryTopic'); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"do" type="word" topic="TestSummaryTopic" scope="text" nonoise="on" format="$summary(searchcontext)"}%' ); @@ -4723,7 +4712,7 @@ sub test_summary_searchcontext_short_word_search { $this->createSummaryTestTopic('TestSummaryTopic'); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"his" type="word" topic="TestSummaryTopic" scope="text" nonoise="on" format="$summary(searchcontext,40)"}%' ); @@ -4746,7 +4735,7 @@ sub test_summary_searchcontext_long_word_search { $this->createSummaryTestTopic('TestSummaryTopic'); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"his" type="word" topic="TestSummaryTopic" scope="text" nonoise="on" format="$summary(searchcontext,200)"}%' ); @@ -4761,47 +4750,47 @@ sub verify_zeroresults { my $this = shift; my $result; - $result = $this->{test_topicObject}->expandMacros('%SEARCH{"NOBLEEGLE"}%'); + $result = $this->test_topicObject->expandMacros('%SEARCH{"NOBLEEGLE"}%'); $this->assert_html_equals( <<'RESULT', _cut_the_crap($result) ); Searched: NOBLEEGLE Number of topics: 0 RESULT $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"NOBLEEGLE" zeroresults="on"}%'); + $this->test_topicObject->expandMacros( + '%SEARCH{"NOBLEEGLE" zeroresults="on"}%'); $this->assert_html_equals( <<'RESULT', _cut_the_crap($result) ); Searched: NOBLEEGLE Number of topics: 0 RESULT $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"NOBLEEGLE" zeroresults="off"}%'); + $this->test_topicObject->expandMacros( + '%SEARCH{"NOBLEEGLE" zeroresults="off"}%'); $this->assert_equals( '', $result ); #Item10324: should return the string '0' ? (I'm not so sure) $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"NOBLEEGLE" zeroresults="0"}%'); + $this->test_topicObject->expandMacros( + '%SEARCH{"NOBLEEGLE" zeroresults="0"}%'); $this->assert_equals( '', $result ); $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"NOBLEEGLE" zeroresults="%NOP%0"}%'); + $this->test_topicObject->expandMacros( + '%SEARCH{"NOBLEEGLE" zeroresults="%NOP%0"}%'); $this->assert_equals( '0', $result ); $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"NOBLEEGLE" zeroresults=" 0"}%'); + $this->test_topicObject->expandMacros( + '%SEARCH{"NOBLEEGLE" zeroresults=" 0"}%'); $this->assert_equals( '', $result ); $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"NOBLEEGLE" zeroresults="1"}%'); + $this->test_topicObject->expandMacros( + '%SEARCH{"NOBLEEGLE" zeroresults="1"}%'); $this->assert_equals( '1', $result ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"NOBLEEGLE" zeroresults="I did not find anything."}%'); $this->assert_html_equals( <<'RESULT', _cut_the_crap($result) ); I did not find anything. @@ -4809,26 +4798,26 @@ RESULT #nototal=on $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"NOBLEEGLE" nototal="on"}%'); + $this->test_topicObject->expandMacros( + '%SEARCH{"NOBLEEGLE" nototal="on"}%'); $this->assert_html_equals( <<'RESULT', _cut_the_crap($result) ); Searched: NOBLEEGLE RESULT $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"NOBLEEGLE" nototal="on" zeroresults="on"}%'); + $this->test_topicObject->expandMacros( + '%SEARCH{"NOBLEEGLE" nototal="on" zeroresults="on"}%'); $this->assert_html_equals( <<'RESULT', _cut_the_crap($result) ); Searched: NOBLEEGLE RESULT $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"NOBLEEGLE" nototal="on" zeroresults="off"}%'); + $this->test_topicObject->expandMacros( + '%SEARCH{"NOBLEEGLE" nototal="on" zeroresults="off"}%'); $this->assert_equals( '', $result ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"NOBLEEGLE" nototal="on" zeroresults="I did not find anything."}%' ); $this->assert_html_equals( <<'RESULT', _cut_the_crap($result) ); @@ -4837,28 +4826,28 @@ RESULT #nototal=off $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"NOBLEEGLE" nototal="off"}%'); + $this->test_topicObject->expandMacros( + '%SEARCH{"NOBLEEGLE" nototal="off"}%'); $this->assert_html_equals( <<'RESULT', _cut_the_crap($result) ); Searched: NOBLEEGLE Number of topics: 0 RESULT $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"NOBLEEGLE" nototal="off" zeroresults="on"}%'); + $this->test_topicObject->expandMacros( + '%SEARCH{"NOBLEEGLE" nototal="off" zeroresults="on"}%'); $this->assert_html_equals( <<'RESULT', _cut_the_crap($result) ); Searched: NOBLEEGLE Number of topics: 0 RESULT $result = - $this->{test_topicObject} - ->expandMacros('%SEARCH{"NOBLEEGLE" nototal="off" zeroresults="off"}%'); + $this->test_topicObject->expandMacros( + '%SEARCH{"NOBLEEGLE" nototal="off" zeroresults="off"}%'); $this->assert_equals( '', $result ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"NOBLEEGLE" nototal="off" zeroresults="I did not find anything."}%' ); $this->assert_html_equals( <<'RESULT', _cut_the_crap($result) ); @@ -4878,7 +4867,7 @@ A Symbol Interpreted In American Architecture. Meta-Physics Of Marxism & Poverty HERE my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, "VeryOldTopic" ); + Foswiki::Func::readTopic( $this->test_web, "VeryOldTopic" ); $topicObject->text($text); $topicObject->put( 'TOPICINFO', @@ -4896,11 +4885,11 @@ HERE #TODO: sadly, the core Handlers don't set the filedate # even though they could # my $file_date = - # $this->{session}->{store} - # ->getApproxRevTime( $this->{test_web}, "VeryOldTopic" ); + # $this->session->store + # ->getApproxRevTime( $this->test_web, "VeryOldTopic" ); # $this->assert_num_equals(86420, $file_date); - my $result = $this->{test_topicObject} + my $result = $this->test_topicObject #SMELL: #TODO: the query type should be abstracted to test each&all backends @@ -4924,7 +4913,7 @@ Suicide Paganism. HERE my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, "OffColour" ); + Foswiki::Func::readTopic( $this->test_web, "OffColour" ); $topicObject->text($text); $topicObject->putKeyed( 'FIELD', @@ -4942,7 +4931,7 @@ HERE # Default $formfield, \n expands to
because people most often display # multiline form fields in TML tables and \n would disturb the tables $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"OffColour" scope="topic" nonoise="on" format="$formfield(Name)"}%' ); $this->assert_str_equals( <<'RESULT', "$result\n" ); @@ -4951,7 +4940,7 @@ RESULT # Default $pattern, \n expands to \n (more sensible) $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"OffColour" scope="topic" nonoise="on" format="$pattern(.*?(Meta.*?Paganism).*)"}%' ); $this->assert_str_equals( <<'RESULT', "$result\n" ); @@ -4964,7 +4953,7 @@ RESULT # $pattern newline="X", \n expands to X $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"OffColour" scope="topic" nonoise="on" format="$pattern(.*?(Meta.*?Paganism).*)" newline="X"}%' ); $this->assert_str_equals( <<'RESULT', "$result\n" ); @@ -4973,7 +4962,7 @@ RESULT # $formfield, newline="X", \n in form data expands to X $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"OffColour" scope="topic" nonoise="on" format="$formfield(Name)" newline="X"}%' ); $this->assert_str_equals( <{test_topicObject}->web, - $this->{test_topicObject}->topic, 'view' ); + Foswiki::Func::getScriptUrl( $this->test_topicObject->web, + $this->test_topicObject->topic, 'view' ); - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -5032,7 +5021,7 @@ FOSWIKI11 $expected =~ s/\n$//s; $this->assert_str_equals( $expected, $result ); - $result = $this->{test_topicObject}->expandMacros( + $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -5079,10 +5068,10 @@ sub test_pager_on_pagerformat { my $this = shift; my $viewTopicUrl = - Foswiki::Func::getScriptUrl( $this->{test_topicObject}->web, - $this->{test_topicObject}->topic, 'view' ); + Foswiki::Func::getScriptUrl( $this->test_topicObject->web, + $this->test_topicObject->topic, 'view' ); - my $result = $this->{test_topicObject}->expandMacros(<<'EXPECT'); + my $result = $this->test_topicObject->expandMacros(<<'EXPECT'); %SEARCH{ "web" type="text" @@ -5120,7 +5109,7 @@ FOOT(1,1) FOSWIKI11 $this->assert_str_equals( $expected, $result ); - $result = $this->{test_topicObject}->expandMacros( + $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -5166,10 +5155,10 @@ sub test_pager_off_pagerformat { my $this = shift; my $viewTopicUrl = - Foswiki::Func::getScriptUrl( $this->{test_topicObject}->web, - $this->{test_topicObject}->topic, 'view' ); + Foswiki::Func::getScriptUrl( $this->test_topicObject->web, + $this->test_topicObject->topic, 'view' ); - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -5206,7 +5195,7 @@ FOSWIKI11 $expected =~ s/\n$//s; $this->assert_str_equals( $expected, $result ); - $result = $this->{test_topicObject}->expandMacros( + $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -5250,10 +5239,10 @@ sub test_pager_off_pagerformat_pagerinheaderfooter { my $this = shift; my $viewTopicUrl = - Foswiki::Func::getScriptUrl( $this->{test_topicObject}->web, - $this->{test_topicObject}->topic, 'view' ); + Foswiki::Func::getScriptUrl( $this->test_topicObject->web, + $this->test_topicObject->topic, 'view' ); - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -5295,7 +5284,7 @@ FOSWIKI11 $expected =~ s/\n$//s; $this->assert_str_equals( $expected, $result ); - $result = $this->{test_topicObject}->expandMacros( + $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -5343,7 +5332,7 @@ FOSWIKI11 sub verify_pager_off_pagerformat_pagerinall { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{ "web" type="text" @@ -5392,7 +5381,7 @@ FOSWIKI11 sub test_simple_format { my $this = shift; - my $actual = $this->{test_topicObject}->expandMacros( + my $actual = $this->test_topicObject->expandMacros( '%SEARCH{ "(WebPreferences|WebTopicList|WebHome)$" type="regex" @@ -5449,7 +5438,7 @@ FOSWIKI11 sub test_formatdotBang { my $this = shift; - my $actual = $this->{test_topicObject}->expandMacros( + my $actual = $this->test_topicObject->expandMacros( '%SEARCH{ "(WebPreferences|WebTopicList|WebHome)$" type="regex" @@ -5487,7 +5476,7 @@ sub test_delayed_expansion { format => '$topic', separator => ", ", }, - $this->{test_topicObject} + $this->test_topicObject ); $this->assert_str_equals( $this->toSiteCharSet(<<'EXPECT'), $result . "\n" ); @@ -5504,7 +5493,7 @@ EXPECT format => '$percentWIKINAME$percent', separator => ", ", }, - $this->{test_topicObject} + $this->test_topicObject ); $this->assert_str_equals( $this->toSiteCharSet(<<'EXPECT'), $result . "\n" ); @@ -5524,7 +5513,7 @@ EXPECT format => '$topic', separator => ", ", }, - $this->{test_topicObject} + $this->test_topicObject ); $this->assert_str_equals( $this->toSiteCharSet(<<'EXPECT'), $result . "\n" ); @@ -5545,10 +5534,8 @@ somethig after HERE -# $this->{twiki}->{store}->saveTopic( 'simon', -# $this->{test_web}, 'QueryTopic', $text, undef, {forcedate=>1178612772} ); my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'QueryTopic' ); + Foswiki::Func::readTopic( $this->test_web, 'QueryTopic' ); $topicObject->text($text); $topicObject->put( 'TOPICINFO', @@ -5661,10 +5648,8 @@ This is QueryTopicTwo SMONG third line HERE - #$this->{twiki}->{store}->saveTopic( 'admin', - # $this->{test_web}, 'QueryTopicTwo', $text, undef, {forcedate=>12} ); ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'QueryTopicTwo' ); + Foswiki::Func::readTopic( $this->test_web, 'QueryTopicTwo' ); $topicObject->text($text); $topicObject->put( 'TOPICINFO', @@ -5777,10 +5762,8 @@ This is QueryTopicThree SMONG third line HERE - #$this->{twiki}->{store}->saveTopic( 'Gerald', - # $this->{test_web}, 'QueryTopicThree', $text, undef, {forcedate=>14} ); ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'QueryTopicThree' ); + Foswiki::Func::readTopic( $this->test_web, 'QueryTopicThree' ); $topicObject->text($text); $topicObject->put( 'TOPICINFO', @@ -5879,10 +5862,10 @@ HERE $topicObject->finish(); my $query = Unit::Request->new(''); - $query->path_info("/$this->{test_web}/$this->{test_topic}"); + $query->path_info( "/" . $this->test_web . "/" . $this->test_topic ); $this->createNewFoswikiSession( undef, $query ); - $this->assert_str_equals( $this->{test_web}, $this->{session}->{webName} ); + $this->assert_str_equals( $this->test_web, $this->session->webName ); return; } @@ -5893,13 +5876,13 @@ sub test_orderTopic { $this->set_up_for_sorting(); my $search = '%SEARCH{".*" type="regex" scope="topic" web="' - . $this->{test_web} + . $this->test_web . '" format="$topic" separator="," nonoise="on" ' . 'excludetopic="SomeOtherÆØÅTopic" '; my $result; #DEFAULT sort=topic.. - $result = $this->{test_topicObject}->expandMacros( $search . '}%' ); + $result = $this->test_topicObject->expandMacros( $search . '}%' ); $this->assert_str_equals( "OkATopic,OkBTopic,OkÆTopic,QueryTopic,QueryTopicThree,QueryTopicTwo,TestTopicSEARCH,WebPreferences", @@ -5908,15 +5891,15 @@ sub test_orderTopic { #order=topic $result = - $this->{test_topicObject}->expandMacros( $search . 'order="topic"}%' ); + $this->test_topicObject->expandMacros( $search . 'order="topic"}%' ); $this->assert_str_equals( "OkATopic,OkBTopic,OkÆTopic,QueryTopic,QueryTopicThree,QueryTopicTwo,TestTopicSEARCH,WebPreferences", $result ); $result = - $this->{test_topicObject} - ->expandMacros( $search . 'order="topic" reverse="on"}%' ); + $this->test_topicObject->expandMacros( + $search . 'order="topic" reverse="on"}%' ); $this->assert_str_equals( "WebPreferences,TestTopicSEARCH,QueryTopicTwo,QueryTopicThree,QueryTopic,OkÆTopic,OkBTopic,OkATopic", $result @@ -5924,8 +5907,8 @@ sub test_orderTopic { #order=created $result = - $this->{test_topicObject} - ->expandMacros( $search . 'order="created" format="$topic"}%' ); + $this->test_topicObject->expandMacros( + $search . 'order="created" format="$topic"}%' ); $this->assert_str_equals( "QueryTopicTwo,QueryTopicThree,QueryTopic,WebPreferences,TestTopicSEARCH,OkÆTopic,OkATopic,OkBTopic", @@ -5933,8 +5916,8 @@ sub test_orderTopic { ); $result = - $this->{test_topicObject} - ->expandMacros( $search . 'order="created" reverse="on"}%' ); + $this->test_topicObject->expandMacros( + $search . 'order="created" reverse="on"}%' ); $this->assert_str_equals( "OkBTopic,OkATopic,OkÆTopic,TestTopicSEARCH,WebPreferences,QueryTopic,QueryTopicThree,QueryTopicTwo", @@ -5943,7 +5926,7 @@ sub test_orderTopic { #order=modified $result = - $this->{test_topicObject}->expandMacros( $search . 'order="modified"}%' ); + $this->test_topicObject->expandMacros( $search . 'order="modified"}%' ); $this->assert_str_equals( "QueryTopicThree,QueryTopic,QueryTopicTwo,WebPreferences,TestTopicSEARCH,OkÆTopic,OkATopic,OkBTopic", @@ -5951,7 +5934,7 @@ sub test_orderTopic { ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( $search . 'order="modified" reverse="on" format="$topic"}%' ); #be very careful with this test and the one above - the change in order between QueryTopicTwo,QueryTopic is due to them having the same date, so its sorting by topicname @@ -5963,7 +5946,7 @@ sub test_orderTopic { #order=editby #TODO: imo this is a bug - alpha sorting should be caseinsensitive $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( $search . 'order="editby" format="$topic ($wikiname)"}%' ); # $this->assert_str_equals( "QueryTopicThree (Gerald),OkATopic (WikiGuest),OkBTopic (WikiGuest),OkÆTopic (WikiGuest),TestTopicSEARCH (WikiGuest),WebPreferences (WikiGuest),QueryTopicTwo (admin),QueryTopic (simon)", $result ); @@ -5980,7 +5963,7 @@ qr/^QueryTopicThree \(Gerald\),.*WikiGuest\),QueryTopic \(simon\),QueryTopicTwo #TODO: why is this different from 1.0.x? $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( $search . 'order="editby" reverse="on" format="$topic ($wikiname)"}%' ); # $this->assert_str_equals( "QueryTopic (simon),QueryTopicTwo (admin),OkATopic (WikiGuest),OkBTopic (WikiGuest),OkÆTopic (WikiGuest),TestTopicSEARCH (WikiGuest),WebPreferences (WikiGuest),QueryTopicThree (Gerald)", $result ); @@ -5998,7 +5981,7 @@ qr/^QueryTopic \(simon\),QueryTopicTwo \(simon\),.*\(WikiGuest\),QueryTopicThree #order=formfield(FieldA) $result = - $this->{test_topicObject}->expandMacros( $search + $this->test_topicObject->expandMacros( $search . 'order="formfield(FieldA)" format="$topic ($formfield(FieldA))"}%' ); @@ -6013,7 +5996,7 @@ qr/^QueryTopic \(simon\),QueryTopicTwo \(simon\),.*\(WikiGuest\),QueryTopicThree ); $result = - $this->{test_topicObject}->expandMacros( $search + $this->test_topicObject->expandMacros( $search . 'order="formfield(FieldA)" reverse="on" format="$topic ($formfield(FieldA))"}%' ); @@ -6025,7 +6008,7 @@ qr/^QueryTopic \(simon\),QueryTopicTwo \(simon\),.*\(WikiGuest\),QueryTopicThree #order=formfield(FieldB) $result = - $this->{test_topicObject}->expandMacros( $search + $this->test_topicObject->expandMacros( $search . 'order="formfield(FieldB)" format="$topic ($formfield(FieldB))"}%' ); @@ -6036,7 +6019,7 @@ qr/^QueryTopic \(simon\),QueryTopicTwo \(simon\),.*\(WikiGuest\),QueryTopicThree ); $result = - $this->{test_topicObject}->expandMacros( $search + $this->test_topicObject->expandMacros( $search . 'order="formfield(FieldB)" reverse="on" format="$topic ($formfield(FieldB))"}%' ); @@ -6048,7 +6031,7 @@ qr/^QueryTopic \(simon\),QueryTopicTwo \(simon\),.*\(WikiGuest\),QueryTopicThree #order=formfield(FieldC) $result = - $this->{test_topicObject}->expandMacros( $search + $this->test_topicObject->expandMacros( $search . 'order="formfield(FieldC)" format="$topic ($formfield(FieldC))"}%' ); @@ -6059,7 +6042,7 @@ qr/^QueryTopic \(simon\),QueryTopicTwo \(simon\),.*\(WikiGuest\),QueryTopicThree ); $result = - $this->{test_topicObject}->expandMacros( $search + $this->test_topicObject->expandMacros( $search . 'order="formfield(FieldC)" reverse="on" format="$topic ($formfield(FieldC))"}%' ); @@ -6071,7 +6054,7 @@ qr/^QueryTopic \(simon\),QueryTopicTwo \(simon\),.*\(WikiGuest\),QueryTopicThree #order=formfield(Firstname) $result = - $this->{test_topicObject}->expandMacros( $search + $this->test_topicObject->expandMacros( $search . 'order="formfield(Firstname)" format="$topic ($formfield(Firstname))"}%' ); @@ -6082,7 +6065,7 @@ qr/^QueryTopic \(simon\),QueryTopicTwo \(simon\),.*\(WikiGuest\),QueryTopicThree ); $result = - $this->{test_topicObject}->expandMacros( $search + $this->test_topicObject->expandMacros( $search . 'order="formfield(Firstname)" reverse="on" format="$topic ($formfield(Firstname))"}%' ); @@ -6094,7 +6077,7 @@ qr/^QueryTopic \(simon\),QueryTopicTwo \(simon\),.*\(WikiGuest\),QueryTopicThree #order=formfield(Date) $result = - $this->{test_topicObject}->expandMacros( $search + $this->test_topicObject->expandMacros( $search . 'order="formfield(Date)" format="$topic ($formfield(Date))"}%' ); $this->assert_str_equals( @@ -6103,7 +6086,7 @@ qr/^QueryTopic \(simon\),QueryTopicTwo \(simon\),.*\(WikiGuest\),QueryTopicThree ); $result = - $this->{test_topicObject}->expandMacros( $search + $this->test_topicObject->expandMacros( $search . 'order="formfield(Date)" reverse="on" format="$topic ($formfield(Date))"}%' ); @@ -6121,11 +6104,11 @@ sub verify_bad_order { $this->set_up_for_sorting(); my $search = '%SEARCH{".*" type="regex" scope="topic" web="' - . $this->{test_web} + . $this->test_web . '" format="$topic" separator="," nonoise="on" excludetopic="Some*"'; my $result = - $this->{test_topicObject} - ->expandMacros( $search . 'order="formfield()"}%' ); + $this->test_topicObject->expandMacros( + $search . 'order="formfield()"}%' ); # Should get the default search order (or an error message, perhaps?) $this->assert_str_equals( @@ -6139,7 +6122,7 @@ sub verify_bad_order { sub test_Item9269 { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{"does not matc[h]" type="regex" zeroresults="$dollarweb=$web" @@ -6147,9 +6130,9 @@ sub test_Item9269 { }%' ); - $this->assert_str_equals( "\$web=$this->{test_web}", $result ); + $this->assert_str_equals( "\$web=" . $this->test_web, $result ); - $result = $this->{test_topicObject}->expandMacros( + $result = $this->test_topicObject->expandMacros( '%SEARCH{".*" limit="1" type="regex" @@ -6161,12 +6144,12 @@ sub test_Item9269 { ); $this->assert_str_equals( - "header: \$web=$this->{test_web}
-format: \$web=$this->{test_web}
-footer: \$web=$this->{test_web}", $result + "header: \$web=" . $this->test_web . "
+format: \$web=" . $this->test_web . "
+footer: \$web=" . $this->test_web, $result ); - $result = $this->{test_topicObject}->expandMacros( + $result = $this->test_topicObject->expandMacros( '%SEARCH{".*" type="regex" nonoise="on" @@ -6182,7 +6165,7 @@ footer: \$web=$this->{test_web}", $result 1 OkBTopic 1 OkÆTopic 1 TestTopicSEARCH -pagerformat: \$web=$this->{test_web}", $result +pagerformat: \$web=" . $this->test_web, $result ); return; @@ -6191,7 +6174,7 @@ pagerformat: \$web=$this->{test_web}", $result sub test_Item9502 { my $this = shift; - my $result = $this->{test_topicObject}->expandMacros( + my $result = $this->test_topicObject->expandMacros( '%SEARCH{"1" type="query" web="%WEB%" @@ -6211,14 +6194,13 @@ sub test_format_tokens { my $this = shift; local $Foswiki::cfg{AntiSpam}{HideUserDetails} = 0; my $emailAddress = - $this->{test_topicObject} - ->expandMacros('%USERINFO{"ScumBag" format="$emails"}%'); + $this->test_topicObject->expandMacros( + '%USERINFO{"ScumBag" format="$emails"}%'); $this->assert_matches( qr/^[a-z]+\@[a-z.]+$/, $emailAddress ); my $testTopic = 'TestFormatTokens'; my $header = "Search with Userinfo"; my $body = ' * Set POTLEADER = ScumBag'; - my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, $testTopic ); + my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, $testTopic ); $topicObject->text("---++ $header\n$body\n"); $topicObject->put( 'FORM', { name => "TestyForm" } ); $topicObject->put( 'TOPICPARENT', { name => "WebHome" } ); @@ -6235,6 +6217,7 @@ sub test_format_tokens { my $testUser = 'WikiGuest'; my $nop = qr/(?:)+/o; my $topicWithDashes = $testTopic; + my $test_web = $this->test_web; $topicWithDashes =~ s/\G(.....)/$1-/g; my $isodate_pattern; if ( $Foswiki::cfg{DisplayTimeValues} eq 'gmtime' ) { @@ -6245,7 +6228,7 @@ sub test_format_tokens { qr/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d[\+\-]\d\d(:?\d\d)?$/; } my %testFormatTokens = ( - '$web' => $this->{test_web}, + '$web' => $test_web, '$topic' => $testTopic, '$topic(20)' => substr( $testTopic, 0, 20 ), '$topic(5, -)' => $topicWithDashes, @@ -6260,7 +6243,7 @@ sub test_format_tokens { '$index' => 1, '$nhits' => 1, '$ntopics' => 1, - '$item' => "$this->{test_web}.$testTopic", + '$item' => "$test_web.$testTopic", '$rev' => 1, '$username' => 'guest', '$wikiname' => $testUser, @@ -6268,7 +6251,7 @@ sub test_format_tokens { '$createusername' => 'guest', '$createwikiname' => $testUser, '$createwikiusername' => "$Foswiki::cfg{UsersWebName}.$testUser", - '$changes' => qr/^$nop$this->{test_web}\.$testTopic $header/, + '$changes' => qr/^$nop$test_web\.$testTopic $header/, '$changes(1)' => '', # Only 1 revision '$formname' => 'TestyForm', '$formfield(Option)' => 'Some long test I can truncate later', @@ -6326,10 +6309,12 @@ sub test_format_percent_tokens { my $this = shift; my $testTopic = 'TestFormatIncludedTokens'; my $body = '%PUBURL%/%WEB%/%TOPIC%/Something.jpg'; - my $testWeb = $this->{test_web} . '/TestSearchFormatWeb'; + my $testWeb = $this->test_web . '/TestSearchFormatWeb'; my $search = "%SEARCH{\"Something\" web=\"$testWeb\" topic=\"$testTopic\" " . 'expandvariables="on" nonoise="on" format="$pattern(.*?begin (.*?) end.*)"}%'; + my $test_web = $this->test_web; + my $test_topic = $this->test_topic; Foswiki::Func::createWeb($testWeb); my ($topicObject) = Foswiki::Func::readTopic( $testWeb, $testTopic ); $topicObject->text("begin $body end\n"); @@ -6337,21 +6322,21 @@ sub test_format_percent_tokens { my $expected = $topicObject->expandMacros($body); my $expectedFail = $expected; for ($expectedFail) { - s/$testWeb/$this->{test_web}/g; - s/$testTopic/$this->{test_topic}/g; + s/$testWeb/$test_web/g; + s/$testTopic/$test_topic/g; } my $result = $topicObject->expandMacros($search); $this->assert_equals( $expected, $result, "Expansion of SEARCH failed locally!\n" . "Expected:'$expected'\n But got:'$result'\n" ); - $result = $this->{test_topicObject}->expandMacros($search); + $result = $this->test_topicObject->expandMacros($search); $this->assert_equals( $expected, $result, "Expansion of SEARCH failed remotely!\n" . "Expected:'$expected'\n But got:'$result'\n" ); $search =~ s/(expandvariables)="on"/$1="off"/; - $result = $this->{test_topicObject}->expandMacros($search); + $result = $this->test_topicObject->expandMacros($search); $this->assert_equals( $expectedFail, $result, "Expansion of SEARCH failed remotely (expandvariables=\"off\")!\n" . "Expected:'$expectedFail'\n But got:'$result'\n" ); @@ -6363,7 +6348,7 @@ sub test_search_scope_topic { my $this = shift; my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"VarREMOTE" web="%SYSTEMWEB%" scope="topic" format="$topic" separator="," nonoise="on"}%' ); @@ -6379,40 +6364,39 @@ sub test_minus_scope_all { my $this = shift; my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'VirtualBeer' ); + Foswiki::Func::readTopic( $this->test_web, 'VirtualBeer' ); $topicObject->text("There are alot of Virtual Beers to go around"); $topicObject->save(); $topicObject->finish(); - ($topicObject) = Foswiki::Func::readTopic( $this->{test_web}, 'RealBeer' ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'RealBeer' ); $topicObject->text("There are alot of Virtual Beer to go around"); $topicObject->save(); $topicObject->finish(); ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'FamouslyBeered' ); + Foswiki::Func::readTopic( $this->test_web, 'FamouslyBeered' ); $topicObject->text( "Virtually speaking there could be alot of famous Beers"); $topicObject->save(); $topicObject->finish(); - ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'VirtualLife' ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'VirtualLife' ); $topicObject->text("In a all life, I would expect to find fine Beer"); $topicObject->save(); $topicObject->finish(); - ($topicObject) = Foswiki::Func::readTopic( $this->{test_web}, 'NoLife' ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'NoLife' ); $topicObject->text("In a all life, I would expect to find fine Beer"); $topicObject->save(); $topicObject->finish(); - ($topicObject) = Foswiki::Func::readTopic( $this->{test_web}, 'NoBeer' ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'NoBeer' ); $topicObject->text("In a all life, I would expect to find fine Beer"); $topicObject->save(); $topicObject->finish(); - ($topicObject) = Foswiki::Func::readTopic( $this->{test_web}, 'SomeBeer' ); + ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'SomeBeer' ); $topicObject->text("In a all life, I would expect to find fine Wine"); $topicObject->save(); $topicObject->finish(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"-Virtual" scope="all" type="word" nonoise="on" format="$topic" excludetopic="SomeOther*"}%' ); @@ -6430,7 +6414,7 @@ EXPECT $this->assert_str_equals( $expected, $result . "\n" ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Beer" scope="all" type="word" nonoise="on" format="$topic" excludetopic="SomeOther*"}%' ); @@ -6446,7 +6430,7 @@ EXPECT $this->assert_str_equals( $expected, $result . "\n" ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"-Virtual Beer" scope="all" type="word" nonoise="on" format="$topic" excludetopic="SomeOther*"}%' ); @@ -6459,7 +6443,7 @@ EXPECT $this->assert_str_equals( $expected, $result . "\n" ); $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"Beer -Virtual" scope="all" type="word" nonoise="on" format="$topic" excludetopic="SomeOther*"}%' ); @@ -6481,7 +6465,7 @@ sub verify_Item10269 { $this->set_up_for_queries(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"NewField=\'Profile/Builder.TermForm\'"' . $stdCrap ); $this->assert_str_equals( 'QueryTopicTwo', $result ); @@ -6495,15 +6479,15 @@ sub verify_Item10398 { $this->set_up_for_queries(); my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'Trash.MainBobTest' ); + Foswiki::Func::readTopic( $this->test_web, 'Trash.MainBobTest' ); $topicObject->text("BLEEGLE blah/matchme.blah"); $topicObject->save(); $topicObject->finish(); my $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"name=\'WebPreferences\'" type="query" web="' - . $this->{test_web} + $this->test_topicObject->expandMacros( + '%SEARCH{"name=\'WebPreferences\'" type="query" web="' + . $this->test_web . '" recurse="on" nonoise="on" format="$topic"}%' ); $this->assert_str_equals( 'WebPreferences', $result ); @@ -6517,8 +6501,8 @@ sub verify_lhs_lc_field_rhs_lc_string { $this->set_up_for_queries(); my $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"lc(Firstname)=lc(\'JOHN\')"' . $stdCrap ); + $this->test_topicObject->expandMacros( + '%SEARCH{"lc(Firstname)=lc(\'JOHN\')"' . $stdCrap ); $this->assert_str_equals( 'QueryTopicTwo', $result ); return; @@ -6531,7 +6515,7 @@ sub verify_Item10491 { #$this->set_up_for_queries(); my ($topicObject) = - Foswiki::Func::readTopic( $this->{test_web}, 'Item10491' ); + Foswiki::Func::readTopic( $this->test_web, 'Item10491' ); $topicObject->text(<<'TOPICTEXT' ); Search on Foswiki.org has been showing some signs of corruption. The topic Tasks/Item968 appeared to be related, however it can be created From IRC: @@ -6584,19 +6568,20 @@ TOPICTEXT $topicObject->save(); $topicObject->finish(); + my $test_web = $this->test_web; my $result = - $this->{test_topicObject} - ->expandMacros( '%SEARCH{"SomeString" type="word" web="' - . $this->{test_web} + $this->test_topicObject->expandMacros( + '%SEARCH{"SomeString" type="word" web="' + . $this->test_web . '" scope="all" order="topic"}%' ); $this->assert_str_equals( _cut_the_crap(<<"RESULT"), _cut_the_crap( $result . "\n" ) );
Searched: SomeString
-

Results from $this->{test_web} web retrieved at 04:34 (GMT)

+

Results from $test_web web retrieved at 04:34 (GMT)

-Item10491 +Item10491
it can be created From IRC: SomeString.txt So hopefully this topic hits don't get corrupted. SomeString? " txt: SomeString? And ?tab=searchadvanced search=SomeString scope=all order=topic type=
-
NEW - 16 Mar 2011 - 04:34 by !WikiGuest
+
NEW - 16 Mar 2011 - 04:34 by !WikiGuest
Number of topics: 1
RESULT @@ -6612,7 +6597,7 @@ sub verify_multiple_order_fields { $this->set_up_for_queries(); my $result = - $this->{test_topicObject}->expandMacros( + $this->test_topicObject->expandMacros( '%SEARCH{"1" order="formfield(Firstname),formfield(Lastname)" ' . $stdCrap ); $this->assert_str_equals( @@ -6624,14 +6609,15 @@ sub verify_multiple_order_fields { } sub verify_crossweb_op_ref { - my $this = shift; - my %topics = ( - "$this->{test_web}/LLB/Analyses/Sequences.00001" => <<"HERE", + my $this = shift; + my $test_web = $this->test_web; + my %topics = ( + "$test_web/LLB/Analyses/Sequences.00001" => <<"HERE", %META:TOPICINFO{author="BaseUserMapping_333" date="1313039642" format="1.1" version="1"}% %META:TOPICPARENT{name="All"}% %META:FORM{name="Profile/Definitions.Acacia_Sequence_Form"}% -%META:FIELD{name="Acacia_TraceSet" title="TraceSet" type="llb+input" value="$this->{test_web}/LLB/Results/TraceSets.00001"}% +%META:FIELD{name="Acacia_TraceSet" title="TraceSet" type="llb+input" value="$test_web/LLB/Results/TraceSets.00001"}% %META:FIELD{name="Acacia_WorkState" title="Editing" type="list+one" value="done"}% %META:FIELD{name="Acacia_Complete" title="Complete" type="boolean" value="1"}% %META:FIELD{name="Acacia_DateCompleted" title="Date completed" type="date" value=""}% @@ -6640,12 +6626,12 @@ sub verify_crossweb_op_ref { %META:FIELD{name="Acacia_SequenceNotes" title="Notes" type="richtext" value=""}% %META:FIELD{name="Acacia_Sequence" title="Sequence" type="llb+sequence" value="TCGGCTTTTAAGTGCGACTCAAAATTTTACACATTTCTATGAAGCAATGGATTCATCCATACCATCGGTAGAGTTTGTAAGACCACGACTGATCCAGAAAGGAATGAATGGAAAAAGCAGCATGTCGTATCAATGGAGAATTCTAAGACTATCTCATTTTTATTGGATCGGGCCCAAATCCATGTTTGTATTCTTGGCTCGCAACAAAAGCAAAAGAAATTCACAGTTGGGTTGAATTAATAAATGGATAGAGTTTGGTGACTCCAATTATAGGGAAACAAAAAGGAACGAGCTTTTGTTTTGAATTTGAATGATTCCCCCATCTAATTATACGTTAAAAATATAAAATATTAGTACTTGATGGGGGAAAAGCTTTTCCCATGAATGGATTATTGATTTTTGTTATGAATCCTAACTATTAGCTATTCTCCATTATAATTAGATTATGGGGTGGCGATAAATGTGTAGAAGAAAGAGTATATTGATAAAGATCTTTTTTTTTTTTCCAAAATCAAAAGAGCGATTGGGTTGAGAAAATAAAGGATTTCTAACTATCTTGTTATCCTAGAACGAACATAAAACAATTAGATGGAAAAAGCGAGTAGAGAGAGTCCGTTGATGAGTCTTACTTGTTTTCTAGGTATCTTTTTTTAGAATAGAATACCCTGTTTTGACTGTATCGCACTATGTATTATTTGATAACCCAATAAATCTTCGATCCTCGGCCCAAATCAAATTTCAAAAAATGGAGGAATTTCAAGTATATTTAGAACTAGATAGATCTCGTCAACATGACTTCCTATACCCACTTATTTTTCGGGAGTATATTTTTGCACTTGCTTACGATCATGGTTTAAATAGTTCCATTTTGGTGCAAGATCTAGGTTATGACAATAAATCTAGTTTACTAATTGTAAAACGTTTAATTACTCGAATGTATCACCAGAATCATTTGATTATTTCTGCTAATAATTCTAACAAAAATCCATTTTGGGGGTACAACAAGAATTTGTATTCTCAAATAATATCAGAGGGGCTTGCCGTCAGTGTGGAAATTCCATTTTCCCTACAACTAATCTCTTCCTTAGAGAAGGCAGAAATTATAAAATCCTATAATTTACGATCAATTCATTCAATATTTCCTTTTTTTGAGGAAAAATTTCCATATTTAAATTATGTGTCAGATGTACAAATACCCTACCCTATACATCTGGAAATCTTGATTCAAACCCTTCGATACTGGGTGAAAGATGCCTCCTCCTTTCATTTATTAAGGCTCTTTCTTTATGAGTATTGTAATTGGAATAGTCTTATTACTCCAAAAAAAAGGATTTCTACTTTTTCAAAAAGTAATCCAAGATTTTTCCTGTTCCTATATAATTTTTATGTAGGTGAATACGAATCCATCTTTCTTTTTCTCCGTAACAAATCTTCTTATTTACGATTAACATCTTCTGGAGTCTTTTTTGAACGAATCTATTTCTATGCAAAAATAAAACATTTTGTAGAAGTCTTTGATAAGGATTTTCCGTCCACCCTATGGTTCTTCAAGGACCCTTTCATTCATTATGTTAGATATCAAGGAAAATCCATTCTAGCTTCAAAGAATACGCCCTTTTTGATGAAAAAATGGAAATACTATCTTATCCATTTATGGCAATGTCATTTTTTTGTTTGGTCTCAACCAGGAAAGATCCATATAAACCAATTATCCGAGCATTCATTTTCCTTTTTGGGTTATTTTTCAAATGTGCGGCTAAATCCTTCAGTGGTACGGAGTCAAATGTTGGAAAAGTCATTTATAATGGAAAATCTTATGAAAAAGCTTGATACAATAATTCCAATTATTCCTCTAATTAGATCATTGGCTAAAGCAAATTTTTGTAATGTATTAGGACATCCCATTAGTAAGCCGGTCTGGGCCGATTCATCCGATTTTGATATTATTGAGCGATTTTTGCAGATATGCAGAGATCTCTCTCATTATTACAACGGATCCTCAAAAAAAAAGAGTTTGTATCGAATCAAAAAAAACTTCGGGCTTNNTGGATNAAAACTTTGGNGGGTAACNCCAAAAGTCCNNNCGGGTTTTTTAAAAAANTAGGTTTTNAANTANTGGAANAATTNTTTCANAGGAAAAAAANATTTTTTTTTTNATTTTTTCNANAGNTTTTTTTNCTTTGCNNAAGNTANAAAAAGGCGGNTTTGGGANTTTGAAANTTTTGANTTTCNNCNANGATNTGGGCCATCATGAAAAACNGGNTATCNNACNTTGANAANGGGAACNANCCNTNAATNNGGGAAAGATNAAAAAAAAAAGAATTCATTCGTTTCTATTATGAAATTTCTATTATGAAATATGAAATGGATTATGAAATGCTCATGTAGTAAGAGTAGGAATTGATAAACTAAGNACTTAACTTTTTTAGAGTCCNGTTCTAGGGAAGGAACTGAGGTTTAGATGTATACATAGGGAAAGCCGTGTGCAATGAAAAATGCAAGTACGGCCTGGGGAGGNNTTTTTTT"}% HERE - "$this->{test_web}/LLB/Analyses/Sequences.00002" => <<"HERE", + "$test_web/LLB/Analyses/Sequences.00002" => <<"HERE", %META:TOPICINFO{author="BaseUserMapping_333" date="1313039642" format="1.1" version="1"}% %META:TOPICPARENT{name="All"}% %META:FORM{name="Profile/Definitions.Acacia_Sequence_Form"}% -%META:FIELD{name="Acacia_TraceSet" title="TraceSet" type="llb+input" value="$this->{test_web}/LLB/Results/TraceSets.00002"}% +%META:FIELD{name="Acacia_TraceSet" title="TraceSet" type="llb+input" value="$test_web/LLB/Results/TraceSets.00002"}% %META:FIELD{name="Acacia_WorkState" title="Editing" type="list+one" value="done"}% %META:FIELD{name="Acacia_Complete" title="Complete" type="boolean" value="1"}% %META:FIELD{name="Acacia_DateCompleted" title="Date completed" type="date" value=""}% @@ -6654,49 +6640,49 @@ HERE %META:FIELD{name="Acacia_SequenceNotes" title="Notes" type="richtext" value=""}% %META:FIELD{name="Acacia_Sequence" title="Sequence" type="llb+sequence" value="AAAATCTTGGTCTTAATGTATACGAGTTTTTGAACGTAAAGGAGCAATAATTAATTTATTGTTCTATCAAGAGGGTTAATATTGCTCCTTTACTTTTTAGTAGTTTCATACATCAATTTTGTATTTACTTCAACATTCTTTACCGTTGTTTTAAGATAAGAAAAAAATATTGGAGTTTCATACTTTTTGTTTCTTTTTTACTAATTTATTTTATACGTTTTTTTCAGCAATCTTTCTTTATCTTTTGAAATGAAAAAAAAAAACAAAAGAAAGAATACAAATATCTCTGTAATTTTTAGATGGTTTTTAGATGGTATAGG"}% HERE - "$this->{test_web}/LLB/Results/TraceSets.00001" => <<"HERE", + "$test_web/LLB/Results/TraceSets.00001" => <<"HERE", %META:TOPICINFO{author="BaseUserMapping_333" date="1313040485" format="1.1" version="1"}% %META:TOPICPARENT{name="All"}% %META:FORM{name="Profile/Definitions.Acacia_TraceSet_Form"}% -%META:FIELD{name="Acacia_PCRProduct" title="PCR Product" type="llb+input" value="$this->{test_web}/LLB/Samples/PCRs.00001"}% +%META:FIELD{name="Acacia_PCRProduct" title="PCR Product" type="llb+input" value="$test_web/LLB/Samples/PCRs.00001"}% HERE - "$this->{test_web}/LLB/Results/TraceSets.00002" => <<"HERE", + "$test_web/LLB/Results/TraceSets.00002" => <<"HERE", %META:TOPICINFO{author="BaseUserMapping_333" date="1313040748" format="1.1" version="1"}% %META:TOPICPARENT{name="All"}% %META:FORM{name="Profile/Definitions.Acacia_TraceSet_Form"}% -%META:FIELD{name="Acacia_PCRProduct" title="PCR Product" type="llb+input" value="$this->{test_web}/LLB/Samples/PCRs.00002"}% +%META:FIELD{name="Acacia_PCRProduct" title="PCR Product" type="llb+input" value="$test_web/LLB/Samples/PCRs.00002"}% HERE - "$this->{test_web}/LLB/Samples/PCRs.00001" => <<"HERE", + "$test_web/LLB/Samples/PCRs.00001" => <<"HERE", %META:TOPICINFO{author="BaseUserMapping_333" date="1313038798" format="1.1" version="1"}% %META:TOPICPARENT{name="All"}% %META:FORM{name="Profile/Definitions.Acacia_SamplePCR_Form"}% -%META:FIELD{name="Acacia_Extract" title="Extract" type="llb+input" value="$this->{test_web}/LLB/Samples/Extracts.0000"}% -%META:FIELD{name="Acacia_Gene" title="Gene" type="fwaddress" value="$this->{test_web}/LLB/Genes.MatK"}% +%META:FIELD{name="Acacia_Extract" title="Extract" type="llb+input" value="$test_web/LLB/Samples/Extracts.0000"}% +%META:FIELD{name="Acacia_Gene" title="Gene" type="fwaddress" value="$test_web/LLB/Genes.MatK"}% %META:FIELD{name="Acacia_WorkState" title="PCR Done" type="list+one" value="working"}% %META:FIELD{name="Acacia_Cleaned" title="PCR Cleaned" type="boolean" value="1"}% %META:FIELD{name="Acacia_FreezerLocation" title="Freezer Location" type="text" value=""}% HERE - "$this->{test_web}/LLB/Samples/PCRs.00002" => <<"HERE", + "$test_web/LLB/Samples/PCRs.00002" => <<"HERE", %META:TOPICINFO{author="BaseUserMapping_333" date="1313038798" format="1.1" version="1"}% %META:TOPICPARENT{name="All"}% %META:FORM{name="Profile/Definitions.Acacia_SamplePCR_Form"}% -%META:FIELD{name="Acacia_Extract" title="Extract" type="llb+input" value="$this->{test_web}/LLB/Samples/Extracts.0000"}% -%META:FIELD{name="Acacia_Gene" title="Gene" type="fwaddress" value="$this->{test_web}/LLB/Genes.PsbA"}% +%META:FIELD{name="Acacia_Extract" title="Extract" type="llb+input" value="$test_web/LLB/Samples/Extracts.0000"}% +%META:FIELD{name="Acacia_Gene" title="Gene" type="fwaddress" value="$test_web/LLB/Genes.PsbA"}% %META:FIELD{name="Acacia_WorkState" title="PCR Done" type="list+one" value="done"}% %META:FIELD{name="Acacia_Cleaned" title="PCR Cleaned" type="boolean" value="0"}% %META:FIELD{name="Acacia_FreezerLocation" title="Freezer Location" type="text" value=""}% HERE - "$this->{test_web}/LLB/Samples/Extracts.0000" => <<"HERE", + "$test_web/LLB/Samples/Extracts.0000" => <<"HERE", %META:TOPICINFO{author="BaseUserMapping_333" date="1313038766" format="1.1" version="1"}% %META:TOPICPARENT{name="All"}% %META:FORM{name="Profile/Definitions.Acacia_Extract_Form"}% -%META:FIELD{name="Acacia_Specimen" title="Specimen" type="llb+input" value="$this->{test_web}/LLB/Materials/Specimens.0120"}% -%META:FIELD{name="Acacia_ExtractMethod" title="Extraction method" type="text" value="$this->{test_web}/LLB/Methods.10"}% +%META:FIELD{name="Acacia_Specimen" title="Specimen" type="llb+input" value="$test_web/LLB/Materials/Specimens.0120"}% +%META:FIELD{name="Acacia_ExtractMethod" title="Extraction method" type="text" value="$test_web/LLB/Methods.10"}% %META:FIELD{name="Acacia_TissueType" title="Tissue type" type="list+one" value=""}% %META:FIELD{name="Acacia_DNAQuality" title="DNA quality" type="list+one" value="Wig L Bug"}% %META:FIELD{name="Acacia_DNAQuality" title="Picture" type="label" value=""}% @@ -6706,13 +6692,13 @@ HERE %META:FIELD{name="Acacia_DNANotes" title="DNA Notes" type="text" value=""}% %META:FIELD{name="Acacia_FreezerLocation" title="Freezer Location" type="text" value=""}% HERE - "$this->{test_web}/LLB/Samples/Extracts.0001" => <<"HERE" + "$test_web/LLB/Samples/Extracts.0001" => <<"HERE" %META:TOPICINFO{author="BaseUserMapping_333" date="1313038766" format="1.1" version="1"}% %META:TOPICPARENT{name="All"}% %META:FORM{name="Profile/Definitions.Acacia_Extract_Form"}% -%META:FIELD{name="Acacia_Specimen" title="Specimen" type="llb+input" value="$this->{test_web}/LLB/Materials/Specimens.1220"}% -%META:FIELD{name="Acacia_ExtractMethod" title="Extraction method" type="text" value="$this->{test_web}/LLB/Methods.03"}% +%META:FIELD{name="Acacia_Specimen" title="Specimen" type="llb+input" value="$test_web/LLB/Materials/Specimens.1220"}% +%META:FIELD{name="Acacia_ExtractMethod" title="Extraction method" type="text" value="$test_web/LLB/Methods.03"}% %META:FIELD{name="Acacia_TissueType" title="Tissue type" type="list+one" value=""}% %META:FIELD{name="Acacia_DNAQuality" title="DNA quality" type="list+one" value=""}% %META:FIELD{name="Acacia_DNAQuality" title="Picture" type="label" value=""}% @@ -6724,35 +6710,34 @@ HERE HERE ); my %tests = ( - "Acacia_Specimen='$this->{test_web}/LLB/Materials/Specimens.1220'" => - "$this->{test_web}/LLB/Samples/Extracts.0001", - "Acacia_Extract/Acacia_ExtractMethod='$this->{test_web}/LLB/Methods.10'" - => "$this->{test_web}/LLB/Samples/PCRs.00001, $this->{test_web}/LLB/Samples/PCRs.00002", - "Acacia_ExtractMethod='$this->{test_web}/LLB/Methods.03'" => - "$this->{test_web}/LLB/Samples/Extracts.0001", - "Acacia_Extract/Acacia_ExtractMethod='$this->{test_web}/LLB/Methods.03'" - => '', - "Acacia_PCRProduct='$this->{test_web}/LLB/Samples/PCRs.00002'" => - "$this->{test_web}/LLB/Results/TraceSets.00002", -"Acacia_PCRProduct/Acacia_Extract/Acacia_ExtractMethod='$this->{test_web}/LLB/Methods.10'" - => "$this->{test_web}/LLB/Results/TraceSets.00001, $this->{test_web}/LLB/Results/TraceSets.00002", -"Acacia_TraceSet/Acacia_PCRProduct/Acacia_Extract/Acacia_ExtractMethod='$this->{test_web}/LLB/Methods.10'" - => "$this->{test_web}/LLB/Analyses/Sequences.00001, $this->{test_web}/LLB/Analyses/Sequences.00002", + "Acacia_Specimen='$test_web/LLB/Materials/Specimens.1220'" => + "$test_web/LLB/Samples/Extracts.0001", + "Acacia_Extract/Acacia_ExtractMethod='$test_web/LLB/Methods.10'" => + "$test_web/LLB/Samples/PCRs.00001, $test_web/LLB/Samples/PCRs.00002", + "Acacia_ExtractMethod='$test_web/LLB/Methods.03'" => + "$test_web/LLB/Samples/Extracts.0001", + "Acacia_Extract/Acacia_ExtractMethod='$test_web/LLB/Methods.03'" => '', + "Acacia_PCRProduct='$test_web/LLB/Samples/PCRs.00002'" => + "$test_web/LLB/Results/TraceSets.00002", +"Acacia_PCRProduct/Acacia_Extract/Acacia_ExtractMethod='$test_web/LLB/Methods.10'" + => "$test_web/LLB/Results/TraceSets.00001, $test_web/LLB/Results/TraceSets.00002", +"Acacia_TraceSet/Acacia_PCRProduct/Acacia_Extract/Acacia_ExtractMethod='$test_web/LLB/Methods.10'" + => "$test_web/LLB/Analyses/Sequences.00001, $test_web/LLB/Analyses/Sequences.00002", "Acacia_TraceSet/Acacia_PCRProduct/Acacia_WorkState='done'" => - "$this->{test_web}/LLB/Analyses/Sequences.00002", + "$test_web/LLB/Analyses/Sequences.00002", "Acacia_TraceSet/Acacia_PCRProduct/Acacia_Cleaned" => - "$this->{test_web}/LLB/Analyses/Sequences.00001", + "$test_web/LLB/Analyses/Sequences.00001", "form.name='Profile/Definitions.Acacia_Sequence_Form' AND Acacia_TraceSet/Acacia_PCRProduct/Acacia_Extract/Acacia_LaneNumber > 5" - => "$this->{test_web}/LLB/Analyses/Sequences.00001, $this->{test_web}/LLB/Analyses/Sequences.00002", + => "$test_web/LLB/Analyses/Sequences.00001, $test_web/LLB/Analyses/Sequences.00002", "form.name='Profile/Definitions.Acacia_Sequence_Form' AND Acacia_TraceSet/Acacia_PCRProduct/Acacia_Extract/Acacia_LaneNumber < 5" => '' ); my $query = Unit::Request->new(''); - $query->path_info("/$this->{test_web}/$this->{test_topic}"); + $query->path_info( "/$test_web/" . $this->test_topic ); $this->createNewFoswikiSession( $Foswiki::cfg{AdminUserLogin}, $query ); - $this->assert_str_equals( $this->{test_web}, $this->{session}->{webName} ); + $this->assert_str_equals( $this->test_web, $this->session->webName ); while ( my ( $fwaddress, $metatext ) = each %topics ) { my ( $web, $topic ) = Foswiki::Func::normalizeWebTopicName( '', $fwaddress ); @@ -6777,8 +6762,7 @@ HERE $topicObj->finish(); } while ( my ( $querysearch, $expected ) = each %tests ) { - my $result = - $this->_test_query( $querysearch, "$this->{test_web}/LLB" ); + my $result = $this->_test_query( $querysearch, "$test_web/LLB" ); $this->assert_str_equals( $expected, $result, "Testing: '$querysearch'\nExpected:'$expected'\nBut got: '$result'" ); @@ -6790,7 +6774,7 @@ HERE sub _test_query { my ( $this, $query, $web ) = @_; - my $result = $this->{test_topicObject}->expandMacros(<<"HERE"); + my $result = $this->test_topicObject->expandMacros(<<"HERE"); %SEARCH{ "$query" type="query" @@ -6821,7 +6805,7 @@ sub test_pager_details_Item10350_one { pager="on" }% HERE - my $result = $this->{test_topicObject}->expandMacros($search); + my $result = $this->test_topicObject->expandMacros($search); # Should get the default search order (or an error message, perhaps?) $this->assert_str_equals( <<'THERE', $result ); @@ -6852,7 +6836,7 @@ sub test_pager_details_Item10350_two { pager="on" }% HERE - my $result = $this->{test_topicObject}->expandMacros($search); + my $result = $this->test_topicObject->expandMacros($search); # Should get the default search order (or an error message, perhaps?) $this->assert_str_equals( <<'THERE', $result ); @@ -6878,7 +6862,7 @@ sub verify_search_for_star { web="TestCases" }% HERE - my $result = $this->{test_topicObject}->expandMacros($search); + my $result = $this->test_topicObject->expandMacros($search); # Should get the default search order (or an error message, perhaps?) $this->assert( 0, $result ) @@ -6901,7 +6885,7 @@ sub verify_decode_options { web="TestCases" }% HERE - my $result = $this->{test_topicObject}->expandMacros($search); + my $result = $this->test_topicObject->expandMacros($search); # Should get the default search order (or an error message, perhaps?) $this->assert( 0, $result ) @@ -6918,7 +6902,7 @@ HERE web="TestCases" }% HERE - $result = $this->{test_topicObject}->expandMacros($search); + $result = $this->test_topicObject->expandMacros($search); # Should get the default search order (or an error message, perhaps?) $this->assert( 0, $result ) @@ -6936,7 +6920,7 @@ HERE web="TestCases" }% HERE - $result = $this->{test_topicObject}->expandMacros($search); + $result = $this->test_topicObject->expandMacros($search); # Should get the default search order (or an error message, perhaps?) $this->assert( 0, $result ) @@ -6953,7 +6937,7 @@ HERE web="TestCases" }% HERE - $result = $this->{test_topicObject}->expandMacros($search); + $result = $this->test_topicObject->expandMacros($search); # Should get the default search order (or an error message, perhaps?) $this->assert( 0, $result ) diff --git a/UnitTestContrib/test/unit/Iterator.pm b/UnitTestContrib/test/unit/Iterator.pm index db5fdf2c02..d47177fcc7 100644 --- a/UnitTestContrib/test/unit/Iterator.pm +++ b/UnitTestContrib/test/unit/Iterator.pm @@ -3,21 +3,17 @@ use strict; # tests for the Foswiki Iterators package Iterator; - -use FoswikiTestCase; -our @ISA = qw( FoswikiTestCase ); +use v5.14; use Foswiki::ListIterator; use Foswiki::AggregateIterator; use Foswiki::Iterator::NumberRangeIterator; -use Error qw( :try ); +use Try::Tiny; -sub new { - my $class = shift; - my $this = $class->SUPER::new(@_); - return $this; -} +use Moo; +use namespace::clean; +extends qw( FoswikiTestCase ); #use the eg in the code. sub test_ListIterator { @@ -25,10 +21,10 @@ sub test_ListIterator { my @list = ( 1, 2, 3 ); - my $it = new Foswiki::ListIterator( \@list ); - $this->assert( $it->isa('Foswiki::Iterator') ); - $it->{filter} = sub { return $_[0] != 2 }; - $it->{process} = sub { return $_[0] + 1 }; + my $it = new Foswiki::ListIterator( list => \@list ); + $this->assert( $it->does('Foswiki::Iterator') ); + $it->filter( sub { return $_[0] != 2 } ); + $it->process( sub { return $_[0] + 1 } ); my $b = ''; while ( $it->hasNext() ) { my $x = $it->next(); @@ -43,8 +39,8 @@ sub test_ListIteratorSimple { my @list = ( 1, 2, 3 ); - my $it = new Foswiki::ListIterator( \@list ); - my $b = ''; + my $it = new Foswiki::ListIterator( list => \@list ); + my $b = ''; while ( $it->hasNext() ) { my $x = $it->next(); $b .= "$x, "; @@ -58,8 +54,8 @@ sub test_ListIteratorWithUndef { my @list = ( 1, 2, undef, 3 ); - my $it = new Foswiki::ListIterator( \@list ); - my $b = ''; + my $it = new Foswiki::ListIterator( list => \@list ); + my $b = ''; while ( $it->hasNext() ) { my $x = $it->next(); $b .= "$x, "; @@ -103,18 +99,18 @@ sub test_AggregateIterator { my $this = shift; my @list1 = ( 1, 2, 3 ); - my $it1 = new Foswiki::ListIterator( \@list1 ); - $it1->{filter} = sub { return $_[0] != 2 }; - $it1->{process} = sub { return $_[0] + 1 }; + my $it1 = new Foswiki::ListIterator( list => \@list1 ); + $it1->filter( sub { return $_[0] != 2 } ); + $it1->process( sub { return $_[0] + 1 } ); my @list2 = ( 1, 2, 3 ); - my $it2 = new Foswiki::ListIterator( \@list2 ); - $it2->{filter} = sub { return $_[0] != 2 }; - $it2->{process} = sub { return $_[0] + 1 }; + my $it2 = new Foswiki::ListIterator( list => \@list2 ); + $it2->filter( sub { return $_[0] != 2 } ); + $it2->process( sub { return $_[0] + 1 } ); my @itrList = ( $it1, $it2 ); - my $it = new Foswiki::AggregateIterator( \@itrList ); - $this->assert( $it->isa('Foswiki::Iterator') ); + my $it = new Foswiki::AggregateIterator( iterators => \@itrList ); + $this->assert( $it->does('Foswiki::Iterator') ); my $b = ''; while ( $it->hasNext() ) { @@ -129,17 +125,20 @@ sub test_AggregateIteratorUnique { my $this = shift; my @list1 = ( 1, 2, 3 ); - my $it1 = new Foswiki::ListIterator( \@list1 ); - $it1->{filter} = sub { return $_[0] != 2 }; - $it1->{process} = sub { return $_[0] + 1 }; + my $it1 = new Foswiki::ListIterator( list => \@list1 ); + $it1->filter( sub { return $_[0] != 2 } ); + $it1->process( sub { return $_[0] + 1 } ); my @list2 = ( 1, 2, 3 ); - my $it2 = new Foswiki::ListIterator( \@list2 ); - $it2->{filter} = sub { return $_[0] != 2 }; - $it2->{process} = sub { return $_[0] + 1 }; + my $it2 = new Foswiki::ListIterator( list => \@list2 ); + $it2->filter( sub { return $_[0] != 2 } ); + $it2->process( sub { return $_[0] + 1 } ); my @itrList = ( $it1, $it2 ); - my $it = new Foswiki::AggregateIterator( \@itrList, 1 ); + my $it = new Foswiki::AggregateIterator( + iterators => \@itrList, + uniqueOnly => 1, + ); my $b = ''; while ( $it->hasNext() ) { @@ -154,15 +153,15 @@ sub test_AggregateIteratorOwnFilter { my $this = shift; my @list1 = ( 1, 2, 3 ); - my $it1 = new Foswiki::ListIterator( \@list1 ); + my $it1 = new Foswiki::ListIterator( list => \@list1 ); my @list2 = ( 1, 2, 3 ); - my $it2 = new Foswiki::ListIterator( \@list2 ); + my $it2 = new Foswiki::ListIterator( list => \@list2 ); my @itrList = ( $it1, $it2 ); - my $it = new Foswiki::AggregateIterator( \@itrList ); - $it->{filter} = sub { return $_[0] != 2 }; - $it->{process} = sub { return $_[0] + 1 }; + my $it = new Foswiki::AggregateIterator( iterators => \@itrList ); + $it->filter( sub { return $_[0] != 2 } ); + $it->process( sub { return $_[0] + 1 } ); my $b = ''; while ( $it->hasNext() ) { @@ -177,13 +176,13 @@ sub test_AggregateIteratorOrder { my $this = shift; my @list1 = ( 1, 2, 3 ); - my $it1 = new Foswiki::ListIterator( \@list1 ); + my $it1 = new Foswiki::ListIterator( list => \@list1 ); my @list2 = qw/a b c d/; - my $it2 = new Foswiki::ListIterator( \@list2 ); + my $it2 = new Foswiki::ListIterator( list => \@list2 ); my @itrList = ( $it1, $it2 ); - my $it = new Foswiki::AggregateIterator( \@itrList ); + my $it = new Foswiki::AggregateIterator( iterators => \@itrList ); my $b = ''; while ( $it->hasNext() ) { @@ -198,15 +197,15 @@ sub test_AggregateIteratorBad { my $this = shift; my @list1 = ( 1, 2, 3 ); - my $it1 = new Foswiki::ListIterator( \@list1 ); + my $it1 = new Foswiki::ListIterator( list => \@list1 ); my @list2 = qw/a b c d/; - my $it2 = new Foswiki::ListIterator( \@list2 ); + my $it2 = new Foswiki::ListIterator( list => \@list2 ); my $it3 = new Foswiki::ListIterator(); my @itrList = ( $it1, $it2, $it3 ); - my $it = new Foswiki::AggregateIterator( \@itrList ); + my $it = new Foswiki::AggregateIterator( iterators => \@itrList ); my $b = ''; while ( $it->hasNext() ) { @@ -221,20 +220,24 @@ sub test_AggregateIteratorNestedUnique { my $this = shift; my @list1 = ( 1, 2, 3 ); - my $it1 = new Foswiki::ListIterator( \@list1 ); + my $it1 = new Foswiki::ListIterator( list => \@list1 ); my @list2 = qw/a b c d/; - my $it2 = new Foswiki::ListIterator( \@list2 ); + my $it2 = new Foswiki::ListIterator( list => \@list2 ); my @listA = qw/p l k/; - my $itA = new Foswiki::ListIterator( \@listA ); + my $itA = new Foswiki::ListIterator( list => \@listA ); my @listB = qw/y 2 b l/; - my $itB = new Foswiki::ListIterator( \@listB ); + my $itB = new Foswiki::ListIterator( list => \@listB ); my @NestedItrList = ( $itA, $itB ); - my $it3 = new Foswiki::AggregateIterator( \@NestedItrList, 1 ); + my $it3 = new Foswiki::AggregateIterator( + iterators => \@NestedItrList, + uniqueOnly => 1 + ); my @itrList = ( $it1, $it2, $it3 ); - my $it = new Foswiki::AggregateIterator( \@itrList, 1 ); + my $it = + new Foswiki::AggregateIterator( iterators => \@itrList, uniqueOnly => 1 ); my $b = ''; while ( $it->hasNext() ) { @@ -249,20 +252,21 @@ sub test_AggregateIteratorNestedUnique2 { my $this = shift; my @list1 = ( 1, 2, 3 ); - my $it1 = new Foswiki::ListIterator( \@list1 ); + my $it1 = new Foswiki::ListIterator( list => \@list1 ); my @list2 = qw/a b c d/; - my $it2 = new Foswiki::ListIterator( \@list2 ); + my $it2 = new Foswiki::ListIterator( list => \@list2 ); my @listA = qw/p l k/; - my $itA = new Foswiki::ListIterator( \@listA ); + my $itA = new Foswiki::ListIterator( list => \@listA ); my @listB = qw/y 2 b l/; - my $itB = new Foswiki::ListIterator( \@listB ); + my $itB = new Foswiki::ListIterator( list => \@listB ); my @NestedItrList = ( $itA, $itB ); - my $it3 = new Foswiki::AggregateIterator( \@NestedItrList ); + my $it3 = new Foswiki::AggregateIterator( iterators => \@NestedItrList ); my @itrList = ( $it1, $it2, $it3 ); - my $it = new Foswiki::AggregateIterator( \@itrList, 1 ); + my $it = + new Foswiki::AggregateIterator( iterators => \@itrList, uniqueOnly => 1 ); my $b = ''; while ( $it->hasNext() ) { @@ -277,20 +281,20 @@ sub test_AggregateIteratorNested { my $this = shift; my @list1 = ( 1, 2, 3 ); - my $it1 = new Foswiki::ListIterator( \@list1 ); + my $it1 = new Foswiki::ListIterator( list => \@list1 ); my @list2 = qw/a b c d/; - my $it2 = new Foswiki::ListIterator( \@list2 ); + my $it2 = new Foswiki::ListIterator( list => \@list2 ); my @listA = qw/p l k/; - my $itA = new Foswiki::ListIterator( \@listA ); + my $itA = new Foswiki::ListIterator( list => \@listA ); my @listB = qw/y 2 b l/; - my $itB = new Foswiki::ListIterator( \@listB ); + my $itB = new Foswiki::ListIterator( list => \@listB ); my @NestedItrList = ( $itA, $itB ); - my $it3 = new Foswiki::AggregateIterator( \@NestedItrList ); + my $it3 = new Foswiki::AggregateIterator( iterators => \@NestedItrList ); my @itrList = ( $it1, $it2, $it3 ); - my $it = new Foswiki::AggregateIterator( \@itrList ); + my $it = new Foswiki::AggregateIterator( iterators => \@itrList ); my $b = ''; while ( $it->hasNext() ) { @@ -304,34 +308,54 @@ sub test_AggregateIteratorNested { sub test_NumberRangeIterator { my $this = shift; - my $i = new Foswiki::Iterator::NumberRangeIterator( 0, 0, 1 ); + my $i = new Foswiki::Iterator::NumberRangeIterator( + start => 0, + end => 0, + inc => 1 + ); $this->assert( $i->hasNext() ); $this->assert_num_equals( 0, $i->next() ); $this->assert( !$i->hasNext() ); - $i = new Foswiki::Iterator::NumberRangeIterator( 0, 0, -1 ); + $i = new Foswiki::Iterator::NumberRangeIterator( + start => 0, + end => 0, + inc => -1 + ); $this->assert( $i->hasNext() ); $this->assert_num_equals( 0, $i->next() ); $this->assert( !$i->hasNext() ); - $i = new Foswiki::Iterator::NumberRangeIterator( 0, 0 ); + $i = new Foswiki::Iterator::NumberRangeIterator( start => 0, end => 0 ); $this->assert( $i->hasNext() ); $this->assert_num_equals( 0, $i->next() ); $this->assert( !$i->hasNext() ); - $i = new Foswiki::Iterator::NumberRangeIterator( 0, 1, 1 ); + $i = new Foswiki::Iterator::NumberRangeIterator( + start => 0, + end => 1, + inc => 1 + ); $this->assert( $i->hasNext() ); $this->assert_num_equals( 0, $i->next() ); $this->assert( $i->hasNext() ); $this->assert_num_equals( 1, $i->next() ); $this->assert( !$i->hasNext() ); - $i = new Foswiki::Iterator::NumberRangeIterator( 0, 3, 2 ); + $i = new Foswiki::Iterator::NumberRangeIterator( + start => 0, + end => 3, + inc => 2 + ); $this->assert( $i->hasNext() ); $this->assert_num_equals( 0, $i->next() ); $this->assert( $i->hasNext() ); $this->assert_num_equals( 2, $i->next() ); $this->assert( !$i->hasNext() ); - $i = new Foswiki::Iterator::NumberRangeIterator( 0, 4, 2 ); + $i = new Foswiki::Iterator::NumberRangeIterator( + start => 0, + end => 4, + inc => 2 + ); $this->assert( $i->hasNext() ); $this->assert_num_equals( 0, $i->next() ); $this->assert( $i->hasNext() ); @@ -340,35 +364,55 @@ sub test_NumberRangeIterator { $this->assert_num_equals( 4, $i->next() ); $this->assert( !$i->hasNext() ); - $i = new Foswiki::Iterator::NumberRangeIterator( 0, 1, -1 ); + $i = new Foswiki::Iterator::NumberRangeIterator( + start => 0, + end => 1, + inc => -1 + ); $this->assert( $i->hasNext() ); $this->assert_num_equals( 0, $i->next() ); $this->assert( $i->hasNext() ); $this->assert_num_equals( 1, $i->next() ); $this->assert( !$i->hasNext() ); - $i = new Foswiki::Iterator::NumberRangeIterator( 0, -1, -1 ); + $i = new Foswiki::Iterator::NumberRangeIterator( + start => 0, + end => -1, + inc => -1 + ); $this->assert( $i->hasNext() ); $this->assert_num_equals( 0, $i->next() ); $this->assert( $i->hasNext() ); $this->assert_num_equals( -1, $i->next() ); $this->assert( !$i->hasNext() ); - $i = new Foswiki::Iterator::NumberRangeIterator( 0, -1, 1 ); + $i = new Foswiki::Iterator::NumberRangeIterator( + start => 0, + end => -1, + inc => 1 + ); $this->assert( $i->hasNext() ); $this->assert_num_equals( 0, $i->next() ); $this->assert( $i->hasNext() ); $this->assert_num_equals( -1, $i->next() ); $this->assert( !$i->hasNext() ); - $i = new Foswiki::Iterator::NumberRangeIterator( 0, -3, -2 ); + $i = new Foswiki::Iterator::NumberRangeIterator( + start => 0, + end => -3, + inc => -2 + ); $this->assert( $i->hasNext() ); $this->assert_num_equals( 0, $i->next() ); $this->assert( $i->hasNext() ); $this->assert_num_equals( -2, $i->next() ); $this->assert( !$i->hasNext() ); - $i = new Foswiki::Iterator::NumberRangeIterator( 0, -4, 2 ); + $i = new Foswiki::Iterator::NumberRangeIterator( + start => 0, + end => -4, + inc => 2 + ); $this->assert( $i->hasNext() ); $this->assert_num_equals( 0, $i->next() ); $this->assert( $i->hasNext() ); @@ -377,7 +421,7 @@ sub test_NumberRangeIterator { $this->assert_num_equals( -4, $i->next() ); $this->assert( !$i->hasNext() ); - $i = new Foswiki::Iterator::NumberRangeIterator( -1, 1 ); + $i = new Foswiki::Iterator::NumberRangeIterator( start => -1, end => 1 ); $this->assert( $i->hasNext() ); $this->assert_num_equals( -1, $i->next() ); $this->assert( $i->hasNext() ); @@ -386,7 +430,7 @@ sub test_NumberRangeIterator { $this->assert_num_equals( 1, $i->next() ); $this->assert( !$i->hasNext() ); - $i = new Foswiki::Iterator::NumberRangeIterator( 1, -1 ); + $i = new Foswiki::Iterator::NumberRangeIterator( start => 1, end => -1 ); $this->assert( $i->hasNext() ); $this->assert_num_equals( 1, $i->next() ); $this->assert( $i->hasNext() ); @@ -413,8 +457,8 @@ sub test_ListIterator_falsies { { my @list = ( -1, 0, '', 'asd' ); - my $it = new Foswiki::ListIterator( \@list ); - $this->assert( $it->isa('Foswiki::Iterator') ); + my $it = new Foswiki::ListIterator( list => \@list ); + $this->assert( $it->does('Foswiki::Iterator') ); my $b = ''; while ( $it->hasNext() ) { my $x = $it->next(); @@ -426,8 +470,8 @@ sub test_ListIterator_falsies { { my @list = ( '', '+&', '@:{}', '!!', '' ); - my $it = new Foswiki::ListIterator( \@list ); - $this->assert( $it->isa('Foswiki::Iterator') ); + my $it = new Foswiki::ListIterator( list => \@list ); + $this->assert( $it->does('Foswiki::Iterator') ); my $b = ''; while ( $it->hasNext() ) { my $x = $it->next(); diff --git a/core/lib/Foswiki.pm b/core/lib/Foswiki.pm index d717f7a8a7..27ddc14d14 100644 --- a/core/lib/Foswiki.pm +++ b/core/lib/Foswiki.pm @@ -197,7 +197,7 @@ has logger => ( my $this = shift; my $logger; if ( $Foswiki::cfg{Log}{Implementation} ne 'none' ) { - eval "require $Foswiki::cfg{Log}{Implementation}"; + load_package( $Foswiki::cfg{Log}{Implementation} ); if ($@) { print STDERR "Logger load failed: $@"; } @@ -300,7 +300,7 @@ has search => ( predicate => 1, default => sub { require Foswiki::Search; - return Foswiki::Search->new( $_[0] ); + return Foswiki::Search->new( session => $_[0] ); }, ); has store => ( @@ -390,7 +390,7 @@ has users => ( lazy => 1, predicate => 1, clearer => 1, - default => sub { return Foswiki::Users->new( $_[0] ); }, + default => sub { return Foswiki::Users->new( session => $_[0] ); }, ); has webName => ( is => 'rw', @@ -2372,15 +2372,22 @@ See http://blog.fox.geek.nz/2010/11/searching-design-spec-for-ultimate.html for sub load_package { my $fullname = shift; + # SMELL Must use system-independant way of forming filepath. + my $filename = File::Spec->catfile( split /::/, $fullname ) . '.pm'; + + # Check if the module has been already loaded before. + return if exists $INC{$filename}; + # Is it already loaded? If so, it might be an internal class an missing # from @INC, so skip it. See perldoc UNIVERSAL for what this does. - return if eval { $fullname->isa($fullname) }; + # XXX vrurg This method is unreliable and sometimes detects a module which + # hasn't been loaded yet. Besides it depends on module name being 1-to-1 + # mapped into file name which is not always the case. Consider macros which + # are part of Foswiki namespace. + #return if eval { $fullname->isa($fullname) }; - # SMELL Must use system-independant way of forming filepath. - $fullname =~ s{::}{/}g; - $fullname .= '.pm'; local $SIG{__DIE__}; - require $fullname; + require $filename; } =begin TML @@ -3568,7 +3575,7 @@ sub _expandMacroOnTopicRendering { } elsif ( exists( $macros{$tag} ) ) { - # vrurg Macro could be either a reference to an object or a sub. Though + # vrurg Macro could either be a reference to an object or a sub. Though # generally OO is preferred but for plguins registering a handling sub # could be of more convenience for a while. unless ( defined( $macros{$tag} ) ) { @@ -3589,7 +3596,7 @@ sub _expandMacroOnTopicRendering { my $attrs = new Foswiki::Attrs( $args, $contextFreeSyntax{$tag} ); if ( ref( $macros{$tag} ) eq 'CODE' ) { - $e = &{ $macros{$tag} }( $this, $attrs, $topicObject ); + $e = $macros{$tag}->( $this, $attrs, $topicObject ); } else { # Create macro object unless it already exists. diff --git a/core/lib/Foswiki/AggregateIterator.pm b/core/lib/Foswiki/AggregateIterator.pm index 488a5ec89f..918a150ecb 100755 --- a/core/lib/Foswiki/AggregateIterator.pm +++ b/core/lib/Foswiki/AggregateIterator.pm @@ -10,11 +10,11 @@ Combine multiple iterators into a single iteration. =cut package Foswiki::AggregateIterator; -use strict; -use warnings; +use v5.14; -use Foswiki::Iterator (); -our @ISA = ('Foswiki::Iterator'); +use Moo; +extends qw(Foswiki::Object); +with qw(Foswiki::Iterator); BEGIN { if ( $Foswiki::cfg{UseLocale} ) { @@ -25,33 +25,34 @@ BEGIN { =begin TML ----++ new(\@list, $unique) +---++ new(iterators => \@list, uniqueOnly => $unique) Create a new iterator over the given list of iterators. The list is not damaged in any way. -If =$unique= is set, we try to not repeat values. -Warning: =$unique= assumes that the values are strings. +If =uniqueOnly= is true, we try to not repeat values. +Warning: =uniqueOnly= assumes that the values are strings. =cut -sub new { - my ( $class, $list, $unique ) = @_; - my $this = bless( - { - Itr_list => $list, - Itr_index => 0, - index => 0, - process => undef, - filter => undef, - next => undef, - unique => $unique, - unique_hash => {} - }, - $class - ); - return $this; -} +has _iterator => ( + is => 'rw', + lazy => 1, + clearer => 1, + predicate => 1, + isa => Foswiki::Object::isaCLASS( + 'list', 'Foswiki::Object', does => 'Foswiki::Iterator', + ), +); +has Itr_list => ( + is => 'rw', + required => 1, + init_arg => 'iterators', + isa => Foswiki::Object::isaARRAY('Itr_list'), +); +has Itr_index => ( is => 'rw', default => 0, ); +has uniqueOnly => ( is => 'rw', default => 0, ); +has unique_hash => ( is => 'rw', lazy => 1, default => sub { {} }, ); =begin TML @@ -63,35 +64,36 @@ Returns false when the iterator is exhausted. sub hasNext { my ($this) = @_; - return 1 if $this->{next}; + return 1 if $this->_next; my $n; do { - unless ( $this->{list} ) { - if ( $this->{Itr_index} < scalar( @{ $this->{Itr_list} } ) ) { - $this->{list} = $this->{Itr_list}->[ $this->{Itr_index}++ ]; + unless ( $this->_has_iterator ) { + if ( $this->Itr_index < scalar( @{ $this->Itr_list } ) ) { + $this->_iterator( $this->Itr_list->[ $this->Itr_index ] ); + $this->Itr_index( $this->Itr_index + 1 ); } else { return 0; #no more iterators in list } } - if ( $this->{list}->hasNext() ) { - $n = $this->{list}->next(); + if ( $this->_iterator->hasNext() ) { + $n = $this->_iterator->next(); } else { - $this->{list} = undef; #goto next iterator + $this->_clear_iterator; #goto next iterator } - } while ( !$this->{list} - || ( $this->{filter} && !&{ $this->{filter} }($n) ) - || ( $this->{unique} && !$this->unique($n) ) ); - $this->{next} = $n; + } while ( !$this->_has_iterator + || ( $this->filter && !&{ $this->filter }($n) ) + || ( $this->uniqueOnly && !$this->unique($n) ) ); + $this->_next($n); return 1; } sub unique { my ( $this, $value ) = @_; - unless ( defined( $this->{unique_hash}{$value} ) ) { - $this->{unique_hash}{$value} = 1; + unless ( defined( $this->unique_hash->{$value} ) ) { + $this->unique_hash->{$value} = 1; return 1; } @@ -119,14 +121,18 @@ iterator object: sub next { my $this = shift; $this->hasNext(); - my $n = $this->{next}; - $this->{next} = undef; - $n = &{ $this->{process} }($n) if $this->{process}; + my $n = $this->_next; + $this->_clear_next; + $n = &{ $this->process }($n) if $this->process; #print STDERR "next - $n \n"; return $n; } +sub reset { + my $this = shift; +} + 1; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/lib/Foswiki/If/OP_allows.pm b/core/lib/Foswiki/If/OP_allows.pm index c75ba634c0..2dc7fe7c07 100644 --- a/core/lib/Foswiki/If/OP_allows.pm +++ b/core/lib/Foswiki/If/OP_allows.pm @@ -39,8 +39,8 @@ sub evaluate { my $mode = $b->_evaluate(@_) || 'view'; my %domain = @_; my $session = $domain{tom}->session; - throw Error::Simple( - 'No context in which to evaluate "' . $a->stringify() . '"' ) + Foswiki::Exception->throw( + text => 'No context in which to evaluate "' . $a->stringify() . '"' ) unless $session; my $str = $a->evaluate(@_); diff --git a/core/lib/Foswiki/If/OP_context.pm b/core/lib/Foswiki/If/OP_context.pm index d027b4c0f2..561298b3d2 100644 --- a/core/lib/Foswiki/If/OP_context.pm +++ b/core/lib/Foswiki/If/OP_context.pm @@ -39,8 +39,8 @@ sub evaluate { my $text = $a->_evaluate(@_) || ''; my %domain = @_; my $session = $domain{tom}->session; - throw Error::Simple( - 'No context in which to evaluate "' . $a->stringify() . '"' ) + Foswiki::Exception->throw( + text => 'No context in which to evaluate "' . $a->stringify() . '"' ) unless $session; return $session->inContext($text) || 0; } diff --git a/core/lib/Foswiki/If/OP_defined.pm b/core/lib/Foswiki/If/OP_defined.pm index fe0f2c647b..d68687047d 100644 --- a/core/lib/Foswiki/If/OP_defined.pm +++ b/core/lib/Foswiki/If/OP_defined.pm @@ -33,8 +33,8 @@ sub evaluate { my $a = $node->params->[0]; my %domain = @_; my $session = $domain{tom}->session; - throw Error::Simple( - 'No context in which to evaluate "' . $a->stringify() . '"' ) + Foswiki::Exception->throw( + text => 'No context in which to evaluate "' . $a->stringify() . '"' ) unless $session; # NOTE: If::Node::_evaluate(), not Query::Node::evaluate diff --git a/core/lib/Foswiki/If/OP_dollar.pm b/core/lib/Foswiki/If/OP_dollar.pm index 277e42e9a7..3966b3ec38 100644 --- a/core/lib/Foswiki/If/OP_dollar.pm +++ b/core/lib/Foswiki/If/OP_dollar.pm @@ -37,8 +37,8 @@ sub evaluate { my $a = $node->params->[0]; my %domain = @_; my $session = $domain{tom}->session; - throw Error::Simple( - 'No context in which to evaluate "' . $a->stringify() . '"' ) + Foswiki::Exception->throw( + text => 'No context in which to evaluate "' . $a->stringify() . '"' ) unless $session; my $text = $a->_evaluate(@_) || ''; if ( $text && defined( $session->request->param($text) ) ) { diff --git a/core/lib/Foswiki/If/OP_ingroup.pm b/core/lib/Foswiki/If/OP_ingroup.pm index 78d33b2b48..272407351c 100644 --- a/core/lib/Foswiki/If/OP_ingroup.pm +++ b/core/lib/Foswiki/If/OP_ingroup.pm @@ -46,8 +46,8 @@ sub evaluate { my $b = $node->params->[1]; # group name (string my %domain = @_; my $session = $domain{tom}->session; - throw Error::Simple( - 'No context in which to evaluate "' . $a->stringify() . '"' ) + Foswiki::Exception->throw( + text => 'No context in which to evaluate "' . $a->stringify() . '"' ) unless $session; my $user = $session->users->getCanonicalUserID( $a->evaluate(@_) ); return 0 unless $user; diff --git a/core/lib/Foswiki/If/OP_istopic.pm b/core/lib/Foswiki/If/OP_istopic.pm index 010cb41625..e7672584f0 100644 --- a/core/lib/Foswiki/If/OP_istopic.pm +++ b/core/lib/Foswiki/If/OP_istopic.pm @@ -33,8 +33,8 @@ sub evaluate { my $a = $node->params->[0]; my %domain = @_; my $session = $domain{tom}->session; - throw Error::Simple( - 'No context in which to evaluate "' . $a->stringify() . '"' ) + Foswiki::Exception->throw( + text => 'No context in which to evaluate "' . $a->stringify() . '"' ) unless $session; my ( $web, $topic ) = ( $session->webName, $a->_evaluate(@_) ); diff --git a/core/lib/Foswiki/If/OP_isweb.pm b/core/lib/Foswiki/If/OP_isweb.pm index 077d26cd09..406c193a32 100644 --- a/core/lib/Foswiki/If/OP_isweb.pm +++ b/core/lib/Foswiki/If/OP_isweb.pm @@ -37,8 +37,8 @@ sub evaluate { my $a = $node->params->[0]; my %domain = @_; my $session = $domain{tom}->session; - throw Error::Simple( - 'No context in which to evaluate "' . $a->stringify() . '"' ) + Foswiki::Exception->throw( + text => 'No context in which to evaluate "' . $a->stringify() . '"' ) unless $session; my $web = $a->_evaluate(@_) || ''; return $session->webExists($web) ? 1 : 0; diff --git a/core/lib/Foswiki/Infix/Parser.pm b/core/lib/Foswiki/Infix/Parser.pm index b1c7197461..82f24ba56f 100644 --- a/core/lib/Foswiki/Infix/Parser.pm +++ b/core/lib/Foswiki/Infix/Parser.pm @@ -58,7 +58,7 @@ following two functions: * =newNode($op, @params)= - create a new operator node. @params is a variable-length list of parameters, left to right. $op is a reference to the operator hash in the \@opers list. -These functions should throw Error::Simple in the event of errors. +These functions should throw Foswiki::Exception in the event of errors. Foswiki::Infix::Node is such a class, ripe for subclassing. The remaining parameters are named, and specify options that affect the diff --git a/core/lib/Foswiki/Iterator.pm b/core/lib/Foswiki/Iterator.pm index 433a5db834..2f6b7f40bc 100644 --- a/core/lib/Foswiki/Iterator.pm +++ b/core/lib/Foswiki/Iterator.pm @@ -17,11 +17,12 @@ See Foswiki::ListIterator for an example implementation. =cut package Foswiki::Iterator; +use v5.14; -use strict; -use warnings; use Assert; +use Moo::Role; + #debug Iterators use constant MONITOR => 0; @@ -32,6 +33,26 @@ BEGIN { } } +has list => ( + is => 'rw', + lazy => 1, + clearer => 1, + predicate => 1, + default => sub { [] }, + isa => Foswiki::Object::isaARRAY('list'), +); +has index => ( + is => 'rw', + lazy => 1, + clearer => 1, + default => 0, +); +has process => ( is => 'rw', clearer => 1, ); +has filter => ( is => 'rw', clearer => 1, ); +has _next => ( is => 'rw', clearer => 1, ); + +requires qw(hasNext next reset); + =begin TML ---++ hasNext() -> $boolean @@ -41,30 +62,6 @@ is exhausted. =cut -sub hasNext { ASSERT('Pure virtual function called') if DEBUG; } - -=begin TML - ----++ next() -> $data - -Return the next data in the iteration. - -The data may be any type. - -The iterator object can be customised to pre- and post-process entries from -the list before returning them. This is done by setting two fields in the -iterator object: - - * ={filter}= can be defined to be a sub that filters each entry. The entry - will be ignored (next() will not return it) if the filter returns false. - * ={process}= can be defined to be a sub to process each entry before it - is returned by next. The value returned from next is the value returned - by the process function. - -=cut - -sub next { ASSERT('Pure virtual function called') if DEBUG; } - =begin TML ---++ reset() -> $boolean @@ -73,8 +70,6 @@ resets the iterator to the begining - returns false if it can't =cut -sub reset { ASSERT('Pure virtual function called') if DEBUG; } - =begin TML ---++ ObjectMethod all() -> @list diff --git a/core/lib/Foswiki/Iterator/AggregateEventIterator.pm b/core/lib/Foswiki/Iterator/AggregateEventIterator.pm index d346da986a..6eb5bfe0c4 100644 --- a/core/lib/Foswiki/Iterator/AggregateEventIterator.pm +++ b/core/lib/Foswiki/Iterator/AggregateEventIterator.pm @@ -1,8 +1,6 @@ # See bottom of file for license and copyright information package Foswiki::Iterator::AggregateEventIterator; - -use strict; -use warnings; +use v5.14; use Assert; BEGIN { @@ -20,26 +18,9 @@ Private subclass of Foswiki::AggregateIterator that implements the snoopNext met =cut # Private subclass of AggregateIterator that can snoop Events. -require Foswiki::AggregateIterator; -our @ISA = ('Foswiki::AggregateIterator'); - -sub new { - my ( $class, $list, $unique ) = @_; - my $this = bless( - { - Itr_list => $list, - Itr_index => 0, - index => 0, - process => undef, - filter => undef, - next => undef, - unique => $unique, - unique_hash => {} - }, - $class - ); - return $this; -} +use Moo; +use namespace::clean; +extends qw(Foswiki::AggregateIterator); =begin TML @@ -50,7 +31,7 @@ Return the field hash of the next availabable record. sub snoopNext { my $this = shift; - return $this->{list}->snoopNext(); + return $this->list->snoopNext(); } 1; diff --git a/core/lib/Foswiki/Iterator/EventIterator.pm b/core/lib/Foswiki/Iterator/EventIterator.pm index 49cfbdb882..424bf8add9 100644 --- a/core/lib/Foswiki/Iterator/EventIterator.pm +++ b/core/lib/Foswiki/Iterator/EventIterator.pm @@ -1,8 +1,6 @@ # See bottom of file for license and copyright information package Foswiki::Iterator::EventIterator; - -use strict; -use warnings; +use v5.14; use Assert; BEGIN { @@ -20,25 +18,19 @@ Private subclass of LineIterator that * reasembles divided records into a single log record * splits the log record into fields +---++ ClassMethod new( version => $api, threshold => $threshold, level => $reqLevel, [filename => $filename,]) + =cut -package Foswiki::Iterator::EventIterator; -require Foswiki::LineIterator; -our @ISA = ('Foswiki::LineIterator'); +use Moo; +extends qw(Foswiki::LineIterator); use constant TRACE => 0; -sub new { - my ( $class, $fh, $threshold, $level, $version, $filename ) = @_; - my $this = $class->SUPER::new($fh); - $this->{_api} = $version; - $this->{_threshold} = $threshold; - $this->{_reqLevel} = $level; - $this->{_filename} = $filename || 'n/a'; - - # print STDERR "EventIterator created for $this->{_filename} \n"; - return $this; -} +has _api => ( is => 'rw', init_arg => 'version', required => 1, ); +has _threshold => ( is => 'rw', init_arg => 'threshold', required => 1, ); +has _reqLevel => ( is => 'rw', init_arg => 'level', required => 1, ); +has _filename => ( is => 'rw', init_arg => 'filename', default => 'n/a', ); =begin TML @@ -51,10 +43,11 @@ Returns true if a cached record is available. =cut -sub hasNext { +around hasNext => sub { + my $orig = shift; my $this = shift; - return 1 if defined $this->{_nextEvent}; - while ( $this->SUPER::hasNext() ) { + return 1 if defined $this->_nextEvent; + while ( $orig->($this) ) { my $ln = $this->SUPER::next(); # Merge records until record ends in | @@ -66,26 +59,27 @@ sub hasNext { shift @line; # skip the leading empty cell next unless scalar(@line) && defined $line[0]; + my $reqLevel = $this->_reqLevel; if ( - $line[0] =~ s/\s+($this->{_reqLevel})\s*$// # test the level + $line[0] =~ s/\s+($reqLevel)\s*$// # test the level # accept a plain 'old' format date with no level only if reading info (statistics) || $line[0] =~ m/^\d{1,2} [a-z]{3} \d{4}/i - && $this->{_reqLevel} =~ m/info/ + && $this->_reqLevel =~ m/info/ ) { - $this->{_level} = $1 || 'info'; + $this->_level( $1 || 'info' ); $line[0] = Foswiki::Time::parseTime( $line[0] ); next unless ( defined $line[0] ); # Skip record if time doesn't decode. - if ( $line[0] >= $this->{_threshold} ) { # test the time - $this->{_nextEvent} = \@line; - $this->{_nextParsed} = $this->formatData(); + if ( $line[0] >= $this->_threshold ) { # test the time + $this->_nextEvent( \@line ); + $this->_nextParsed( $this->formatData() ); return 1; } } } return 0; -} +}; =begin TML @@ -98,9 +92,9 @@ which will read the file until it finds a matching record. sub snoopNext { my $this = shift; - return $this->{_nextParsed}; # if defined $this->{_nextParsed}; - #return undef unless $this->hasNext(); - #return $this->{_nextParsed}; + return $this->_nextParsed; # if defined $this->_nextParsed; + #return undef unless $this->hasNext(); + #return $this->_nextParsed; } =begin TML @@ -112,9 +106,9 @@ Returns a hash, or an array of the fields in the next available record depending sub next { my $this = shift; - undef $this->{_nextEvent}; - return $this->{_nextParsed}[0] if $this->{_api}; - return $this->{_nextParsed}[1]; + $this->_clear_nextEvent; + return $this->_nextParsed->[0] if $this->_api; + return $this->_nextParsed->[1]; } =begin TML @@ -128,12 +122,12 @@ interface, or the array returned for the original Version 0 interface. sub formatData { my $this = shift; - my $data = $this->{_nextEvent}; + my $data = $this->_nextEvent; my %fhash; # returned hash of identified fields - $fhash{level} = $this->{_level}; - $fhash{filename} = $this->{_filename} + $fhash{level} = $this->_level; + $fhash{filename} = $this->_filename if (TRACE); - if ( $this->{_level} eq 'info' ) { + if ( $this->_level eq 'info' ) { $fhash{epoch} = @$data[0]; $fhash{user} = @$data[1]; $fhash{action} = @$data[2]; @@ -141,11 +135,11 @@ sub formatData { $fhash{extra} = @$data[4]; $fhash{remoteAddr} = @$data[5]; } - elsif ( $this->{_level} =~ m/warning|error|critical|alert|emergency/ ) { + elsif ( $this->_level =~ m/warning|error|critical|alert|emergency/ ) { $fhash{epoch} = @$data[0]; $fhash{extra} = join( ' ', @$data[ 1 .. $#$data ] ); } - elsif ( $this->{_level} eq 'debug' ) { + elsif ( $this->_level eq 'debug' ) { $fhash{epoch} = @$data[0]; $fhash{extra} = join( ' ', @$data[ 1 .. $#$data ] ); } diff --git a/core/lib/Foswiki/Iterator/FilterIterator.pm b/core/lib/Foswiki/Iterator/FilterIterator.pm index 768ca9f276..c865ee9c65 100755 --- a/core/lib/Foswiki/Iterator/FilterIterator.pm +++ b/core/lib/Foswiki/Iterator/FilterIterator.pm @@ -9,13 +9,13 @@ Iterator that filters another iterator based on the results from a function. =cut package Foswiki::Iterator::FilterIterator; +use v5.14; -use strict; -use warnings; use Assert; -use Foswiki::Iterator (); -our @ISA = ('Foswiki::Iterator'); +use Moo; +extends qw(Foswiki::Object); +with qw(Foswiki::Iterator); BEGIN { if ( $Foswiki::cfg{UseLocale} ) { @@ -24,9 +24,20 @@ BEGIN { } } +has iterator => ( + is => 'rw', + required => 1, + weak_ref => 1, + isa => Foswiki::Object::isaCLASS( + 'iterator', 'Foswiki::Object', does => 'Foswiki::Iterator', + ), +); +has data => ( is => 'rw', required => 1, ); +has pending => ( is => 'rw', default => 0, ); + =begin TML ----++ ClassMethod new( $iter, $sub, $data ) +---++ ClassMethod new( iterator => $iter, filter => $sub, data => $data ) Construct a new iterator that will filter $iter based on the results from $sub. $sub should return 0 if the next() from $iter should be filtered and 1 if it should be treated as the next item in the sequence. @@ -35,43 +46,35 @@ $data is an optional arbitrary data item which will be passed to $sub in $_[1] =cut -sub new { - my ( $class, $iter, $sub, $data ) = @_; - ASSERT( UNIVERSAL::isa( $iter, 'Foswiki::Iterator' ) ) if DEBUG; - ASSERT( ref($sub) eq 'CODE' ) if DEBUG; - my $this = bless( {}, $class ); - $this->{iterator} = $iter; - $this->{filter} = $sub; - $this->{data} = $data; - $this->{next} = undef; - $this->{pending} = 0; - return $this; +sub BUILD { + my $this = shift; + ASSERT( ref( $this->filter ) eq 'CODE' ) if DEBUG; } #lie - give the unfiltered count for speed. sub numberOfTopics { my $this = shift; - return $this->{iterator}->numberOfTopics(); + return $this->iterator->numberOfTopics(); } sub nextWeb { my $this = shift; - $this->{iterator}->nextWeb(); + $this->iterator->nextWeb(); } sub sortResults { my $this = shift; - $this->{iterator}->sortResults(@_); + $this->iterator->sortResults(@_); } # See Foswiki::Iterator for a description of the general iterator contract sub hasNext { my $this = shift; - return 1 if $this->{pending}; - while ( $this->{iterator}->hasNext() ) { - $this->{next} = $this->{iterator}->next(); - if ( &{ $this->{filter} }( $this->{next}, $this->{data} ) ) { - $this->{pending} = 1; + return 1 if $this->pending; + while ( $this->iterator->hasNext() ) { + $this->_next( $this->iterator->next ); + if ( &{ $this->filter }( $this->_next, $this->data ) ) { + $this->pending(1); return 1; } } @@ -84,12 +87,12 @@ sub skip { my $count = shift; #ask CAN skip() for faster path - if ( $this->{iterator}->can('skip') ) { - $count = $this->{iterator}->skip($count); + if ( $this->iterator->can('skip') ) { + $count = $this->iterator->skip($count); - if ( $this->{iterator}->hasNext() ) { - $this->{next} = $this->{iterator}->next(); - $this->{pending} = 1; + if ( $this->iterator->hasNext() ) { + $this->_next( $this->iterator->next ); + $this->pending(1); $count--; } } @@ -99,12 +102,11 @@ sub skip { while ( ( $count > 0 ) #must come first - don't want to advance the inner itr if count ==0 - and $this->{iterator}->hasNext() + and $this->iterator->hasNext() ) { $count--; - $this->{next} = - $this->{iterator}->next() + $this->_next( $this->iterator->next ) ; #drain next, so hasNext goes to next element } } @@ -112,8 +114,8 @@ sub skip { if ( $count >= 0 ) { #skipped past the end of the set - $this->{next} = undef; - $this->{pending} = 0; + $this->_clear_next; + $this->pending(0); } print STDERR "--------------------------------------------FilterIterator::skip() => $count\n" @@ -126,17 +128,17 @@ sub skip { sub next { my $this = shift; return unless $this->hasNext(); - $this->{pending} = 0; - return $this->{next}; + $this->pending(0); + return $this->_next; } # See Foswiki::Iterator for a description of the general iterator contract sub reset { my ($this) = @_; - return unless ( $this->{iterator}->reset() ); - $this->{next} = undef; - $this->{pending} = 0; + return unless ( $this->iterator->reset() ); + $this->_clear_next; + $this->pending(0); return 1; } diff --git a/core/lib/Foswiki/Iterator/MergeEventIterator.pm b/core/lib/Foswiki/Iterator/MergeEventIterator.pm index af17c69534..7c81601825 100644 --- a/core/lib/Foswiki/Iterator/MergeEventIterator.pm +++ b/core/lib/Foswiki/Iterator/MergeEventIterator.pm @@ -1,8 +1,7 @@ # See bottom of file for license and copyright information package Foswiki::Iterator::MergeEventIterator; +use v5.14; -use strict; -use warnings; use Assert; BEGIN { @@ -23,22 +22,11 @@ Private subclass of Foswiki::Iterator that =cut -require Foswiki::Iterator; -our @ISA = ('Foswiki::Iterator'); - -sub new { - my ( $class, $list ) = @_; - my $this = bless( - { - Itr_list_ref => $list, - process => undef, - filter => undef, - next => undef, - }, - $class - ); - return $this; -} +use Moo; +extends qw(Foswiki::Object); +with qw(Foswiki::Iterator); + +has Itr_list_ref => ( is => 'rw', init_arg => 'list', required => 1 ); =begin TML @@ -50,7 +38,7 @@ Scans all the iterators to determine if any of them have a record available. sub hasNext { my $this = shift; - foreach my $It ( @{ $this->{Itr_list_ref} } ) { + foreach my $It ( @{ $this->Itr_list_ref } ) { return 1 if $It->hasNext(); } return 0; @@ -69,7 +57,7 @@ sub next { my $lowIt; my $lowest; - foreach my $It ( @{ $this->{Itr_list_ref} } ) { + foreach my $It ( @{ $this->Itr_list_ref } ) { next unless $It->hasNext(); my $nextRec = @{ $It->snoopNext() }[0]; my $epoch = $nextRec->{epoch}; @@ -82,6 +70,11 @@ sub next { return $lowIt->next(); } +sub reset { + + # Just a stub to conform Iterator requirements. +} + 1; __END__ Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/lib/Foswiki/Iterator/NumberRangeIterator.pm b/core/lib/Foswiki/Iterator/NumberRangeIterator.pm index 6cb0988633..0bae9c9f31 100644 --- a/core/lib/Foswiki/Iterator/NumberRangeIterator.pm +++ b/core/lib/Foswiki/Iterator/NumberRangeIterator.pm @@ -9,13 +9,14 @@ Iterator over a range of integer values, with programmable increment. =cut package Foswiki::Iterator::NumberRangeIterator; -use Foswiki::Iterator; -our @ISA = ('Foswiki::Iterator'); +use v5.14; -use strict; -use warnings; use Assert; +use Moo; +extends qw(Foswiki::Object); +with qw(Foswiki::Iterator); + BEGIN { if ( $Foswiki::cfg{UseLocale} ) { require locale; @@ -25,7 +26,7 @@ BEGIN { =begin TML ----++ ClassMethod new($start, $end, $inc) +---++ ClassMethod new(start => $start, end => $end, inc => $inc) Construct a new iterator from start to end step inc. The range is inclusive i.e. if $end == $start, you will get an iterator that returns a single value. @@ -34,40 +35,38 @@ The iteration step is the absolute value of $inc, and defaults to 1. =cut -sub new { - my ( $class, $start, $end, $inc ) = @_; - $inc ||= 1; - return bless( - { - start => $start, - end => $end, - inc => ( $end > $start ) ? abs($inc) : -abs($inc), - cur => $start, - }, - $class - ); +has start => ( is => 'rw', required => 1, ); +has end => ( is => 'rw', required => 1, ); +has inc => ( is => 'rw', default => 1, ); +has cur => + ( is => 'rw', lazy => 1, clearer => 1, default => sub { $_[0]->start }, ); + +sub BUILD { + my $this = shift; + $this->inc( + $this->end > $this->start ? abs( $this->inc ) : -abs( $this->inc ) ); } sub hasNext { my $this = shift; - if ( $this->{inc} > 0 ) { - return $this->{cur} <= $this->{end}; + if ( $this->inc > 0 ) { + return $this->cur <= $this->end; } else { - return $this->{cur} >= $this->{end}; + return $this->cur >= $this->end; } } sub next { my $this = shift; - my $res = $this->{cur}; - $this->{cur} += $this->{inc}; + my $res = $this->cur; + $this->cur( $this->cur + $this->inc ); return $res; } sub reset { my $this = shift; - $this->{cur} = $this->{start}; + $this->clear_cur; } 1; diff --git a/core/lib/Foswiki/Iterator/PagerIterator.pm b/core/lib/Foswiki/Iterator/PagerIterator.pm index f0ee1fdf79..7877c20ccd 100644 --- a/core/lib/Foswiki/Iterator/PagerIterator.pm +++ b/core/lib/Foswiki/Iterator/PagerIterator.pm @@ -9,13 +9,12 @@ Iterator that Pages another iterator =cut package Foswiki::Iterator::PagerIterator; - -use strict; -use warnings; +use v5.14; use Assert; -use Foswiki::Iterator (); -our @ISA = ('Foswiki::Iterator'); +use Moo; +extends qw(Foswiki::Object); +with qw(Foswiki::Iterator); BEGIN { if ( $Foswiki::cfg{UseLocale} ) { @@ -24,9 +23,47 @@ BEGIN { } } +has iterator => ( + is => 'rw', + required => 1, + weak_ref => 1, + isa => Foswiki::Object::isaCLASS( + 'iterator', 'Foswiki::Object', does => 'Foswiki::Iterator', + ), + handles => [qw(nextWeb sortResults)], +); +has pagesize => ( + is => 'ro', + coerce => sub { + return ( $_[0] || $Foswiki::cfg{Search}{DefaultPageSize} || 25 ); + }, +); +has showpage => ( + is => 'ro', + coerce => sub { return defined( $_[0] ? $_[0] : 1 ); }, +); +has pending => ( + is => 'rw', + default => 0, +); +has pager_skip_results_from => ( + is => 'rw', + lazy => 1, + default => sub { + my $this = shift; + return $this->pagesize * ( $this->showpage - 1 ); + }, +); +has pager_result_count => ( + is => 'rw', + lazy => 1, + clearer => 1, + default => sub { return $_[0]->pagesize; }, +); + =begin TML ----++ ClassMethod new( $iter, $pagesize, $showpage) +---++ ClassMethod new( iterator => $iter, [pagesize => $pagesize,] [showpage => $showpage,]) skip a certain number of results based on pagesize and page number @@ -34,112 +71,63 @@ skip a certain number of results based on pagesize and page number =cut -sub new { - my ( $class, $iter, $pagesize, $showpage ) = @_; - ASSERT( UNIVERSAL::isa( $iter, 'Foswiki::Iterator' ) ) if DEBUG; - - my $this = bless( {}, $class ); - $this->{iterator} = $iter; - - $this->{next} = undef; - $this->{pending} = - 0; #has 'hasNext' already been called, but 'next' hasn't been - - $this->{pagesize} = - $pagesize - || $Foswiki::cfg{Search}{DefaultPageSize} - || 25; - $this->{showpage} = $showpage; - $this->{showpage} = 1 unless ( defined( $this->{showpage} ) ); - - $this->{pager_skip_results_from} = - $this->{pagesize} * ( $this->{showpage} - 1 ); - print STDERR -" $this->{pager_skip_results_from} = $this->{pagesize} * ($this->{showpage}-1);\n" - if Foswiki::Iterator::MONITOR; - $this->{pager_result_count} = $this->{pagesize}; - - return $this; -} - -sub pagesize { - my $this = shift; - return $this->{pagesize}; -} - -sub showpage { - my $this = shift; - return $this->{showpage}; -} - #lie - give the requested pagesize - it might be less, if we're at the end of the list #and we can never know if there is just one more, as the underlying iterator may have only asked for pagesize reaults #so it can't tell us sub numberOfTopics { my $this = shift; - if ( !$this->hasNext() && ( $this->{pager_result_count} > 0 ) ) { - return $this->{pagesize} - $this->{pager_result_count}; + if ( !$this->hasNext() && ( $this->pager_result_count > 0 ) ) { + return $this->pagesize - $this->pager_result_count; } else { #we're still iterating, so we don't know the page size - return $this->{pagesize}; + return $this->pagesize; } } #another lie - this hopes that the inner iterator knows the number, and isn't just guessing. sub numberOfPages { my $this = shift; - if ( !$this->hasNext() && ( $this->{pager_result_count} > 0 ) ) { + if ( !$this->hasNext() && ( $this->pager_result_count > 0 ) ) { #if we've exhausted the undelying iterator, and have not got pagesize elements, then we know there are no more. return $this->showpage(); } else { #we're still iterating, so we don't know the page size - return - int( $this->{iterator}->numberOfTopics() / $this->{pagesize} ) + 1; + return int( $this->iterator->numberOfTopics() / $this->pagesize ) + 1; } } -sub nextWeb { - my $this = shift; - $this->{iterator}->nextWeb(); -} - -sub sortResults { - my $this = shift; - $this->{iterator}->sortResults(@_); -} - # See Foswiki::Iterator for a description of the general iterator contract sub hasNext { my $this = shift; - return 1 if $this->{pending}; + return 1 if $this->pending; - if ( $this->{pager_skip_results_from} > 0 ) { - $this->{pager_skip_results_from} = - $this->skip( $this->{pager_skip_results_from} ); + if ( $this->pager_skip_results_from > 0 ) { + $this->pager_skip_results_from( + $this->skip( $this->pager_skip_results_from ) ); - #this already loads $this->{next} + #this already loads $this->_next } else { - if ( $this->{iterator}->hasNext() ) { - $this->{next} = $this->{iterator}->next(); - $this->{pending} = 1; + if ( $this->iterator->hasNext() ) { + $this->_next( $this->iterator->next ); + $this->pending(1); } } - if ( $this->{pending} ) { - if ( $this->{pager_result_count} <= 0 ) { + if ( $this->pending ) { + if ( $this->pager_result_count <= 0 ) { #SVEN - huh? #finished. - $this->{next} = undef; - $this->{pending} = 0; + $this->_clear_next; + $this->pending(0); return 0; } - $this->{pager_result_count}--; + $this->pager_result_count( $this->pager_result_count - 1 ); return 1; } return 0; @@ -156,11 +144,11 @@ sub skip { if Foswiki::Iterator::MONITOR; #ask CAN skip() for faster path - if ( 1 == 2 && $this->{iterator}->can('skip') ) { - $count = $this->{iterator}->skip($count); - if ( $this->{iterator}->hasNext() ) { - $this->{next} = $this->{iterator}->next(); - $this->{pending} = 1; + if ( 1 == 2 && $this->iterator->can('skip') ) { + $count = $this->iterator->skip($count); + if ( $this->iterator->hasNext() ) { + $this->_next( $this->iterator->next ); + $this->pending(1); $count--; } } @@ -170,14 +158,13 @@ sub skip { while ( ( $count >= 0 ) #must come first - don't want to advance the inner itr if count ==0 - and $this->{iterator}->hasNext() + and $this->iterator->hasNext() ) { $count--; - $this->{next} = - $this->{iterator}->next() + $this->_next( $this->iterator->next ) ; #drain next, so hasNext goes to next element - $this->{pending} = defined( $this->{next} ); + $this->pending( defined( $this->_next ) ); } } @@ -185,8 +172,8 @@ sub skip { if ( $count >= 0 ) { #skipped past the end of the set - $this->{next} = undef; - $this->{pending} = 0; + $this->_clear_next; + $this->pending(0); } print STDERR "--------------------------------------------PagerIterator::skip() => $count\n" @@ -199,17 +186,17 @@ sub skip { sub next { my $this = shift; return unless $this->hasNext(); - $this->{pending} = 0; - return $this->{next}; + $this->pending(0); + return $this->_next; } # See Foswiki::Iterator for a description of the general iterator contract sub reset { my ($this) = @_; - return unless ( $this->{iterator}->reset() ); - $this->{next} = undef; - $this->{pending} = 0; + return unless ( $this->iterator->reset() ); + $this->_clear_next; + $this->pending(0); return 1; } diff --git a/core/lib/Foswiki/Iterator/ProcessIterator.pm b/core/lib/Foswiki/Iterator/ProcessIterator.pm index 3471709b7b..9b8518c8b3 100755 --- a/core/lib/Foswiki/Iterator/ProcessIterator.pm +++ b/core/lib/Foswiki/Iterator/ProcessIterator.pm @@ -10,13 +10,13 @@ element in the iteration. =cut package Foswiki::Iterator::ProcessIterator; +use v5.14; -use strict; -use warnings; use Assert; -use Foswiki::Iterator (); -our @ISA = ('Foswiki::Iterator'); +use Moo; +extends qw(Foswiki::Object); +with qw(Foswiki::Iterator); BEGIN { if ( $Foswiki::cfg{UseLocale} ) { @@ -25,37 +25,35 @@ BEGIN { } } +has iterator => ( + is => 'rw', + weak_ref => 1, + required => 1, + isa => Foswiki::Object::isaCLASS( + 'iterator', 'Foswiki::Object', does => 'Foswiki::Iterator', + ), +); +has '+process' => ( is => 'rw', clearer => 1, required => 1, ); +has data => ( is => 'rw', required => 1, ); + =begin TML ----++ ClassMethod new( $iter, $sub ) +---++ ClassMethod new( iterator => $iter, process => $sub, data => $data ) Construct a new iterator that will filter $iter by calling $sub. on each element. $sub should return the filtered value for the element. =cut -sub new { - my ( $class, $iter, $sub, $data ) = @_; - ASSERT( UNIVERSAL::isa( $iter, 'Foswiki::Iterator' ) ) if DEBUG; - ASSERT( ref($sub) eq 'CODE' ) if DEBUG; - my $this = bless( {}, $class ); - $this->{iterator} = $iter; - $this->{process} = $sub; - $this->{data} = $data; - $this->{next} = undef; - return $this; -} - -# See Foswiki::Iterator for a description of the general iterator contract -sub hasNext { +sub BUILD { my $this = shift; - return $this->{iterator}->hasNext(); + ASSERT( ref( $this->process ) eq 'CODE' ) if DEBUG; } # See Foswiki::Iterator for a description of the general iterator contract sub next { my $this = shift; - return &{ $this->{process} }( $this->{iterator}->next(), $this->{data} ); + return &{ $this->process }( $this->iterator->next(), $this->data ); } # See Foswiki::Iterator for a description of the general iterator contract @@ -67,6 +65,11 @@ sub reset { return; } +sub hasNext { + my $this = shift; + return $this->iterator->hasNext(@_); +} + sub all { my $this = shift; my @results; diff --git a/core/lib/Foswiki/LineIterator.pm b/core/lib/Foswiki/LineIterator.pm index 8dae907782..cd84f6c6f8 100644 --- a/core/lib/Foswiki/LineIterator.pm +++ b/core/lib/Foswiki/LineIterator.pm @@ -10,12 +10,11 @@ Iterator over the lines read from a file handle. =cut package Foswiki::LineIterator; +use v5.14; -use strict; -use warnings; - -use Foswiki::Iterator (); -our @ISA = ('Foswiki::Iterator'); +use Moo; +extends qw(Foswiki::Object); +with qw(Foswiki::Iterator); BEGIN { if ( $Foswiki::cfg{UseLocale} ) { @@ -24,28 +23,29 @@ BEGIN { } } +has nextLine => ( + is => 'rw', + coerce => sub { + return undef unless defined( $_[0] ); + chomp $_[0]; + return $_[0]; + }, +); +has handle => ( is => 'rw', init_arg => 'fileHandle', required => 1, ); + =begin TML ----++ new( $fh ) +---++ new( fileHandle => $fh ) Create a new iterator over the given file handle. =cut -sub new { - my ( $class, $fh ) = @_; - my $this = bless( - { - nextLine => undef, - handle => $fh, - }, - $class - ); +sub BUILD { + my $this = shift; Foswiki::LineIterator::next($this); - $this->{process} = undef; - $this->{filter} = undef; - - return $this; + $this->clear_process; + $this->clear_filter; } =begin TML @@ -64,7 +64,7 @@ while ($it->hasNext()) { sub hasNext { my $this = shift; - return defined( $this->{nextLine} ); + return defined( $this->nextLine ); } =begin TML @@ -97,23 +97,20 @@ while ($it->hasNext()) { =cut sub next { - my ($this) = @_; - my $curLine = $this->{nextLine}; + my $this = shift; + my $curLine = $this->nextLine; local $/ = "\n"; while (1) { - my $h = $this->{handle}; - $this->{nextLine} = <$h>; - if ( !defined( $this->{nextLine} ) ) { + my $h = $this->handle; + $this->nextLine(<$h>); + if ( !defined( $this->nextLine ) ) { last; } - else { - chomp( $this->{nextLine} ); - } - last if !$this->{filter}; - last unless &{ $this->{filter} }( $this->{nextLine} ); + last if !$this->filter; + last unless &{ $this->filter }( $this->nextLine ); } - $curLine = &{ $this->{process} }($curLine) - if defined $curLine && $this->{process}; + $curLine = &{ $this->process }($curLine) + if defined $curLine && $this->process; return $curLine; } diff --git a/core/lib/Foswiki/ListIterator.pm b/core/lib/Foswiki/ListIterator.pm index 60efa62228..3c4599424e 100644 --- a/core/lib/Foswiki/ListIterator.pm +++ b/core/lib/Foswiki/ListIterator.pm @@ -8,16 +8,17 @@ Iterator over a perl list WARNING: this Iterator will skip any elements that are == undef. -SMELL: hasNext should not 'return 1 if defined($this->{next}), but rather use a boolean - to allow array elements to be undef too. +SMELL: hasNext should not 'return 1 if defined($this->_next), but rather use a boolean - to allow array elements to be undef too. =cut package Foswiki::ListIterator; -use strict; -use warnings; +use v5.14; -use Foswiki::Iterator (); -our @ISA = ('Foswiki::Iterator'); +use Moo; +use namespace::clean; +extends qw(Foswiki::Object); +with qw(Foswiki::Iterator); use Assert; @@ -38,26 +39,6 @@ any way. =cut -sub new { - my ( $class, $list ) = @_; - - $list = [] unless defined $list; - - ASSERT( UNIVERSAL::isa( $list, 'ARRAY' ) ) if DEBUG; - - my $this = bless( - { - list => $list, - index => 0, - process => undef, - filter => undef, - next => undef, - }, - $class - ); - return $this; -} - =begin TML ---++ hasNext() -> $boolean @@ -75,19 +56,21 @@ while ($it->hasNext()) { sub hasNext { my ($this) = @_; return 1 - if defined( $this->{next} ) + if defined( $this->_next ) ; #SMELL: this is still wrong if the array element == undef, but at least means zero is an element my $n; do { - if ( $this->{list} && $this->{index} < scalar( @{ $this->{list} } ) ) { - $n = $this->{list}->[ $this->{index}++ ]; + if ( $this->list && $this->index < scalar( @{ $this->list } ) ) { + $n = $this->list->[ $this->index ]; + $this->index( $this->index + 1 ); } else { return 0; } - } while ( $this->{filter} && !&{ $this->{filter} }($n) ); - $this->{next} = $n; - print STDERR "ListIterator::hasNext -> $this->{index} == $this->{next}\n" + } while ( $this->filter && !&{ $this->filter }($n) ); + $this->_next($n); + print STDERR "ListIterator::hasNext -> ", $this->index, " == ", + $this->_next, "\n" if Foswiki::Iterator::MONITOR; return 1; } @@ -105,7 +88,7 @@ sub skip { my $this = shift; my $count = shift; - if ( defined( $this->{next} ) ) { + if ( defined( $this->_next ) ) { $count--; } @@ -113,29 +96,30 @@ sub skip { return 0 if ( $count <= 0 ); print STDERR -"--------------------------------------------ListIterator::skip($count) $this->{index}, " - . scalar( @{ $this->{list} } ) . "\n" +"--------------------------------------------ListIterator::skip($count) ", + $this->index, ", ", scalar( @{ $this->list } ), "\n" if Foswiki::Iterator::MONITOR; - my $length = scalar( @{ $this->{list} } ); + my $length = scalar( @{ $this->list } ); - if ( ( $this->{index} + $count ) >= $length ) { + if ( ( $this->index + $count ) >= $length ) { #list too small - $count = $this->{index} + $count - $length; - $this->{index} = 1 + $length; + $count = $this->index + $count - $length; + $this->index( 1 + $length ); } else { - $this->{index} += $count; + $this->index( $this->index + $count ); $count = 0; } - $this->{next} = undef; + $this->_clear_next; my $hasnext = $this->hasNext(); if ($hasnext) { $count--; } print STDERR -"--------------------------------------------ListIterator::skip() => $this->{index} $count, $hasnext\n" + "--------------------------------------------ListIterator::skip() => ", + $this->index, " $count, $hasnext\n" if Foswiki::Iterator::MONITOR; return $count; @@ -179,9 +163,9 @@ will print sub next { my $this = shift; $this->hasNext(); - my $n = $this->{next}; - $this->{next} = undef; - $n = &{ $this->{process} }($n) if $this->{process}; + my $n = $this->_next; + $this->_clear_next; + $n = &{ $this->process }($n) if $this->process; return $n; } @@ -200,17 +184,17 @@ copy to be made. sub all { my $this = shift; - if ( $this->{index} ) { - my @copy = @{ $this->{list} }; # don't damage the original list - splice( @copy, 0, $this->{index} ); - $this->{index} = scalar( @{ $this->{list} } ); + if ( $this->index ) { + my @copy = @{ $this->list }; # don't damage the original list + splice( @copy, 0, $this->index ); + $this->index = scalar( @{ $this->list } ); return @copy; } else { # At the start (good) - $this->{index} = scalar( @{ $this->{list} } ); - return @{ $this->{list} }; + $this->index( scalar( @{ $this->list } ) ); + return @{ $this->list }; } } @@ -229,8 +213,8 @@ while ($it->hasNext()) { sub reset { my ($this) = @_; - $this->{next} = undef; - $this->{index} = 0; + $this->_clear_next; + $this->clear_index; return 1; } diff --git a/core/lib/Foswiki/Macros/QUERY.pm b/core/lib/Foswiki/Macros/QUERY.pm index 248c9bbbab..1655048492 100644 --- a/core/lib/Foswiki/Macros/QUERY.pm +++ b/core/lib/Foswiki/Macros/QUERY.pm @@ -77,7 +77,7 @@ sub expand { catch { if ( $_->isa('Foswiki::Infix::Error') ) { $result = - $this->inlineAlert( 'alerts', 'generic', 'QUERY{', + $this->session->inlineAlert( 'alerts', 'generic', 'QUERY{', $params->stringify(), '}:', $_->text ); } else { diff --git a/core/lib/Foswiki/Macros/QUERYPARAMS.pm b/core/lib/Foswiki/Macros/QUERYPARAMS.pm index 2d55f3817d..6958894382 100644 --- a/core/lib/Foswiki/Macros/QUERYPARAMS.pm +++ b/core/lib/Foswiki/Macros/QUERYPARAMS.pm @@ -14,7 +14,7 @@ BEGIN { sub QUERYPARAMS { my ( $this, $params ) = @_; - return '' unless $this->{request}; + return '' unless $this->request; my $format = defined $params->{format} ? $params->{format} @@ -33,10 +33,10 @@ sub QUERYPARAMS { $separator = Foswiki::expandStandardEscapes($separator); my @list; - foreach my $name ( $this->{request}->multi_param() ) { + foreach my $name ( $this->request->multi_param() ) { # Issues multi-valued parameters as separate hiddens - my @values = $this->{request}->multi_param($name); + my @values = $this->request->multi_param($name); foreach my $value (@values) { $value = '' unless defined $value; $name = $this->ENCODE( { type => $encoding, _DEFAULT => $name } ); diff --git a/core/lib/Foswiki/Macros/REVINFO.pm b/core/lib/Foswiki/Macros/REVINFO.pm index c63ab88352..a0fb73ba0c 100644 --- a/core/lib/Foswiki/Macros/REVINFO.pm +++ b/core/lib/Foswiki/Macros/REVINFO.pm @@ -19,7 +19,7 @@ sub REVINFO { my $format = $params->{_DEFAULT} || $params->{format}; my $web = $params->{web} || $topicObject->web; my $topic = $params->{topic} || $topicObject->topic; - my $cgiQuery = $this->{request}; + my $cgiQuery = $this->request; my $cgiRev = ''; $cgiRev = $cgiQuery->param('rev') if ($cgiQuery); my $rev = Foswiki::Store::cleanUpRevID( $params->{rev} || $cgiRev || '' ); diff --git a/core/lib/Foswiki/Macros/REVTITLE.pm b/core/lib/Foswiki/Macros/REVTITLE.pm index 25dee86b0a..3320760036 100644 --- a/core/lib/Foswiki/Macros/REVTITLE.pm +++ b/core/lib/Foswiki/Macros/REVTITLE.pm @@ -13,7 +13,7 @@ BEGIN { sub REVTITLE { my ( $this, $params, $topicObject ) = @_; - my $request = $this->{request}; + my $request = $this->request; my $out = ''; if ($request) { my $rev = diff --git a/core/lib/Foswiki/Macros/SEARCH.pm b/core/lib/Foswiki/Macros/SEARCH.pm index 1e6dbbb7e1..7a24487e62 100644 --- a/core/lib/Foswiki/Macros/SEARCH.pm +++ b/core/lib/Foswiki/Macros/SEARCH.pm @@ -44,6 +44,14 @@ sub SEARCH { my $exception = $_; my $message; + # If an unhandled system error took place then let lower level code take + # care of it. + # If code is executed in unit test mode then avoid HTMLization of error + # report. + if ( $Foswiki::inUnitTestMode || !ref($exception) ) { + Foswiki::Exception::Fatal->rethrow($exception); + } + if (DEBUG) { $message = $exception->stringify(); } diff --git a/core/lib/Foswiki/Macros/WIKINAME.pm b/core/lib/Foswiki/Macros/WIKINAME.pm index 4aa38427c1..b8de4eaa74 100644 --- a/core/lib/Foswiki/Macros/WIKINAME.pm +++ b/core/lib/Foswiki/Macros/WIKINAME.pm @@ -16,7 +16,7 @@ BEGIN { sub WIKINAME { my ( $this, $params ) = @_; - $params->{format} = $this->{prefs}->getPreference('WIKINAME') + $params->{format} = $this->prefs->getPreference('WIKINAME') || '$wikiname'; return $this->USERINFO($params); diff --git a/core/lib/Foswiki/Meta.pm b/core/lib/Foswiki/Meta.pm index 20adb5cd79..07521c0d17 100644 --- a/core/lib/Foswiki/Meta.pm +++ b/core/lib/Foswiki/Meta.pm @@ -2151,7 +2151,7 @@ sub saveAs { # Don't verify web existance for WebPreferences, as saving # WebPreferences creates the web. unless ( $this->session->store->webExists( $this->web ) ) { - throw Error::Simple( 'Unable to save topic ' + Foswiki::Exception->throw( text => 'Unable to save topic ' . $this->topic . ' - web ' . $this->web @@ -2689,18 +2689,18 @@ sub removeFromStore { ASSERT( $this->web, 'this is not a removable object' ) if DEBUG; if ( !$store->webExists( $this->web ) ) { - throw Error::Simple( 'No such web ' . $this->web ); + Foswiki::Exception->throw( text => 'No such web ' . $this->web ); } if ( $this->topic && !$store->topicExists( $this->web, $this->topic ) ) { - throw Error::Simple( - 'No such topic ' . $this->web . '.' . $this->topic ); + Foswiki::Exception->throw( + text => 'No such topic ' . $this->web . '.' . $this->topic ); } if ( $attachment && !$this->hasAttachment($attachment) ) { ASSERT( $this->topic, 'this is not a removable object' ) if DEBUG; - throw Error::Simple( 'No such attachment ' + Foswiki::Exception->throw( text => 'No such attachment ' . $this->web . '.' . $this->topic . '.' . $attachment ); @@ -2941,9 +2941,11 @@ sub attach { # no stream given, but a file was given; open it. open( $opts{stream}, '<', $opts{file} ) - || throw Error::Simple( 'Could not open ' . $opts{file} ); + || Foswiki::Exception->throw( + text => 'Could not open ' . $opts{file} ); binmode( $opts{stream} ) - || throw Error::Simple( $opts{file} . ' binmode failed: ' . $! ); + || Foswiki::Exception->throw( + text => $opts{file} . ' binmode failed: ' . $! ); } my $attrs; diff --git a/core/lib/Foswiki/MetaCache.pm b/core/lib/Foswiki/MetaCache.pm index 68e347d409..2f523f94ad 100644 --- a/core/lib/Foswiki/MetaCache.pm +++ b/core/lib/Foswiki/MetaCache.pm @@ -1,7 +1,6 @@ # See bottom of file for license and copyright information package Foswiki::MetaCache; -use strict; -use warnings; +use v5.14; =begin TML @@ -23,6 +22,10 @@ use Foswiki::Func (); use Foswiki::Meta (); use Foswiki::Users::BaseUserMapping (); +use Moo; +use namespace::clean; +extends qw(Foswiki::Object); + #use Monitor (); #Monitor::MonitorMethod('Foswiki::MetaCache', 'getTopicListIterator'); @@ -41,24 +44,33 @@ BEGIN { =cut -sub new { - my ( $class, $session ) = @_; - - #my $this = $class->SUPER::new([]); - my $this = bless( - { - session => $session, - cache => {}, - new_count => 0, - get_count => 0, - undef_count => 0, - meta_cache_session_user => $session->{user}, - }, - $class - ); - - return $this; -} +has session => ( + is => 'rw', + weak_ref => 1, + isa => Foswiki::Object::isaCLASS( 'session', 'Foswiki' ), +); +has cache => ( + is => 'rw', + lazy => 1, + default => sub { {} }, +); +has new_count => ( + is => 'rw', + default => 0, +); +has get_count => ( + is => 'rw', + default => 0, +); +has undef_count => ( + is => 'rw', + default => 0, +); +has meta_cache_session_user => ( + is => 'ro', + lazy => 1, + default => sub { return $_[0]->session->user; }, +); #need to delete from cache if the store saves / updates it :/ #otherwise the Meta::load thing is busted. @@ -76,7 +88,8 @@ Break circular references. sub finish { my $this = shift; - undef $this->{session}; + + #undef $this->{session}; #must clear cache every request until the cache is hooked up to Store's save foreach my $cuid ( keys( %{ $this->{cache} } ) ) { @@ -112,9 +125,8 @@ sub hasCached { ASSERT( defined($topic) ) if DEBUG; return unless ( defined($topic) ); - return ( $this->{session}->{user} - and - defined( $this->{cache}->{ $this->current_user() }{$web}{$topic} ) ); + return ( $this->session->user + and defined( $this->cache->{ $this->current_user }{$web}{$topic} ) ); } sub removeMeta { @@ -122,18 +134,18 @@ sub removeMeta { my $user = $this->current_user(); if ( defined($topic) ) { - my $cached_userwebtopic = $this->{cache}->{$user}{$web}{$topic}; + my $cached_userwebtopic = $this->cache->{$user}{$web}{$topic}; if ($cached_userwebtopic) { $cached_userwebtopic->finish() if blessed($cached_userwebtopic); - delete $this->{cache}->{$user}{$web}{$topic}; + delete $this->cache->{$user}{$web}{$topic}; } } elsif ( defined $web ) { - foreach my $topic ( keys( %{ $this->{cache}->{$user}{$web} } ) ) { + foreach my $topic ( keys( %{ $this->cache->{$user}{$web} } ) ) { $this->removeMeta( $web, $topic ); } - delete $this->{cache}->{$user}{$web}; + delete $this->cache->{$user}{$web}; } return; @@ -149,11 +161,11 @@ sub addMeta { # If the cache is already populated, return it, don't add it again if ( $this->hasCached( $web, $topic ) ) { print STDERR "Cache hit for $web.$topic for $user\n" if (TRACE); - return $this->{cache}->{$user}{$web}{$topic}->{tom}; + return $this->cache->{$user}{$web}{$topic}->{tom}; } if ( not defined($meta) ) { - $meta = Foswiki::Meta->load( $this->{session}, $web, $topic ); + $meta = Foswiki::Meta->load( $this->session, $web, $topic ); } if ( ( defined($meta) and $meta ne '' ) and defined( $meta->latestIsLoaded ) @@ -168,15 +180,15 @@ sub addMeta { return; } - unless ( $this->{cache}->{$user}{$web} ) { - $this->{cache}->{$user}{$web} = {}; + unless ( $this->cache->{$user}{$web} ) { + $this->cache->{$user}{$web} = {}; } - unless ( $this->{cache}->{$user}{$web}{$topic} ) { - $this->{cache}->{$user}{$web}{$topic} = {}; + unless ( $this->cache->{$user}{$web}{$topic} ) { + $this->cache->{$user}{$web}{$topic} = {}; } - unless ( defined( $this->{cache}->{$user}{$web}{$topic}->{tom} ) ) { - $this->{cache}->{$user}{$web}{$topic}->{tom} = $meta; - $this->{new_count}++; + unless ( defined( $this->cache->{$user}{$web}{$topic}->{tom} ) ) { + $this->cache->{$user}{$web}{$topic}->{tom} = $meta; + $this->new_count( $this->new_count + 1 ); } return $meta; } @@ -185,9 +197,9 @@ sub getMeta { my ( $this, $web, $topic, $meta ) = @_; my $user = $this->current_user(); - return unless ( defined( $this->{cache}->{$user}{$web} ) ); - return unless ( defined( $this->{cache}->{$user}{$web}{$topic} ) ); - return $this->{cache}->{$user}{$web}{$topic}->{tom}; + return unless ( defined( $this->cache->{$user}{$web} ) ); + return unless ( defined( $this->cache->{$user}{$web}{$topic} ) ); + return $this->cache->{$user}{$web}{$topic}->{tom}; } =begin TML @@ -221,14 +233,14 @@ sub get { $meta = $m if ( defined($m) ); ASSERT( defined($meta) ) if DEBUG; - $this->{get_count}++; + $this->get_count( $this->get_count + 1 ); my $info = { tom => $meta }; my $user = $this->current_user(); ASSERT( defined $user ) if DEBUG; - $info = $this->{cache}->{$user}{$web}{$topic} - if defined( $this->{cache}->{$user}{$web}{$topic} ); + $info = $this->cache->{$user}{$web}{$topic} + if defined( $this->cache->{$user}{$web}{$topic} ); if ( not defined( $info->{editby} ) ) { #TODO: extract this to the Meta Class, or remove entirely @@ -244,16 +256,16 @@ sub get { #Ideally, the Store2::Meta object will _not_ contain any session info, and anything that is session / user oriented gets stored in another object that links to the 'database' object. #it'll probably be better to make the MetaCache know what #Item10097: make the cache multi-user safe by storing the haveAccess on a per user basis - if ( not defined( $info->{ $this->{session}->{user} } ) ) { - $info->{ $this->{session}->{user} } = (); + if ( not defined( $info->{ $this->session->user } ) ) { + $info->{ $this->session->user } = (); } - if ( not defined( $info->{ $this->{session}->{user} }{allowView} ) ) { - $info->{ $this->{session}->{user} }{allowView} = + if ( not defined( $info->{ $this->session->user }{allowView} ) ) { + $info->{ $this->session->user }{allowView} = $info->{tom}->haveAccess('VIEW'); } #use the cached permission - $info->{allowView} = $info->{ $this->{session}->{user} }{allowView}; + $info->{allowView} = $info->{ $this->session->user }{allowView}; } return $info; diff --git a/core/lib/Foswiki/Object.pm b/core/lib/Foswiki/Object.pm index 0e45c515e4..c739d55bfd 100644 --- a/core/lib/Foswiki/Object.pm +++ b/core/lib/Foswiki/Object.pm @@ -107,7 +107,8 @@ sub BUILDARGS { # If $paramHash is undef at this point then either @params is a key/value pairs array or no @_newParameters array defined. # SMELL XXX Number of elements in @params has to be checked and an exception thrown if it's inappropriate. unless ( defined $paramHash ) { - Carp::confess("Odd number of elements in parameters hash") + Foswiki::Exception::Fatal->throw( + text => "Odd number of elements in parameters hash" ) if ( @params % 2 ) == 1; $paramHash = {@params}; } @@ -232,6 +233,7 @@ descendant. * =noUndef= – do not allow undef value * =strictMatch= - allow only =$className=, no decsendants + * =does= - defines a Role class must do. =cut @@ -249,13 +251,14 @@ sub isaCLASS { . $className . ' but not " . (defined $_[0] ? ref($_[0]) || $_[0] : "undef") . "." ) if ' . ( $opts{noUndef} ? '!defined( $_[0] ) || ' : '' ) - . '( defined( $_[0] ) && ' + . '( defined( $_[0] ) && (' . ( $opts{strictMatch} ? 'ref( $_[0] ) ne "' . $className . '"' : '!$_[0]->isa("' . $className . '")' ) - . '); }' + . ( $opts{does} ? ' || !$_[0]->does("' . $opts{does} . '")' : '' ) + . ')' . '); }' ); } diff --git a/core/lib/Foswiki/Query/HoistREs.pm b/core/lib/Foswiki/Query/HoistREs.pm index d5306f56d1..40589eac00 100644 --- a/core/lib/Foswiki/Query/HoistREs.pm +++ b/core/lib/Foswiki/Query/HoistREs.pm @@ -318,8 +318,8 @@ sub _hoistDOT { { $lhs = $lhs->params->[0]; $rhs = $rhs->params->[0]; - if ( $Foswiki::Query::Node::aliases{$lhs} ) { - $lhs = $Foswiki::Query::Node::aliases{$lhs}; + if ( $Foswiki::Meta::aliases{$lhs} ) { + $lhs = $Foswiki::Meta::aliases{$lhs}; } if ( $lhs =~ m/^META:/ ) { diff --git a/core/lib/Foswiki/Search.pm b/core/lib/Foswiki/Search.pm index 1e51c9ef25..e5e0bc8d95 100644 --- a/core/lib/Foswiki/Search.pm +++ b/core/lib/Foswiki/Search.pm @@ -1,5 +1,6 @@ # See bottom of file for license and copyright information package Foswiki::Search; +use v5.14; =begin TML @@ -9,9 +10,6 @@ This module implements all the search functionality. =cut -use strict; -use warnings; -use Assert; use Try::Tiny; use Foswiki (); @@ -31,6 +29,8 @@ use namespace::clean; extends 'Foswiki::Object'; +use Assert; + use constant MONITOR => 0; BEGIN { @@ -41,8 +41,29 @@ BEGIN { } has session => ( is => 'ro', ); - -our @_newParameters = qw( session ); +has metacache => ( + is => 'ro', + lazy => 1, + default => sub { + return Foswiki::MetaCache->new( session => $_[0]->session ); + }, +); +has queryParser => ( + is => 'ro', + lazy => 1, + default => sub { + require Foswiki::Query::Parser; + return Foswiki::Query::Parser->new; + }, +); +has searchParser => ( + is => 'ro', + lazy => 1, + default => sub { + require Foswiki::Search::Parser; + return Foswiki::Search::Parser->new( session => $_[0]->session ); + }, +); =begin TML @@ -55,44 +76,28 @@ Break circular references. =cut -sub finish { - my $this = shift; - undef $this->{session}; - -# these may well be function objects, but if (a setting changes, it needs to be picked up again. - if ( defined( $this->{queryParser} ) ) { - - #$this->{queryParser}->finish(); - undef $this->{queryParser}; - } - if ( defined( $this->{searchParser} ) ) { - - #$this->{searchParser}->finish(); - undef $this->{searchParser}; - } - if ( defined( $this->{MetaCache} ) ) { - - #$this->{MetaCache}->finish(); - undef $this->{MetaCache}; - } -} - -=begin TML - ----++ ObjectMethod metacache -returns the metacache. - -=cut - -sub metacache { - my $this = shift; - -# these may well be function objects, but if (a setting changes, it needs to be picked up again. - if ( !defined( $this->{MetaCache} ) ) { - $this->{MetaCache} = new Foswiki::MetaCache( $this->{session} ); - } - return $this->{MetaCache}; -} +# XXX vrurg finish is not needed as attributes will be cleared automatically. +#sub finish { +# my $this = shift; +# undef $this->session; +# +## these may well be function objects, but if (a setting changes, it needs to be picked up again. +# if ( defined( $this->queryParser ) ) { +# +# #$this->{queryParser}->finish(); +# undef $this->{queryParser}; +# } +# if ( defined( $this->{searchParser} ) ) { +# +# #$this->{searchParser}->finish(); +# undef $this->{searchParser}; +# } +# if ( defined( $this->{MetaCache} ) ) { +# +# #$this->{MetaCache}->finish(); +# undef $this->{MetaCache}; +# } +#} =begin TML @@ -112,19 +117,10 @@ sub parseSearch { my $query; my $theParser; if ( $params->{type} eq 'query' ) { - unless ( defined( $this->{queryParser} ) ) { - require Foswiki::Query::Parser; - $this->{queryParser} = new Foswiki::Query::Parser(); - } - $theParser = $this->{queryParser}; + $theParser = $this->queryParser; } else { - unless ( defined( $this->{searchParser} ) ) { - require Foswiki::Search::Parser; - $this->{searchParser} = - new Foswiki::Search::Parser( $this->{session} ); - } - $theParser = $this->{searchParser}; + $theParser = $this->searchParser; } try { $query = $theParser->parse( $searchString, $params ); @@ -137,7 +133,7 @@ sub parseSearch { # # # Pass the error on to the caller - # throw Error::Simple( shift->stringify() ); + # Foswiki::Exception->throw( text => shift->stringify() ); #}; # Guess as now exceptions are all derived from a single ancestor there is no # more need to convert into Error::Simple. Though stringification has to be @@ -145,6 +141,8 @@ sub parseSearch { $_->throw; } + # SMELL What shall we do with the rest of the exceptions? + Foswiki::Exception::Fatal->rethrow($_); }; #print STDERR "parseSearch($searchString) => ".$query->stringify()."\n" if MONITOR; @@ -264,16 +262,16 @@ FIXME: =callback= cannot work with format parameter (consider format='| $topic | sub searchWeb { my $this = shift; - my $session = $this->{session}; - ASSERT( defined $session->{webName} ) if DEBUG; + my $session = $this->session; + ASSERT( defined $session->webName ) if DEBUG; my %params = @_; - my $baseWebObject = Foswiki::Meta->new( $session, $session->{webName} ); + my $baseWebObject = Foswiki::Meta->new( $session, $session->webName ); my ( $callback, $cbdata ) = setup_callback( \%params, $baseWebObject ); - my $baseTopic = $params{basetopic} || $session->{topicName}; - my $baseWeb = $params{baseweb} || $session->{webName}; + my $baseTopic = $params{basetopic} || $session->topicName; + my $baseWeb = $params{baseweb} || $session->webName; $params{casesensitive} = Foswiki::isTrue( $params{casesensitive} ); $params{excludeTopics} = $params{excludetopic} || ''; my $formatDefined = $params{formatdefined} = defined $params{format}; @@ -341,7 +339,7 @@ sub searchWeb { $searchString =~ s/(&#(39|34|60|62|37);)/chr($2)/ge; } else { - throw Error::Simple( + Foswiki::Exception->throw( text => 'Unknown decode type requested: Valid types are entity, entities, safe and url.' ); } @@ -385,7 +383,7 @@ sub searchWeb { $params{pager_urlparam_id} = $paging_ID; # 1-based system; 0 is not a valid page number - $params{showpage} = $session->{request}->param($paging_ID) + $params{showpage} = $session->request->param($paging_ID) || $params{showpage}; #append a pager to the end of the search result. @@ -508,7 +506,7 @@ sub loadTemplates { $noSummary, $noTotal, $noFooter ) = @_; - my $session = $this->{session}; + my $session = $this->session; #tmpl loading code. my $tmpl = ''; @@ -612,12 +610,12 @@ the hash of subs can take care of %MACRO{}% specific complex to evaluate replace sub formatResults { my ( $this, $query, $infoCache, $params ) = @_; - my $session = $this->{session}; - my $users = $session->{users}; + my $session = $this->session; + my $users = $session->users; my ( $callback, $cbdata ) = setup_callback($params); - my $baseTopic = $session->{topicName}; - my $baseWeb = $session->{webName}; + my $baseTopic = $session->topicName; + my $baseWeb = $session->webName; my $doBookView = Foswiki::isTrue( $params->{bookview} ); my $caseSensitive = Foswiki::isTrue( $params->{casesensitive} ); my $doExpandVars = Foswiki::isTrue( $params->{expandvariables} ); @@ -674,8 +672,8 @@ sub formatResults { my %new_params; #kill me please, i can't find a way to just load up the hash :( - foreach my $key ( $session->{request}->param ) { - $new_params{$key} = $session->{request}->param($key); + foreach my $key ( $session->request->param ) { + $new_params{$key} = $session->request->param($key); } $session->templates->readTemplate('searchformat'); @@ -803,7 +801,7 @@ sub formatResults { Foswiki::Func::normalizeWebTopicName( '', $listItem ); # add dependencies (TODO: unclear if this should be before the paging, or after the allowView - sadly, it can't be _in_ the infoCache) - if ( my $cache = $session->{cache} ) { + if ( my $cache = $session->cache ) { $cache->addDependency( $web, $topic ); } @@ -1170,7 +1168,7 @@ sub formatResults { sub formatCommon { my ( $this, $out, $customKeys ) = @_; - my $session = $this->{session}; + my $session = $this->session; foreach my $key ( keys(%$customKeys) ) { $out =~ s/\$$key/&{$customKeys->{$key}}()/ges; @@ -1198,7 +1196,7 @@ sub formatResult { my ( $this, $out, $item, $text, $searchOptions, $nonTomKeys, $tomKeys ) = @_; - my $session = $this->{session}; + my $session = $this->session; #TODO: these need to go away. my $revNum = &{ $nonTomKeys->{'revNum'} }(); @@ -1267,7 +1265,7 @@ s/\$formfield\(\s*([^\)]*)\s*\)/displayFormField( $item, $1, $newLine )/ges; $text = $item->text() unless defined $text; $text = '' unless defined $text; - if ( $item->topic eq $session->{topicName} ) { + if ( $item->topic eq $session->topicName ) { #TODO: extract the diffusion and generalise to whatever MACRO we are processing - anything with a format can loop diff --git a/core/lib/Foswiki/Search/InfoCache.pm b/core/lib/Foswiki/Search/InfoCache.pm index 2fa3ff60d5..15557c4d80 100644 --- a/core/lib/Foswiki/Search/InfoCache.pm +++ b/core/lib/Foswiki/Search/InfoCache.pm @@ -1,12 +1,15 @@ # See bottom of file for license and copyright information package Foswiki::Search::InfoCache; -use strict; -use warnings; - -use Foswiki::ListIterator (); -our @ISA = ('Foswiki::ListIterator'); +use v5.14; use Unicode::Normalize; +use Foswiki::Func (); +use Foswiki::Meta (); +use Foswiki::Iterator::FilterIterator (); + +use Moo; +use namespace::clean; +extends qw(Foswiki::ListIterator); BEGIN { if ( $Foswiki::cfg{UseLocale} ) { @@ -30,16 +33,13 @@ about the same topic more than once. # Sven has the feeling that we should make result sets immutable use Assert; -use Foswiki::Func (); -use Foswiki::Meta (); -use Foswiki::Iterator::FilterIterator (); #use Monitor (); #Monitor::MonitorMethod('Foswiki::Search::InfoCache', 'getTopicListIterator'); =begin TML ----++ ClassMethod new($session, $defaultWeb, \@topicList) +---++ ClassMethod new(session => $session, defaultWeb => $defaultWeb, topicList => \@topicList) Initialise a new list of topics, allowing their data to be lazy loaded if and when needed. @@ -56,23 +56,45 @@ Because this Iterator can be created and filled dynamically, once the Iterator h #TODO: or..... make reset() make the object mutable again, so we can change the elements in the list, but re-use the meta cache?? #CONSIDER: convert the internals to a hash[tomAddress] = {matches->[list of resultint text bits], othermeta...} - except this does not give us order :/ -sub new { - my ( $class, $session, $defaultWeb, $topicList ) = @_; - - my $this = $class->SUPER::new( [] ); - $this->{_session} = $session; - $this->{_defaultWeb} = $defaultWeb; - $this->{count} = 0; - if ( defined($topicList) ) { - $this->addTopics( $defaultWeb, @$topicList ); - } +has _session => ( + is => 'rw', + weak_ref => 1, + init_arg => 'session', +); +has _defaultWeb => ( + is => 'rw', + init_arg => 'defaultWeb', +); +has count => ( + is => 'rw', + lazy => 1, + default => 0, +); +has _topicList => ( + is => 'rw', + init_arg => 'topicList', + isa => Foswiki::Object::isaARRAY('_topicList'), + clearer => 1, + predicate => 1, +); +has sorted => ( + is => 'rw', + predicate => 1, + clearer => 1, + lazy => 1, + defaut => 0, +); + +sub BUILD { + my $this = shift; - return $this; + $this->addTopics( $this->_defaultWeb, @{ $this->_topicList } ) + if $this->_has_topicList; } sub isImmutable { my $this = shift; - return ( $this->{index} != 0 ); + return ( $this->index != 0 ); } sub addTopics { @@ -84,10 +106,10 @@ sub addTopics { foreach my $t (@list) { my ( $web, $topic ) = Foswiki::Func::normalizeWebTopicName( $defaultWeb, $t ); - push( @{ $this->{list} }, "$web.$topic" ); - $this->{count}++; + push( @{ $this->list }, "$web.$topic" ); + $this->count( $this->count + 1 ); } - undef $this->{sorted}; + $this->clear_sorted; } #TODO: what if it isa Meta obj @@ -102,12 +124,12 @@ sub addTopic { my ( $w, $t ) = Foswiki::Func::normalizeWebTopicName( $web, $topic ); my $webtopic = "$w.$t"; - push( @{ $this->{list} }, $webtopic ); - $this->{count}++; + push( @{ $this->list }, $webtopic ); + $this->count( $this->count + 1 ); if ( defined($meta) ) { - $this->{_session}->search->metacache->addMeta( $web, $topic, $meta ); + $this->_session->search->metacache->addMeta( $web, $topic, $meta ); } - undef $this->{sorted}; + $this->clear_sorted; } sub numberOfTopics { @@ -115,10 +137,10 @@ sub numberOfTopics { #can't use this, as it lies once its gone through the 'sortResults' hack #and lies more because the filterByDate is evaluated later. - #return scalar(@{ $this->{list} }); + #return scalar(@{ $this->list }); # when fixed, the count update in filterByDate should be removed - return $this->{count}; + return $this->count; } =begin TML @@ -138,10 +160,10 @@ sub sortResults { my ( $this, $params ) = @_; #TODO: for now assume we do not change the sort order later - return if ( defined( $this->{sorted} ) ); - $this->{sorted} = 1; + return if ( $this->sorted ); + $this->sorted(1); - my $session = $this->{_session}; + my $session = $this->_session; my $sortOrder = $params->{order} || ''; my $revSort = Foswiki::isTrue( $params->{reverse} ); @@ -182,7 +204,7 @@ sub sortResults { # SMELL: In Dakar this seems to be pointless since latest rev # time is taken from topic instead of dir list. my $slack = 10; - if ( $limit + 2 * $slack < scalar( @{ $this->{list} } ) ) { + if ( $limit + 2 * $slack < scalar( @{ $this->list } ) ) { # sort by approx latest rev time my @tmpList = @@ -190,17 +212,20 @@ sub sortResults { sort { $a->[0] <=> $b->[0] } map { my ( $web, $topic ) = - Foswiki::Func::normalizeWebTopicName( $this->{_defaultWeb}, + Foswiki::Func::normalizeWebTopicName( $this->_defaultWeb, $_ ); [ $session->getApproxRevTime( $web, $topic ), $_ ] - } @{ $this->{list} }; + } @{ $this->list }; @tmpList = reverse(@tmpList) if ($revSort); # then shorten list and build the hashes for date and author my $idx = $limit + $slack; - @{ $this->{list} } = (); + +# SMELL This is the old pre-Moo code. Hopefully it doesn't rely on exact array reference? +#@{ $this->list } = (); + $this->clear_list; foreach (@tmpList) { - push( @{ $this->{list} }, $_ ); + push( @{ $this->list }, $_ ); $idx -= 1; last if $idx <= 0; } @@ -219,7 +244,7 @@ sub sortResults { #default to topic sorting $sortOrder = 'topic'; } - sortTopics( $this->{list}, $sortOrder, !$revSort ); + sortTopics( $this->list, $sortOrder, !$revSort ); } =begin TML @@ -239,25 +264,27 @@ $infoCache->filterByDate( $date ); sub filterByDate { my ( $this, $date ) = @_; - ASSERT( !defined( $this->{filter} ) ) if DEBUG; + ASSERT( !defined( $this->filter ) ) if DEBUG; my $session = $Foswiki::Plugins::SESSION; require Foswiki::Time; my @ends = Foswiki::Time::parseInterval($date); - $this->{filter} = sub { - my $webtopic = shift; + $this->filter( + sub { + my $webtopic = shift; - # if date falls out of interval: exclude topic from result - my ( $web, $topic ) = - Foswiki::Func::normalizeWebTopicName( $this->{_defaultWeb}, - $webtopic ); - my $topicdate = $session->getApproxRevTime( $web, $topic ); + # if date falls out of interval: exclude topic from result + my ( $web, $topic ) = + Foswiki::Func::normalizeWebTopicName( $this->_defaultWeb, + $webtopic ); + my $topicdate = $session->getApproxRevTime( $web, $topic ); - return !( $topicdate < $ends[0] || $topicdate > $ends[1] ); + return !( $topicdate < $ends[0] || $topicdate > $ends[1] ); - }; + } + ); return; } diff --git a/core/lib/Foswiki/Search/Parser.pm b/core/lib/Foswiki/Search/Parser.pm index d2ec7a3869..71ab00ebea 100644 --- a/core/lib/Foswiki/Search/Parser.pm +++ b/core/lib/Foswiki/Search/Parser.pm @@ -1,5 +1,6 @@ # See bottom of file for license and copyright information package Foswiki::Search::Parser; +use v5.14; =begin TML @@ -9,14 +10,16 @@ Parse SEARCH token strings into Foswiki::Search::Node objects. =cut -use strict; -use warnings; - -use Assert; -use Error qw( :try ); +use Try::Tiny; use Foswiki::Search::Node (); +use Moo; +use namespace::clean; +extends qw(Foswiki::Object); + +use Assert; + BEGIN { if ( $Foswiki::cfg{UseLocale} ) { require locale; @@ -32,28 +35,33 @@ our $MARKER = "\0"; =cut -sub new { - my ( $class, $session ) = @_; - my $this = bless( { session => $session }, $class ); - return $this; -} +has session => ( + is => 'rw', + weak_ref => 1, +); +has initialised => ( + is => 'rw', + default => 0, +); +has stopwords => ( is => 'rw', ); # Initialise on demand before a first parse sub _initialise { my $this = shift; - return if ( $this->{initialised} ); + return if ( $this->initialised ); # Build pattern of stop words - my $WMARK = chr(0); # Set a word marker - my $prefs = $this->{session}->{prefs}; + my $WMARK = chr(0); # Set a word marker + my $prefs = $this->session->prefs; ASSERT($prefs) if DEBUG; - $this->{stopwords} = $prefs->getPreference('SEARCHSTOPWORDS') || ''; - $this->{stopwords} =~ s/[\s\,]+/$WMARK/g; - $this->{stopwords} = quotemeta $this->{stopwords}; - $this->{stopwords} =~ s/\\$WMARK/|/g; + my $stopwords = $prefs->getPreference('SEARCHSTOPWORDS') || ''; + $stopwords =~ s/[\s\,]+/$WMARK/g; + $stopwords = quotemeta $stopwords; + $stopwords =~ s/\\$WMARK/|/g; + $this->stopwords($stopwords); - $this->{initialised} = 1; + $this->initialised(1); } =begin TML @@ -63,13 +71,13 @@ Break circular references. =cut -sub finish { - my $self = shift; - - undef $self->{session}; - undef $self->{stopwords}; - undef $self->{initialised}; -} +#sub finish { +# my $self = shift; +# +# undef $self->{session}; +# undef $self->{stopwords}; +# undef $self->{initialised}; +#} =begin TML @@ -119,16 +127,17 @@ sub parse { # Tokenize string taking account of literal strings, then remove # stop words and convert '+' and '-' syntax. + my $stopwords = $this->stopwords; @tokens = - grep { !/^($this->{stopwords})$/i } # remove stopwords + grep { !/^($stopwords)$/i } # remove stopwords map { s/^\+//; s/^\-/\!/; s/^"//; $_ - } # remove +, change - to !, remove " - map { s/$MARKER/ /go; $_ } # restore space - split( /\s+/, $searchString ); # split on spaces + } # remove +, change - to !, remove " + map { s/$MARKER/ /go; $_ } # restore space + split( /\s+/, $searchString ); # split on spaces } my $result = new Foswiki::Search::Node( $searchString, \@tokens, $options ); diff --git a/core/lib/Foswiki/Store.pm b/core/lib/Foswiki/Store.pm index 1ba0506404..ec4899c5ba 100644 --- a/core/lib/Foswiki/Store.pm +++ b/core/lib/Foswiki/Store.pm @@ -129,12 +129,13 @@ sub getWorkArea { # attachment names. $key = Foswiki::Sandbox::untaint( $key, \&Foswiki::Sandbox::validateAttachmentName ); - throw Error::Simple("Bad work area name $key") unless ($key); + Foswiki::Exception->throw( text => "Bad work area name $key" ) + unless ($key); my $dir = "$Foswiki::cfg{WorkingDir}/work_areas/$key"; unless ( -d $dir ) { - mkdir($dir) || throw Error::Simple(<throw( text => <{'date'} || ''; # Fold constants - my $context = Foswiki::Meta->new( $session, $session->{webName} ); + my $context = + Foswiki::Meta->new( session => $session, web => $session->webName ); print STDERR "--- before: " . $query->stringify() . "\n" if MONITOR; $query->simplify( tom => $context, data => $context ); print STDERR "--- simplified: " . $query->stringify() . "\n" if MONITOR; @@ -102,8 +103,8 @@ sub query { #do the search my $queryItr = Foswiki::Iterator::ProcessIterator->new( - $webItr, - sub { + iterator => $webItr, + process => sub { my $web = shift; my $params = shift; @@ -117,7 +118,7 @@ sub query { return $infoCache; }, - { + data => { query => $query, inputset => $inputTopicSet, session => $session, @@ -210,17 +211,18 @@ sub getWebIterator { my @webs = Foswiki::Store::Interfaces::QueryAlgorithm::getListOfWebs( $webNames, $recurse, $searchAllFlag ); - my $rawWebIter = new Foswiki::ListIterator( \@webs ); - my $webItr = new Foswiki::Iterator::FilterIterator( - $rawWebIter, - sub { + my $rawWebIter = new Foswiki::ListIterator( list => \@webs ); + my $webItr = new Foswiki::Iterator::FilterIterator( + iterator => $rawWebIter, + filter => sub { my $web = shift; my $params = shift; # can't process what ain't thar return 0 unless $session->webExists($web); - my $webObject = Foswiki::Meta->new( $session, $web ); + my $webObject = + Foswiki::Meta->new( session => $session, web => $web ); my $thisWebNoSearchAll = Foswiki::isTrue( $webObject->getPreference('NOSEARCHALL') ); @@ -233,7 +235,7 @@ sub getWebIterator { && $web ne $session->{webName} ); return 1; }, - {} + data => {}, ); } @@ -296,7 +298,7 @@ sub getField { $data->getRevisionInfo(); } - if ( $Foswiki::Query::Node::isArrayType{$field} ) { + if ( $Foswiki::Meta::isArrayType{$field} ) { # Array type, have to use find my @e = $data->find($field); @@ -459,15 +461,18 @@ sub getListOfWebs { my $webObject; my $prefix = "$web/"; if ( $web =~ m/^(all|on)$/i ) { - $webObject = Foswiki::Meta->new($session); - $prefix = ''; + $webObject = Foswiki::Meta->new( session => $session ); + $prefix = ''; } else { $web = Foswiki::Sandbox::untaint( $web, \&Foswiki::Sandbox::validateWebName ); ASSERT($web) if DEBUG; push( @tmpWebs, $web ); - $webObject = Foswiki::Meta->new( $session, $web ); + $webObject = Foswiki::Meta->new( + session => $session, + web => $web + ); } my $it = $webObject->eachWeb(1); while ( $it->hasNext() ) { @@ -499,7 +504,10 @@ sub getListOfWebs { push( @tmpWebs, $web ); if ( Foswiki::isTrue($recurse) ) { require Foswiki::Meta; - my $webObject = Foswiki::Meta->new( $session, $session->{webName} ); + my $webObject = Foswiki::Meta->new( + session => $session, + web => $session->webName + ); my $it = $webObject->eachWeb( $Foswiki::cfg{EnableHierarchicalWebs} ); while ( $it->hasNext() ) { diff --git a/core/lib/Foswiki/UserMapping.pm b/core/lib/Foswiki/UserMapping.pm index 6c8803ecc8..37568c6727 100644 --- a/core/lib/Foswiki/UserMapping.pm +++ b/core/lib/Foswiki/UserMapping.pm @@ -31,11 +31,9 @@ __Note:__ in all the following documentation, =$cUID= refers to a =cut package Foswiki::UserMapping; - -use strict; -use warnings; +use v5.14; use Assert; -use Error (); +use Foswiki::Exception (); use Foswiki::Func; BEGIN { @@ -45,26 +43,64 @@ BEGIN { } } +use Moo; +use namespace::clean; +extends qw(Foswiki::Object); + +has session => ( + is => 'ro', + weak_ref => 1, + required => 1, +); +has mapping_id => ( + is => 'rw', + default => '', +); +has L2U => ( # login 2 cUID + is => 'rw', + lazy => 1, + clearer => 1, + default => sub { {} }, +); +has U2L => ( # cUID 2 login + is => 'rw', + lazy => 1, + clearer => 1, + default => sub { {} }, +); +has W2U => ( # wikiname 2 cUID + is => 'rw', + lazy => 1, + clearer => 1, + default => sub { {} }, +); +has U2W => ( # cUID 2 wikiname + is => 'rw', + lazy => 1, + clearer => 1, + default => sub { {} }, +); +has U2E => ( # cUID 2 email + is => 'rw', + lazy => 1, + clearer => 1, + default => sub { {} }, +); +has L2P => ( # login 2 password + is => 'rw', + lazy => 1, + clearer => 1, + default => sub { {} }, +); + =begin TML ----++ PROTECTED ClassMethod new ($session, $mapping_id) +---++ PROTECTED ClassMethod new (session => $session, mapping_id => $mapping_id) Construct a user mapping object, using the given mapping id. =cut -sub new { - my ( $class, $session, $mid ) = @_; - my $this = bless( - { - mapping_id => $mid || '', - session => $session, - }, - $class - ); - return $this; -} - =begin TML ---++ ObjectMethod finish() @@ -72,11 +108,11 @@ Break circular references. =cut -sub finish { - my $this = shift; - undef $this->{mapping_id}; - undef $this->{session}; -} +#sub finish { +# my $this = shift; +# undef $this->{mapping_id}; +# undef $this->{session}; +#} =begin TML @@ -182,29 +218,31 @@ alphanumerics and underscores. If you fail to create a new user (for eg your Mapper has read only access),
-    throw Error::Simple('Failed to add user: '.$error);
+    Foswiki::Exception->throw(text => 'Failed to add user: '.$error);
 
where $error is a descriptive string. -Throws an Error::Simple if user adding is not supported (the default). +Throws an Foswiki::Exception if user adding is not supported (the default). =cut sub addUser { - throw Error::Simple('Failed to add user: adding users is not supported'); + Foswiki::Exception->throw( + 'Failed to add user: adding users is not supported'); } =begin TML ---++ ObjectMethod removeUser( $cUID ) -> $boolean -Delete the users entry from this mapper. Throws an Error::Simple if +Delete the users entry from this mapper. Throws an Foswiki::Exception if user removal is not supported (the default). =cut sub removeUser { - throw Error::Simple('Failed to remove user: user removal is not supported'); + Foswiki::Exception->throw( + 'Failed to remove user: user removal is not supported'); } =begin TML @@ -344,10 +382,10 @@ sub groupAllowsChange { ---++ ObjectMethod addToGroup( $cuid, $group, $create ) -> $boolean adds the user specified by the cuid to the group. -Mapper should throws Error::Simple if errors are encountered. For example, +Mapper should throws Foswiki::Exception if errors are encountered. For example, if the group does not exist, and the create flag is not supplied:
-    throw Error::Simple( $this->{session}
+    Foswiki::Exception->throw( text => $this->session
         ->i18n->maketext('Group does not exist and create not permitted')
     ) unless ($create);
 
@@ -362,11 +400,11 @@ sub addUserToGroup { ---++ ObjectMethod removeFromGroup( $cuid, $group ) -> $boolean -Mapper should throws Error::Simple if errors are encountered. For example, +Mapper should throws Foswiki::Exception if errors are encountered. For example, if the user does not exist in the group:
-   throw Error::Simple(
-      $this->{session}->i18n->maketext(
+   Foswiki::Exception->throw(
+      text => $this->session->i18n->maketext(
          'User [_1] not in group, cannot be removed', $cuid
       )
    );
@@ -570,7 +608,8 @@ sub validateRegistrationField {
         if ( length( $_[2] )
             && !( $_[2] =~ m/$Foswiki::cfg{LoginNameFilterIn}/ ) )
         {
-            throw Error::Simple( Foswiki::entityEncode("Invalid $_[1]") );
+            Foswiki::Exception->throw(
+                text => Foswiki::entityEncode("Invalid $_[1]") );
         }
         else {
             return $_[2];
diff --git a/core/lib/Foswiki/Users.pm b/core/lib/Foswiki/Users.pm
index 79461826a6..3ef0346e37 100644
--- a/core/lib/Foswiki/Users.pm
+++ b/core/lib/Foswiki/Users.pm
@@ -76,8 +76,6 @@ BEGIN {
     }
 }
 
-our @_newParameters = qw(session);
-
 has session => (
     is      => 'rw',
     clearer => 1,
@@ -154,7 +152,8 @@ sub BUILD {
       || 'Foswiki::Users::BaseUserMapping';
     eval "require $implBaseUserMappingManager";
     Foswiki::Exception->throw( text => $@ ) if $@;
-    $this->basemapping( $implBaseUserMappingManager->new($session) );
+    $this->basemapping(
+        $implBaseUserMappingManager->new( session => $session ) );
 
     my $implUserMappingManager = $Foswiki::cfg{UserMappingManager};
     $implUserMappingManager = 'Foswiki::Users::TopicUserMapping'
@@ -164,9 +163,10 @@ sub BUILD {
         $this->mapping( $this->basemapping );    #TODO: probly make undef..
     }
     else {
-        eval "require $implUserMappingManager";
-        Foswiki::Exception->throw($@) if $@;
-        $this->mapping( $implUserMappingManager->new($session) );
+        Foswiki::load_package($implUserMappingManager);
+
+        #Foswiki::Exception->throw(text => $@) if $@;
+        $this->mapping( $implUserMappingManager->new( session => $session ) );
     }
 
     $this->loginManager( Foswiki::LoginManager::makeLoginManager($session) );
diff --git a/core/lib/Foswiki/Users/BaseUserMapping.pm b/core/lib/Foswiki/Users/BaseUserMapping.pm
index 3ebbdbe8ec..05feadf450 100755
--- a/core/lib/Foswiki/Users/BaseUserMapping.pm
+++ b/core/lib/Foswiki/Users/BaseUserMapping.pm
@@ -27,18 +27,18 @@ prefix 'BaseUserMapping_'.
 =cut
 
 package Foswiki::Users::BaseUserMapping;
-use strict;
-use warnings;
-
-use Foswiki::UserMapping ();
-our @ISA = ('Foswiki::UserMapping');
+use v5.14;
 
 use Assert;
 use Encode;
-use Error ();
+use Foswiki::Exception ();
 use Digest::MD5 qw(md5_hex);
 use Crypt::PasswdMD5 qw(apache_md5_crypt);
 
+use Moo;
+use namespace::clean;
+extends qw(Foswiki::UserMapping);
+
 BEGIN {
     if ( $Foswiki::cfg{UseLocale} ) {
         require locale;
@@ -51,9 +51,18 @@ our $UNKNOWN_USER_CUID = 'BaseUserMapping_999';
 our %BASE_USERS;
 our %BASE_GROUPS;
 
+has GROUPS => (
+    is      => 'rw',
+    lazy    => 1,
+    default => sub {
+        return {%BASE_GROUPS};
+    },
+);
+has error => ( is => 'rw', default => '', );
+
 =begin TML
 
----++ ClassMethod new ($session)
+---++ ClassMethod new (session => $session)
 
 Construct the BaseUserMapping object
 
@@ -61,8 +70,9 @@ Construct the BaseUserMapping object
 
 # Constructs a new user mapping handler of this type, referring to $session
 # for any required Foswiki services.
-sub new {
-    my ( $class, $session ) = @_;
+around BUILDARGS => sub {
+    my $orig  = shift;
+    my $class = shift;
 
     # $DEFAULT_USER_CUID , $UNKNOWN_USER_CUID, %BASE_USERS and %BASE_GROUPS
     # could be initialised statically, but tests have been written that rely
@@ -116,32 +126,25 @@ sub new {
         #         RegistrationGroup => ['BaseUserMapping_222']
     );
 
-    my $this = $class->SUPER::new( $session, 'BaseUserMapping_' );
     $Foswiki::cfg{Register}{RegistrationAgentWikiName} ||= 'RegistrationAgent';
 
-    # set up our users
-    $this->{L2U} = {};    # login 2 cUID
-    $this->{U2L} = {};    # cUID 2 login
-    $this->{W2U} = {};    # wikiname 2 cUID
-    $this->{U2W} = {};    # cUID 2 wikiname
-    $this->{U2E} = {};    # cUID 2 email
-    $this->{L2P} = {};    # login 2 password
+    return $orig->( $class, @_ );
+};
+
+sub BUILD {
+    my $this = shift;
 
     while ( my ( $k, $v ) = each %BASE_USERS ) {
-        $this->{U2L}->{$k} = $v->{login};
-        $this->{U2W}->{$k} = $v->{wikiname};
-        $this->{U2E}->{$k} = $v->{email} if defined $v->{email};
+        $this->U2L->{$k} = $v->{login};
+        $this->U2W->{$k} = $v->{wikiname};
+        $this->U2E->{$k} = $v->{email} if defined $v->{email};
 
-        $this->{L2U}->{ $v->{login} } = $k;
-        $this->{L2P}->{ $v->{login} } = $v->{password}
+        $this->L2U->{ $v->{login} } = $k;
+        $this->L2P->{ $v->{login} } = $v->{password}
           if defined $v->{password};
 
-        $this->{W2U}->{ $v->{wikiname} } = $k;
+        $this->W2U->{ $v->{wikiname} } = $k;
     }
-
-    %{ $this->{GROUPS} } = %BASE_GROUPS;
-
-    return $this;
 }
 
 =begin TML
@@ -154,17 +157,17 @@ Break circular references.
 # Note to developers; please undef *all* fields in the object explicitly,
 # whether they are references or not. That way this method is "golden
 # documentation" of the live fields in the object.
-sub finish {
-    my $this = shift;
-    undef $this->{U2L};
-    undef $this->{U2W};
-    undef $this->{L2P};
-    undef $this->{U2E};
-    undef $this->{L2U};
-    undef $this->{W2U};
-    undef $this->{GROUPS};
-    $this->SUPER::finish();
-}
+#sub finish {
+#    my $this = shift;
+#    undef $this->{U2L};
+#    undef $this->{U2W};
+#    undef $this->{L2P};
+#    undef $this->{U2E};
+#    undef $this->{L2U};
+#    undef $this->{W2U};
+#    undef $this->{GROUPS};
+#    $this->SUPER::finish();
+#}
 
 =begin TML
 
@@ -192,9 +195,9 @@ the details of the users we specialise in.
 sub handlesUser {
     my ( $this, $cUID, $login, $wikiname ) = @_;
 
-    return 1 if ( defined($cUID)     && defined( $this->{U2L}{$cUID} ) );
-    return 1 if ( defined($login)    && defined( $this->{L2U}{$login} ) );
-    return 1 if ( defined($wikiname) && defined( $this->{W2U}{$wikiname} ) );
+    return 1 if ( defined($cUID)     && defined( $this->U2L->{$cUID} ) );
+    return 1 if ( defined($login)    && defined( $this->L2U->{$login} ) );
+    return 1 if ( defined($wikiname) && defined( $this->W2U->{$wikiname} ) );
 
     return 0;
 }
@@ -213,7 +216,7 @@ characters, and must correspond 1:1 to the login name.
 sub login2cUID {
     my ( $this, $login ) = @_;
 
-    return $this->{L2U}{$login};
+    return $this->L2U->{$login};
 
     #alternative impl - slower, but more re-useable
     #my @list = findUserByWikiName($this, $login);
@@ -231,7 +234,7 @@ converts an internal cUID to that user's login
 
 sub getLoginName {
     my ( $this, $user ) = @_;
-    return $this->{U2L}{$user};
+    return $this->U2L->{$user};
 }
 
 =begin TML
@@ -244,7 +247,7 @@ Map a canonical user name to a wikiname
 
 sub getWikiName {
     my ( $this, $cUID ) = @_;
-    return $this->{U2W}->{$cUID} || getLoginName( $this, $cUID );
+    return $this->U2W->{$cUID} || getLoginName( $this, $cUID );
 }
 
 =begin TML
@@ -259,7 +262,7 @@ sub userExists {
     my ( $this, $cUID ) = @_;
     ASSERT($cUID) if DEBUG;
     return 0 unless defined $cUID;
-    return $this->{U2L}{$cUID};
+    return $this->U2L->{$cUID};
 }
 
 =begin TML
@@ -273,9 +276,9 @@ See baseclass for documentation.
 sub eachUser {
     my ($this) = @_;
 
-    my @list = keys( %{ $this->{U2W} } );
+    my @list = keys( %{ $this->U2W } );
     require Foswiki::ListIterator;
-    return new Foswiki::ListIterator( \@list );
+    return Foswiki::ListIterator->new( list => \@list );
 }
 
 =begin TML
@@ -293,12 +296,12 @@ sub eachGroupMember {
     my $this  = shift;
     my $group = shift;
 
-    my $members = $this->{GROUPS}{$group};
+    my $members = $this->GROUPS->{$group};
 
     #print STDERR "eachGroupMember($group): ".join(',', @{$members});
 
     require Foswiki::ListIterator;
-    return new Foswiki::ListIterator($members);
+    return Foswiki::ListIterator->new( list => $members );
 }
 
 =begin TML
@@ -314,7 +317,7 @@ sub isGroup {
     $name ||= "";
 
     #TODO: what happens to the code if we implement this using an iterator too?
-    return ( $this->{GROUPS}->{$name} );
+    return ( $this->GROUPS->{$name} );
 }
 
 =begin TML
@@ -327,10 +330,10 @@ See baseclass for documentation.
 
 sub eachGroup {
     my ($this) = @_;
-    my @groups = keys( %{ $this->{GROUPS} } );
+    my @groups = keys( %{ $this->GROUPS } );
 
     require Foswiki::ListIterator;
-    return new Foswiki::ListIterator( \@groups );
+    return Foswiki::ListIterator->new( list => \@groups );
 }
 
 =begin TML
@@ -396,7 +399,7 @@ return the addresses of everyone in the group.
 sub getEmails {
     my ( $this, $user ) = @_;
 
-    return $this->{U2E}{$user} || ();
+    return $this->U2E->{$user} || ();
 }
 
 =begin TML
@@ -417,16 +420,16 @@ sub findUserByWikiName {
     else {
 
         # Add additional mappings defined in WikiUsers
-        if ( $this->{W2U}->{$wn} ) {
-            push( @users, $this->{W2U}->{$wn} );
+        if ( $this->W2U->{$wn} ) {
+            push( @users, $this->W2U->{$wn} );
         }
-        elsif ( $this->{L2U}->{$wn} ) {
+        elsif ( $this->L2U->{$wn} ) {
 
            # The wikiname is also a login name for the purposes of this
            # mapping. We have to do this because Foswiki defines access controls
            # in terms of mapped users, and if a wikiname is *missing* from the
            # mapping there is "no such user".
-            push( @users, $this->{L2U}->{$wn} );
+            push( @users, $this->L2U->{$wn} );
         }
     }
     return \@users;
@@ -445,7 +448,7 @@ Returns 1 on success, undef on failure.
 sub checkPassword {
     my ( $this, $login, $pass ) = @_;
 
-    my $hash = $this->{L2P}->{$login};
+    my $hash = $this->L2P->{$login};
 
     # All of the digest / hash routines require bytes
     $pass = Encode::encode_utf8($pass);
@@ -469,8 +472,9 @@ sub checkPassword {
 
     # be a little more helpful to the admin
     if ( $login eq $Foswiki::cfg{AdminUserLogin} && !$hash ) {
-        $this->{error} =
-          'To login as ' . $login . ', you must set {Password} in configure.';
+        $this->error( 'To login as '
+              . $login
+              . ', you must set {Password} in configure.' );
     }
     return 0;
 }
@@ -493,8 +497,8 @@ Otherwise returns 1 on success, undef on failure.
 
 sub setPassword {
     my ( $this, $cUID, $newPassU, $oldPassU ) = @_;
-    throw Error::Simple(
-        'cannot change user passwords using Foswiki::BaseUserMapping');
+    Foswiki::Exception->throw(
+        text => 'cannot change user passwords using Foswiki::BaseUserMapping' );
 }
 
 =begin TML
@@ -511,7 +515,7 @@ returns undef if no error
 sub passwordError {
     my $this = shift;
 
-    return $this->{error};
+    return $this->error;
 }
 
 1;
diff --git a/core/lib/Foswiki/Users/HtPasswdUser.pm b/core/lib/Foswiki/Users/HtPasswdUser.pm
index 9b54521f3c..b40993d63d 100644
--- a/core/lib/Foswiki/Users/HtPasswdUser.pm
+++ b/core/lib/Foswiki/Users/HtPasswdUser.pm
@@ -12,16 +12,16 @@ See documentation of that class for descriptions of the methods of this class.
 =cut
 
 package Foswiki::Users::HtPasswdUser;
-use strict;
-use warnings;
-
-use Foswiki::Users::Password ();
-our @ISA = ('Foswiki::Users::Password');
+use v5.14;
 
 use Assert;
-use Error qw( :try );
+use Try::Tiny;
 use Fcntl qw( :DEFAULT :flock );
 
+use Moo;
+use namespace::clean;
+extends qw(Foswiki::Users::Password);
+
 BEGIN {
     if ( $Foswiki::cfg{UseLocale} ) {
         require locale;
@@ -31,6 +31,15 @@ BEGIN {
 
 our ( $GlobalCache, $GlobalTimestamp );
 
+has LocalCache => (
+    is      => 'rw',
+    clearer => 1,
+);
+has LocalTimestamp => (
+    is      => 'rw',
+    clearer => 1,
+);
+
 sub PasswordData {
     my $this = shift;
 
@@ -39,8 +48,8 @@ sub PasswordData {
         return $HtPasswdUser::GlobalCache;
     }
     else {
-        $this->{LocalCache} = shift if @_;
-        return $this->{LocalCache};
+        $this->LocalCache(shift) if @_;
+        return $this->LocalCache;
     }
 }
 
@@ -51,8 +60,8 @@ sub PasswordTimestamp {
         return $HtPasswdUser::GlobalTimestamp;
     }
     else {
-        $this->{LocalTimestamp} = shift if @_;
-        return $this->{LocalTimestamp};
+        $this->LocalTimestamp(shift) if @_;
+        return $this->LocalTimestamp;
     }
 }
 
@@ -65,8 +74,8 @@ sub ClearCache {
         $HtPasswdUser::GlobalTimestamp = 0;
     }
     else {
-        undef $this->{LocalCache};
-        undef $this->{LocalTimestamp};
+        $this->clear_LocalCache;
+        $this->clear_LocalTimestamp;
     }
 }
 
@@ -74,21 +83,23 @@ sub ClearCache {
 # Set TRACE to 2 for verbose auto-encoding report
 use constant TRACE => 0;
 
-sub new {
-    my ( $class, $session ) = @_;
-    my $this = bless( $class->SUPER::new($session), $class );
-    $this->{error} = undef;
+has SHA    => ( is => 'rw', default => 0, );
+has APR    => ( is => 'rw', default => 0, );
+has BCRYPT => ( is => 'rw', default => 0, );
+
+sub BUILD {
+    my $this = shift;
 
     if ( $Foswiki::cfg{Htpasswd}{AutoDetect} ) {
 
       # For autodetect, soft errors are allowed.  If the .htpasswd file contains
       # a password for an unsupported encoding, it will not match.
         eval 'use Digest::SHA';
-        $this->{SHA} = 1 unless ($@);
+        $this->SHA(1) unless ($@);
         eval 'use Crypt::PasswdMD5';
-        $this->{APR} = 1 unless ($@);
+        $this->APR(1) unless ($@);
         eval 'use Crypt::Eksblowfish::Bcrypt;';
-        $this->{BCRYPT} = 1 unless ($@);
+        $this->BCRYPT(1) unless ($@);
     }
 
     if (   $Foswiki::cfg{Htpasswd}{Encoding} eq 'md5'
@@ -98,7 +109,7 @@ sub new {
         if ( $Foswiki::cfg{AuthRealm} =~ m/\:/ ) {
             print STDERR
 "ERROR: the AuthRealm cannot contain a ':' (colon) as it corrupts the password file\n";
-            throw Error::Simple(
+            Foswiki::Exception->throw( text =>
 "ERROR: the AuthRealm cannot contain a ':' (colon) as it corrupts the password file"
             );
         }
@@ -109,24 +120,25 @@ sub new {
     }
     elsif ( $Foswiki::cfg{Htpasswd}{Encoding} eq 'sha1' ) {
         require Digest::SHA;
-        $this->{SHA} = 1;
+        $this->SHA(1);
     }
     elsif ( $Foswiki::cfg{Htpasswd}{Encoding} eq 'apache-md5' ) {
         require Crypt::PasswdMD5;
-        $this->{APR} = 1;
+        $this->APR(1);
     }
     elsif ( $Foswiki::cfg{Htpasswd}{Encoding} eq 'crypt-md5' ) {
         eval 'use Crypt::PasswdMD5';
-        $this->{APR} = 1 unless ($@);
+        $this->APR(1) unless ($@);
     }
     elsif ( $Foswiki::cfg{Htpasswd}{Encoding} eq 'bcrypt' ) {
         eval 'use Crypt::Eksblowfish::Bcrypt;';
-        $this->{BCRYPT} = 1 unless ($@);
+        $this->BCRYPT(1) unless ($@);
     }
     else {
         print STDERR "ERROR: unknown {Htpasswd}{Encoding} setting : "
           . $Foswiki::cfg{Htpasswd}{Encoding} . "\n";
-        throw Error::Simple( "ERROR: unknown {Htpasswd}{Encoding} setting : "
+        Foswiki::Exception->throw(
+                text => "ERROR: unknown {Htpasswd}{Encoding} setting : "
               . $Foswiki::cfg{Htpasswd}{Encoding}
               . "\n" );
     }
@@ -144,12 +156,12 @@ Break circular references.
 # Note to developers; please undef *all* fields in the object explicitly,
 # whether they are references or not. That way this method is "golden
 # documentation" of the live fields in the object.
-sub finish {
-    my $this = shift;
-    $this->SUPER::finish();
-    undef $this->{LocalCache};
-    undef $this->{LocalTimestamp};
-}
+#sub finish {
+#    my $this = shift;
+#    $this->SUPER::finish();
+#    undef $this->{LocalCache};
+#    undef $this->{LocalTimestamp};
+#}
 
 =begin TML
 
@@ -165,12 +177,12 @@ sub readOnly {
 
     # We expect the path to exist and be writable.
     if ( -e $path && -f _ && -w _ ) {
-        $this->{session}->enterContext('passwords_modifyable');
+        $this->session->enterContext('passwords_modifyable');
         return 0;
     }
 
     # Otherwise, log a problem.
-    $this->{session}->logger->log( 'warning',
+    $this->session->logger->log( 'warning',
             'The password file does not exist or cannot be written.'
           . 'Run =configure= and check the setting of {Htpasswd}{FileName}.'
           . ' New user registration has been disabled until this is corrected.'
@@ -204,7 +216,7 @@ sub _lockPasswdFile {
       || "$Foswiki::cfg{WorkingDir}/htpasswd.lock";
 
     sysopen( my $fh, $lockFileName, O_RDWR | O_CREAT, 0666 )
-      || throw Error::Simple( $lockFileName
+      || Foswiki::Exception->throw( text => $lockFileName
           . ' open or create password lock file failed -'
           . 'check access rights: '
           . $! );
@@ -290,8 +302,8 @@ sub _readPasswd {
 
     my $enc = $Foswiki::cfg{Htpasswd}{CharacterEncoding} || 'utf-8';
     open( $IN_FILE, "<:encoding($enc)", $Foswiki::cfg{Htpasswd}{FileName} )
-      || throw Error::Simple(
-        $Foswiki::cfg{Htpasswd}{FileName} . ' open failed: ' . $! );
+      || Foswiki::Exception->throw(
+        text => $Foswiki::cfg{Htpasswd}{FileName} . ' open failed: ' . $! );
     my $line = '';
     my $tID;
     my $pwcount = 0;
@@ -468,8 +480,10 @@ sub _savePasswd {
 
        # Item4544: Document special format used in .htpasswd for email addresses
         open( my $readme, '>', "$Foswiki::cfg{Htpasswd}{FileName}.README" )
-          or throw Error::Simple(
-            $Foswiki::cfg{Htpasswd}{FileName} . '.README open failed: ' . $! );
+          or
+          Foswiki::Exception->throw( text => $Foswiki::cfg{Htpasswd}{FileName}
+              . '.README open failed: '
+              . $! );
 
         print $readme <<'EoT';
 Foswiki uses a specially crafted .htpasswd file format that should not be
@@ -489,8 +503,8 @@ EoT
 
     my $enc = $Foswiki::cfg{Htpasswd}{CharacterEncoding} || 'utf-8';
     open( $fh, ">:encoding($enc)", $Foswiki::cfg{Htpasswd}{FileName} )
-      || throw Error::Simple(
-        "$Foswiki::cfg{Htpasswd}{FileName} open failed: $!");
+      || Foswiki::Exception->throw(
+        text => "$Foswiki::cfg{Htpasswd}{FileName} open failed: $!" );
     print $fh $content;
 
     close($fh);
@@ -528,8 +542,8 @@ sub encrypt {
 
     if ( $enc eq 'sha1' ) {
 
-        unless ( $this->{SHA} ) {
-            $this->{error} = "Unsupported Encoding";
+        unless ( $this->SHA ) {
+            $this->error("Unsupported Encoding");
             return 0;
         }
 
@@ -568,8 +582,8 @@ sub encrypt {
     }
     elsif ( $enc eq 'apache-md5' ) {
 
-        unless ( $this->{APR} ) {
-            $this->{error} = "Unsupported Encoding";
+        unless ( $this->APR ) {
+            $this->error("Unsupported Encoding");
             return 0;
         }
 
@@ -616,7 +630,7 @@ sub encrypt {
         }
 
         # crypt is not cross-plaform, so use Crypt::PasswdMD5 if it's available
-        if ( $this->{APR} ) {
+        if ( $this->APR ) {
             return Crypt::PasswdMD5::unix_md5_crypt(
                 Foswiki::encode_utf8($passwd),
                 Foswiki::encode_utf8( substr( $salt, 0, 11 ) ) );
@@ -632,8 +646,8 @@ sub encrypt {
 
     }
     elsif ( $enc eq 'bcrypt' ) {
-        unless ( $this->{BCRYPT} ) {
-            $this->{error} = "Unsupported Encoding";
+        unless ( $this->BCRYPT ) {
+            $this->error("Unsupported Encoding");
             return 0;
         }
 
@@ -694,21 +708,21 @@ sub fetchPass {
                 $enc = $db->{$login}->{enc};
             }
             else {
-                $this->{error} = "Login $login invalid";
+                $this->error("Login $login invalid");
                 $ret = undef;
             }
         }
-        catch Error with {
-            my $e = shift;
-            $this->{error} = $!;
+        catch {
+            my $e = $_;
+            $this->error($!);
             print STDERR "ERROR: failed to fetchPass - $! ($e)";
-            $this->{error} = 'unknown error in fetchPass'
-              unless ( $this->{error} && length( $this->{error} ) );
+            $this->error('unknown error in fetchPass')
+              unless ( $this->error && length( $this->error ) );
             return undef;
         };
     }
     else {
-        $this->{error} = 'No user';
+        $this->error('No user');
     }
     return (wantarray) ? ( $ret, $db->{$login} ) : $ret;
 }
@@ -741,7 +755,7 @@ sub setPassword {
         }
     }
     elsif ( $this->fetchPass($login) ) {
-        $this->{error} = $login . ' already exists';
+        $this->error( $login . ' already exists' );
         return 0;
     }
 
@@ -767,19 +781,19 @@ sub setPassword {
         $this->_savePasswd($db);
 
     }
-    catch Error with {
-        my $e = shift;
-        $this->{error} = $!;
+    catch {
+        my $e = $_;
+        $this->error($!);
         print STDERR "ERROR: failed to setPassword - $! ($e)";
-        $this->{error} = 'unknown error in setPassword'
-          unless ( $this->{error} && length( $this->{error} ) );
+        $this->error('unknown error in setPassword')
+          unless ( $this->error && length( $this->error ) );
         return undef;
     }
     finally {
         _unlockPasswdFile($lockHandle) if $lockHandle;
     };
 
-    $this->{error} = undef;
+    $this->clear_error;
     return 1;
 }
 
@@ -797,7 +811,7 @@ Returns 1 on success, undef on failure.
 sub removeUser {
     my ( $this, $login ) = @_;
     my $result = undef;
-    $this->{error} = undef;
+    $this->clear_error;
 
     my $lockHandle;
     try {
@@ -807,7 +821,7 @@ sub removeUser {
         #  - Don't trust cache
         my $db = $this->_readPasswd( 0, 1 );
         unless ( $db->{$login} ) {
-            $this->{error} = 'No such user ' . $login;
+            $this->error( 'No such user ' . $login );
         }
         else {
             delete $db->{$login};
@@ -815,12 +829,12 @@ sub removeUser {
             $result = 1;
         }
     }
-    catch Error with {
+    catch {
         my $e = shift;
-        $this->{error} = $!;
+        $this->error($!);
         print STDERR "ERROR: failed to removeUser - $! ($e)";
-        $this->{error} = 'unknown error in removeUser'
-          unless ( $this->{error} && length( $this->{error} ) );
+        $this->error('unknown error in removeUser')
+          unless ( $this->error && length( $this->error ) );
         return undef;
     }
     finally {
@@ -852,14 +866,14 @@ sub checkPassword {
     my $encryptedPassword = $this->encrypt( $login, $password, 0, $entry );
     return 0 unless ($encryptedPassword);
 
-    $this->{error} = undef;
+    $this->clear_error;
 
     #print STDERR "Checking $pw against $encryptedPassword\n" if (TRACE);
 
     if ( length($pw) != length($encryptedPassword) ) {
 
     #print STDERR "Fail on length mismatch ($pw) vs enc ($encryptedPassword)\n";
-        $this->{error} = 'Invalid user/password';
+        $this->error('Invalid user/password');
         return 0;
     }
     return 1 if ( $pw && ( $encryptedPassword eq $pw ) );
@@ -869,7 +883,7 @@ sub checkPassword {
     # order to reset the password.
     return 1 if ( defined $password && $pw eq '' && $password eq '' );
 
-    $this->{error} = 'Invalid user/password';
+    $this->error('Invalid user/password');
     return 0;
 }
 
@@ -939,9 +953,12 @@ sub setEmails {
 
         $this->_savePasswd($db);
     }
-    finally {
+    catch {
+        # SMELL Rethrow of an exception may be needed.
+        #Foswiki::Exception->rethrow($_);
+      } finally {
         _unlockPasswdFile($lockHandle) if $lockHandle;
-    };
+      };
     return 1;
 }
 
diff --git a/core/lib/Foswiki/Users/Password.pm b/core/lib/Foswiki/Users/Password.pm
index 616b2b774f..006a22ca4e 100644
--- a/core/lib/Foswiki/Users/Password.pm
+++ b/core/lib/Foswiki/Users/Password.pm
@@ -13,11 +13,13 @@ to implement other password handling methods.
 =cut
 
 package Foswiki::Users::Password;
+use v5.14;
 
-use strict;
-use warnings;
 use Assert;
 
+use Moo;
+extends qw(Foswiki::Object);
+
 BEGIN {
     if ( $Foswiki::cfg{UseLocale} ) {
         require locale;
@@ -34,13 +36,15 @@ for any required Foswiki services.
 
 =cut
 
-sub new {
-    my ( $class, $session ) = @_;
-
-    my $this = bless( { session => $session }, $class );
-    $this->{error} = undef;
-    return $this;
-}
+has session => (
+    is       => 'ro',
+    required => 1,
+    weak_ref => 1,
+);
+has error => (
+    is      => 'rw',
+    clearer => 1,
+);
 
 =begin TML
 
@@ -52,11 +56,11 @@ Break circular references.
 # Note to developers; please undef *all* fields in the object explicitly,
 # whether they are references or not. That way this method is "golden
 # documentation" of the live fields in the object.
-sub finish {
-    my $this = shift;
-    undef $this->{error};
-    undef $this->{session};
-}
+#sub finish {
+#    my $this = shift;
+#    undef $this->{error};
+#    undef $this->{session};
+#}
 
 =begin TML
 
@@ -100,7 +104,7 @@ Returns 1 on success, undef on failure.
 
 sub checkPassword {
     my $this = shift;
-    $this->{error} = undef;
+    $this->clear_error;
     return 1;
 }
 
@@ -114,7 +118,7 @@ Delete the users entry.
 
 sub removeUser {
     my $this = shift;
-    $this->{error} = undef;
+    $this->clear_error;
     return 1;
 }
 
@@ -136,7 +140,7 @@ Otherwise returns 1 on success, undef on failure.
 
 sub setPassword {
     my $this = shift;
-    $this->{error} = 'System does not support changing passwords';
+    $this->error('System does not support changing passwords');
     return 1;
 }
 
@@ -169,12 +173,6 @@ method call succeeded.
 
 =cut
 
-sub error {
-    my $this = shift;
-
-    return $this->{error};
-}
-
 =begin TML
 
 ---++ ObjectMethod isManagingEmails() -> $boolean