diff --git a/EditTablePlugin/test/unit/EditTablePlugin/EditTablePluginSuite.pm b/EditTablePlugin/test/unit/EditTablePlugin/EditTablePluginSuite.pm index 4dc40a4d14..3b513776d8 100644 --- a/EditTablePlugin/test/unit/EditTablePlugin/EditTablePluginSuite.pm +++ b/EditTablePlugin/test/unit/EditTablePlugin/EditTablePluginSuite.pm @@ -1,11 +1,9 @@ # See bottom of file for license and copyright information package EditTablePluginSuite; +use v5.14; -use strict; -use warnings; - -use Unit::TestSuite; -our @ISA = 'Unit::TestSuite'; +use Moo; +extends qw(Unit::TestSuite); sub include_tests { return 'EditTablePluginTests' } diff --git a/EditTablePlugin/test/unit/EditTablePlugin/EditTablePluginTests.pm b/EditTablePlugin/test/unit/EditTablePlugin/EditTablePluginTests.pm index f7c497afc1..bfc5111739 100644 --- a/EditTablePlugin/test/unit/EditTablePlugin/EditTablePluginTests.pm +++ b/EditTablePlugin/test/unit/EditTablePlugin/EditTablePluginTests.pm @@ -1,43 +1,42 @@ # See bottom of file for license and copyright information package EditTablePluginTests; -use strict; -use warnings; +use v5.14; # tests for basic formatting -use FoswikiFnTestCase(); -our @ISA = qw( FoswikiFnTestCase ); - -use strict; -use warnings; use Foswiki::UI::Save(); use Foswiki::Plugins::EditTablePlugin(); use Foswiki::Plugins::EditTablePlugin::Core(); use Foswiki::Plugins::EditTablePlugin::EditTableData(); -use Error qw( :try ); +use Try::Tiny; -sub new { - my ( $class, @args ) = @_; - return $class->SUPER::new( 'EditTableFunctions', @args ); -} +use Moo; +use namespace::clean; +extends qw( FoswikiFnTestCase ); + +around BUILDARGS => sub { + my $orig = shift; + return $orig->( @_, testSuite => 'EditTableFunctions' ); +}; -sub set_up { +around set_up => sub { + my $orig = shift; my $this = shift; - $this->SUPER::set_up(); + $orig->( $this, @_ ); # $this->{sup} = $this->{session}->getScriptUrl(0, 'view'); $Foswiki::cfg{AntiSpam}{RobotsAreWelcome} = 1; $Foswiki::cfg{AllowInlineScript} = 0; $Foswiki::cfg{Plugins}{TablePlugin}{DefaultAttributes} = 'tableborder="1" valign="top" headercolor="#fff" headerbg="#687684" headerbgsorted="#334455" databg="#ddd,#edf4f9" databgsorted="#f1f7fc,#ddebf6" tablerules="rows" headerrules="cols"'; - $Foswiki::cfg{Plugins}{EditRowPlugin}{Enabled} = 0; + $Foswiki::cfg{Plugins}{EditRowPlugin}{Enabled} = 0; $Foswiki::cfg{Plugins}{EditTablePlugin}{Enabled} = 1; local $ENV{SCRIPT_NAME} = ''; # required by fake sort URLs in expected text return; -} +}; =pod @@ -66,9 +65,9 @@ can see the nops. sub do_testHtmlOutput { my ( $this, $expected, $actual, $doRender ) = @_; - my $session = $this->{session}; - my $webName = $this->{test_web}; - my $topicName = $this->{test_topic}; + my $session = $this->session; + my $webName = $this->test_web; + my $topicName = $this->test_topic; if ($doRender) { $actual = @@ -98,8 +97,8 @@ A simple edit table in view mode, with 'before' and 'after' text. sub test_render_simple_before_after { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -137,8 +136,8 @@ A simple edit table in view mode, with spaces before table lines. sub test_render_simple_pre { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewAuthUrl = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -180,8 +179,8 @@ A simple rendered edit table. sub test_render_simple { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -219,8 +218,8 @@ Test if saving does not add newlines after the table. sub test_do_not_add_newline { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -255,7 +254,7 @@ INPUT $query->path_info("/$webName/$topicName"); $query->method('POST'); - Foswiki::Func::saveTopic( $this->{test_web}, $this->{test_topic}, undef, + Foswiki::Func::saveTopic( $this->test_web, $this->test_topic, undef, $input ); $this->createNewFoswikiSession( undef, $query ); @@ -265,7 +264,7 @@ INPUT sub { $response->print( Foswiki::Func::expandCommonVariables( - $input, $this->{test_topic}, $this->{test_web}, undef + $input, $this->test_topic, $this->test_web, undef ) ); } @@ -293,8 +292,8 @@ param editbutton. sub test_param_editbutton { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -335,8 +334,8 @@ Editing a simple table. sub test_editSimple { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -387,8 +386,8 @@ Pass param 'format' and edit the table. sub test_param_format_edit { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -410,8 +409,8 @@ INPUT $this->createNewFoswikiSession( undef, $query ); my $result = - Foswiki::Func::expandCommonVariables( $input, $this->{test_topic}, - $this->{test_web}, undef ); + Foswiki::Func::expandCommonVariables( $input, $this->test_topic, + $this->test_web, undef ); my $expected = <<"EXPECTED"; %TABLE{disableallsort="on" databg="#fff"}% @@ -447,8 +446,8 @@ Adding a row and saving the table. sub test_editAddRow { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -474,8 +473,8 @@ INPUT my $expected = ''; my $result = - Foswiki::Func::expandCommonVariables( $input, $this->{test_topic}, - $this->{test_web}, undef ); + Foswiki::Func::expandCommonVariables( $input, $this->test_topic, + $this->test_web, undef ); $expected = <<"EXPECTED"; %TABLE{disableallsort="on" databg="#fff"}% @@ -516,9 +515,10 @@ EXPECTED $this->createNewFoswikiSession( undef, $query ); $result = - Foswiki::Func::expandCommonVariables( $input, $this->{test_topic}, - $this->{test_web}, undef ); + Foswiki::Func::expandCommonVariables( $input, $this->test_topic, + $this->test_web, undef ); + my $test_topic = $this->test_topic; $expected = <<"EXPECTED"; @@ -529,17 +529,17 @@ EXPECTED - - - - - - - - - - -
0
1
+ + + + + + + + + + +
0
1
@@ -560,8 +560,8 @@ EXPECTED sub test_delete_last_row { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -600,10 +600,11 @@ INPUT $this->createNewFoswikiSession( undef, $query ); my $result = - Foswiki::Func::expandCommonVariables( $input, $this->{test_topic}, - $this->{test_web}, undef ); + Foswiki::Func::expandCommonVariables( $input, $this->test_topic, + $this->test_web, undef ); - my $expected = <<"EXPECTED"; + my $test_topic = $this->test_topic; + my $expected = <<"EXPECTED"; @@ -615,25 +616,25 @@ INPUT - - - - - - - - - - - - - - - - - - -
HEADER
FOOTER
+ + + + + + + + + + + + + + + + + + +
HEADER
FOOTER
@@ -660,8 +661,8 @@ Test select dropdown box sub test_param_format_selectbox { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -687,7 +688,8 @@ INPUT Foswiki::Func::expandCommonVariables( $text, $topicName, $webName, undef ); - my $expected = <<"END"; + my $test_topic = $this->test_topic; + my $expected = <<"END"; @@ -696,15 +698,15 @@ INPUT - - - - - - - - - +
+ + + + + + + +
@@ -732,8 +734,8 @@ Test variables inside checkboxes and radio buttons sub test_param_format_variable_expansion_in_checkbox_and_radio_buttons { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubPathSystemWeb = @@ -756,7 +758,8 @@ INPUT Foswiki::Func::expandCommonVariables( $text, $topicName, $webName, undef ); - my $expected = <<"END"; + my $test_topic = $this->test_topic; + my $expected = <<"END"; @@ -765,13 +768,13 @@ INPUT - - - - - - - +
dead, deadly, doom
cool
dead, deadly, doom
cool
+ + + + + +
dead, deadly, doom
cool
dead, deadly, doom
cool
@@ -797,8 +800,8 @@ END sub test_param_format_with_variables { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); @@ -831,12 +834,12 @@ INPUT - - - - - - + + + + + +
DONE $topicName
DONE $topicName
@@ -862,15 +865,15 @@ Format parameter with $percntY$percnt macros. Edit the table. sub test_param_format_with_macro_placeholders_edit { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = Foswiki::Func::getUrlHost() . Foswiki::Func::getPubUrlPath() . '/' . $Foswiki::cfg{SystemWebName}; - my $userName = $this->{users_web} . '.' . 'WikiGuest'; + my $userName = $this->users_web . '.' . 'WikiGuest'; my $text = <<"INPUT"; %EDITTABLE{format="| text, 30, \$percntY\$percnt | text, 30, \$percntTOPIC\$percnt |"}% @@ -889,7 +892,8 @@ INPUT Foswiki::Func::expandCommonVariables( $text, $topicName, $webName, undef ); - my $expected = <<"END"; + my $test_topic = $this->test_topic; + my $expected = <<"END"; @@ -898,13 +902,13 @@ INPUT - - - - - - - +
+ + + + + +
@@ -932,8 +936,8 @@ Saving a simple table. sub test_save { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -967,7 +971,7 @@ INPUT $query->path_info("/$webName/$topicName"); $query->method('POST'); - Foswiki::Func::saveTopic( $this->{test_web}, $this->{test_topic}, undef, + Foswiki::Func::saveTopic( $this->test_web, $this->test_topic, undef, $input ); $this->createNewFoswikiSession( undef, $query ); @@ -977,7 +981,7 @@ INPUT sub { $response->print( Foswiki::Func::expandCommonVariables( - $input, $this->{test_topic}, $this->{test_web}, undef + $input, $this->test_topic, $this->test_web, undef ) ); } @@ -1006,8 +1010,8 @@ DEPRECATED: saving a table with changes through params will be changed sub _DEPRECATED_test_param_headerrows_and_footerrows_save { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -1046,7 +1050,7 @@ INPUT $query->path_info("/$webName/$topicName"); $query->method('POST'); - Foswiki::Func::saveTopic( $this->{test_web}, $this->{test_topic}, undef, + Foswiki::Func::saveTopic( $this->test_web, $this->test_topic, undef, $input ); $this->createNewFoswikiSession( undef, $query ); @@ -1056,7 +1060,7 @@ INPUT sub { $response->print( Foswiki::Func::expandCommonVariables( - $input, $this->{test_topic}, $this->{test_web}, undef + $input, $this->test_topic, $this->test_web, undef ) ); } @@ -1092,8 +1096,8 @@ DEPRECATED: saving a table with changes through params will be changed sub _DEPRECATED_test_param_headerrows_and_footerrows_save_table_above { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -1133,7 +1137,7 @@ INPUT $query->path_info("/$webName/$topicName"); $query->method('POST'); - Foswiki::Func::saveTopic( $this->{test_web}, $this->{test_topic}, undef, + Foswiki::Func::saveTopic( $this->test_web, $this->test_topic, undef, $input ); $this->createNewFoswikiSession( undef, $query ); @@ -1143,7 +1147,7 @@ INPUT sub { $response->print( Foswiki::Func::expandCommonVariables( - $input, $this->{test_topic}, $this->{test_web}, undef + $input, $this->test_topic, $this->test_web, undef ) ); } @@ -1175,8 +1179,8 @@ Test if cells with a space do not voided (and rendered with a colspan): text fie sub test_keepSpacesInEmptyCellsWithTexts { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -1205,7 +1209,7 @@ INPUT ); $query->path_info("/$webName/$topicName"); $query->method('POST'); - Foswiki::Func::saveTopic( $this->{test_web}, $this->{test_topic}, undef, + Foswiki::Func::saveTopic( $this->test_web, $this->test_topic, undef, $input ); $this->createNewFoswikiSession( undef, $query ); my $response = Unit::Response->new(); @@ -1213,7 +1217,7 @@ INPUT sub { $response->print( Foswiki::Func::expandCommonVariables( - $input, $this->{test_topic}, $this->{test_web}, undef + $input, $this->test_topic, $this->test_web, undef ) ); } @@ -1238,8 +1242,8 @@ Test if cells with a space do not voided (and rendered with a colspan): date fie sub test_keepSpacesInEmptyCellsWithDates { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -1269,7 +1273,7 @@ INPUT ); $query->path_info("/$webName/$topicName"); $query->method('POST'); - Foswiki::Func::saveTopic( $this->{test_web}, $this->{test_topic}, undef, + Foswiki::Func::saveTopic( $this->test_web, $this->test_topic, undef, $input ); $this->createNewFoswikiSession( undef, $query ); my $response = Unit::Response->new(); @@ -1277,7 +1281,7 @@ INPUT sub { $response->print( Foswiki::Func::expandCommonVariables( - $input, $this->{test_topic}, $this->{test_web}, undef + $input, $this->test_topic, $this->test_web, undef ) ); } @@ -1306,8 +1310,8 @@ If a merge feature is added please pay attention to Item5217 sub test_addSpacesToEmptyCells { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -1335,7 +1339,7 @@ INPUT ); $query->path_info("/$webName/$topicName"); $query->method('POST'); - Foswiki::Func::saveTopic( $this->{test_web}, $this->{test_topic}, undef, + Foswiki::Func::saveTopic( $this->test_web, $this->test_topic, undef, $input ); $this->createNewFoswikiSession( undef, $query ); my $response = Unit::Response->new(); @@ -1343,7 +1347,7 @@ INPUT sub { $response->print( Foswiki::Func::expandCommonVariables( - $input, $this->{test_topic}, $this->{test_web}, undef + $input, $this->test_topic, $this->test_web, undef ) ); } @@ -1368,8 +1372,8 @@ Test if TML formatting is rendered. sub test_TMLFormattingInsideCell_BR { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -1394,11 +1398,11 @@ INPUT - - - - -
blablabla
there's still a bug
lurking around
italic
bold
+ + + blablabla
there's still a bug
lurking around
italic
bold + + @@ -1420,8 +1424,8 @@ Test if TML formatting is rendered with
tags. sub test_TMLFormattingInsideCell_tag_br { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -1446,11 +1450,11 @@ INPUT - - - - -
blablabla
there's still a bug
lurking around
italic
bold
+ + + blablabla
there's still a bug
lurking around
italic
bold + + @@ -1471,8 +1475,8 @@ Test if stars are preserved after saving. sub test_keepStars { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -1499,7 +1503,7 @@ INPUT ); $query->path_info("/$webName/$topicName"); $query->method('POST'); - Foswiki::Func::saveTopic( $this->{test_web}, $this->{test_topic}, undef, + Foswiki::Func::saveTopic( $this->test_web, $this->test_topic, undef, $input ); $this->createNewFoswikiSession( undef, $query ); my $response = Unit::Response->new(); @@ -1507,7 +1511,7 @@ INPUT sub { $response->print( Foswiki::Func::expandCommonVariables( - $input, $this->{test_topic}, $this->{test_web}, undef + $input, $this->test_topic, $this->test_web, undef ) ); } @@ -1530,8 +1534,8 @@ Test if linebreaks inside input fields are kept. sub test_lineBreaksInsideInputField { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -1558,7 +1562,7 @@ INPUT ); $query->path_info("/$webName/$topicName"); $query->method('POST'); - Foswiki::Func::saveTopic( $this->{test_web}, $this->{test_topic}, undef, + Foswiki::Func::saveTopic( $this->test_web, $this->test_topic, undef, $input ); $this->createNewFoswikiSession( undef, $query ); my $response = Unit::Response->new(); @@ -1566,7 +1570,7 @@ INPUT sub { $response->print( Foswiki::Func::expandCommonVariables( - $input, $this->{test_topic}, $this->{test_web}, undef + $input, $this->test_topic, $this->test_web, undef ) ); } @@ -1588,8 +1592,8 @@ NEWEXPECTED sub test_param_buttonrow_top { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -1623,8 +1627,8 @@ END sub test_param_buttonrow_top_edit { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -1685,8 +1689,8 @@ Test if saving is keeping tags inside table. sub test_save_with_verbatim_inside_table { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -1720,7 +1724,7 @@ INPUT $query->path_info("/$webName/$topicName"); $query->method('POST'); - Foswiki::Func::saveTopic( $this->{test_web}, $this->{test_topic}, undef, + Foswiki::Func::saveTopic( $this->test_web, $this->test_topic, undef, $input ); $this->createNewFoswikiSession( undef, $query ); @@ -1730,7 +1734,7 @@ INPUT sub { $response->print( Foswiki::Func::expandCommonVariables( - $input, $this->{test_topic}, $this->{test_web}, undef + $input, $this->test_topic, $this->test_web, undef ) ); } @@ -1757,8 +1761,8 @@ Test if saving is keeping tags outside of tables. sub test_save_with_verbatim_in_topic { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -1795,7 +1799,7 @@ INPUT $query->path_info("/$webName/$topicName"); $query->method('POST'); - Foswiki::Func::saveTopic( $this->{test_web}, $this->{test_topic}, undef, + Foswiki::Func::saveTopic( $this->test_web, $this->test_topic, undef, $input ); $this->createNewFoswikiSession( undef, $query ); @@ -1805,7 +1809,7 @@ INPUT sub { $response->print( Foswiki::Func::expandCommonVariables( - $input, $this->{test_topic}, $this->{test_web}, undef + $input, $this->test_topic, $this->test_web, undef ) ); } @@ -1837,8 +1841,7 @@ sub test_INCLUDE_view { # Create topic to include my $includedTopic = "TopicToInclude"; - Foswiki::Func::saveTopic( $this->{test_web}, $includedTopic, undef, - <<'THIS'); + Foswiki::Func::saveTopic( $this->test_web, $includedTopic, undef, <<'THIS'); %EDITTABLE{ format="| row, -1 | text, 20, init | select, 1, not started, starting, ongoing, completed | checkbox, 3,:-),:-I,:-( | date, 20 |" changerows="on" quietsave="on"}% | *URL* | *Name* | *By* | *Comment* | *Timestamp* | | 1 | Unified field theory | not started | :-) , :-I , :-( | 1 Apr 2012 | @@ -1848,8 +1851,8 @@ sub test_INCLUDE_view { THIS # include this in our test topic - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuthTestTopic = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $viewUrlAuthOtherTopic = @@ -1924,21 +1927,19 @@ sub test_INCLUDE_include { # Create topic with table definition my $tableDefTopic = "QmsCommentTable"; - Foswiki::Func::saveTopic( $this->{test_web}, $tableDefTopic, undef, - <<'THIS'); + Foswiki::Func::saveTopic( $this->test_web, $tableDefTopic, undef, <<'THIS'); %EDITTABLE{ header="|* Section *|* Description *|* Severity *|* Status *|* Originator & Date *|" format="| text, 10 | textarea, 10x60 | select, 1, Major, Minor, Note | select, 1, Originated, Assessed, Performed, Rejected | text, 20 |" changerows="on" }% THIS my $includeTopic = "ProcedureSysarch000Comments"; - Foswiki::Func::saveTopic( $this->{test_web}, $includeTopic, undef, - <<'THIS'); + Foswiki::Func::saveTopic( $this->test_web, $includeTopic, undef, <<'THIS'); %EDITTABLE{ include="QmsCommentTable" }% |*Section*|*Description*|*Severity*|*Status*|*Originator & Date*| THIS # include this in our test topic - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuthTestTopic = Foswiki::Func::getScriptUrl( $webName, $includeTopic, 'viewauth' ); @@ -1981,8 +1982,8 @@ Test if macro EDITCELL is preserved after saving sub test_macro_EDITCELL_save { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -2021,7 +2022,7 @@ INPUT $query->path_info("/$webName/$topicName"); $query->method('POST'); - Foswiki::Func::saveTopic( $this->{test_web}, $this->{test_topic}, undef, + Foswiki::Func::saveTopic( $this->test_web, $this->test_topic, undef, $input ); $this->createNewFoswikiSession( undef, $query ); @@ -2031,7 +2032,7 @@ INPUT sub { $response->print( Foswiki::Func::expandCommonVariables( - $input, $this->{test_topic}, $this->{test_web}, undef + $input, $this->test_topic, $this->test_web, undef ) ); } @@ -2063,8 +2064,8 @@ Tests if CALC is rendered in view mode, if CALC is outside an EditTable sub test_CALC_in_table_other_than_EDITTABLE { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -2086,8 +2087,8 @@ sub test_CALC_in_table_other_than_EDITTABLE { '; my $result = - Foswiki::Func::expandCommonVariables( $input, $this->{test_topic}, - $this->{test_web}, undef ); + Foswiki::Func::expandCommonVariables( $input, $this->test_topic, + $this->test_web, undef ); my $expected = ' | *Item Description* | *Qty* | *Reason* | *Unit Price* | *Total Price* | | Hej Ho | 4 | Hello | 50000 | 200000 | @@ -2130,9 +2131,9 @@ Test if TablePlugin parameters are read if the tag is on the same line as EDITTA sub test_TABLE_on_same_line_as_EDITTABLE_TABLE_last { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; - my $cgi = $this->{request}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; + my $cgi = $this->request; my $url = $cgi->url( -absolute => 1 ); my $viewUrlAuth = @@ -2150,7 +2151,8 @@ sub test_TABLE_on_same_line_as_EDITTABLE_TABLE_last { my $result = Foswiki::Func::expandCommonVariables( $input, $topicName, $webName ); - my $expected = <<"EXPECTED"; + my $test_topic = $this->test_topic; + my $expected = <<"EXPECTED";
  • Set MYNAMES = Ed, Kenneth,Benny
  • Set EXTRACT = R0:C1..R0:C-1 @@ -2164,27 +2166,27 @@ sub test_TABLE_on_same_line_as_EDITTABLE_TABLE_last { - - - - - - - - - - - - - - - - - - - - -
    StartdateSorted ascending Stopdate Who What/Where Icon Details
    3 Jan 2008 22 Jan 2008 Benny Vacation smile %EXTRACT%
    + + + + + + + + + + + + + + + + + + + + +
    StartdateSorted ascending Stopdate Who What/Where Icon Details
    3 Jan 2008 22 Jan 2008 Benny Vacation smile %EXTRACT%
    @@ -2206,9 +2208,9 @@ Test if TablePlugin parameters are read if the tag is on the same line as EDITTA sub test_TABLE_on_same_line_as_EDITTABLE_TABLE_first { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; - my $cgi = $this->{request}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; + my $cgi = $this->request; my $url = $cgi->url( -absolute => 1 ); my $viewUrlAuth = @@ -2226,7 +2228,8 @@ sub test_TABLE_on_same_line_as_EDITTABLE_TABLE_first { my $result = Foswiki::Func::expandCommonVariables( $input, $topicName, $webName ); - my $expected = <<"EXPECTED"; + my $test_topic = $this->test_topic; + my $expected = <<"EXPECTED";
    • Set MYNAMES = Ed, Kenneth,Benny
    • Set EXTRACT = R0:C1..R0:C-1 @@ -2240,27 +2243,27 @@ sub test_TABLE_on_same_line_as_EDITTABLE_TABLE_first { - - - - - - - - - - - - - - - - - - - - -
      StartdateSorted ascending Stopdate Who What/Where Icon Details
      3 Jan 2008 22 Jan 2008 Benny Vacation smile %EXTRACT%
      + + + + + + + + + + + + + + + + + + + + +
      StartdateSorted ascending Stopdate Who What/Where Icon Details
      3 Jan 2008 22 Jan 2008 Benny Vacation smile %EXTRACT%
      @@ -2282,8 +2285,8 @@ Tests the substitution of SpreadSheetPlugin formulas by 'CALC' in edit mode. sub test_CALC_substitution { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -2307,8 +2310,8 @@ INPUT $this->createNewFoswikiSession( undef, $query ); my $result = - Foswiki::Func::expandCommonVariables( $input, $this->{test_topic}, - $this->{test_web}, undef ); + Foswiki::Func::expandCommonVariables( $input, $this->test_topic, + $this->test_web, undef ); my $expected = ' %TABLE{disableallsort="on" databg="#fff"}% @@ -2345,8 +2348,8 @@ Parameter changerows sub test_param_changerows_off { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -2368,8 +2371,8 @@ INPUT $this->createNewFoswikiSession( undef, $query ); my $result = - Foswiki::Func::expandCommonVariables( $input, $this->{test_topic}, - $this->{test_web}, undef ); + Foswiki::Func::expandCommonVariables( $input, $this->test_topic, + $this->test_web, undef ); my $expected = <<"EXPECTED"; %TABLE{disableallsort="on" databg="#fff"}% @@ -2403,8 +2406,8 @@ Test if saving is keeping ENCODE parameters sub test_save_with_encode_param_and_footerrows { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = @@ -2441,7 +2444,7 @@ INPUT $query->path_info("/$webName/$topicName"); $query->method('POST'); - Foswiki::Func::saveTopic( $this->{test_web}, $this->{test_topic}, undef, + Foswiki::Func::saveTopic( $this->test_web, $this->test_topic, undef, $input ); $this->createNewFoswikiSession( undef, $query ); @@ -2451,7 +2454,7 @@ INPUT sub { $response->print( Foswiki::Func::expandCommonVariables( - $input, $this->{test_topic}, $this->{test_web}, undef + $input, $this->test_topic, $this->test_web, undef ) ); } @@ -2480,8 +2483,8 @@ This TML has caused infinite recursion in Foswiki 1.0.4. sub test_render_simple_with_verbatim_and_unfinished_table_rows { my $this = shift; - my $topicName = $this->{test_topic}; - my $webName = $this->{test_web}; + my $topicName = $this->test_topic; + my $webName = $this->test_web; my $viewUrlAuth = Foswiki::Func::getScriptUrl( $webName, $topicName, 'viewauth' ); my $pubUrlSystemWeb = diff --git a/UnitTestContrib/lib/Unit/Response.pm b/UnitTestContrib/lib/Unit/Response.pm index 653e584d6f..9ed528082c 100644 --- a/UnitTestContrib/lib/Unit/Response.pm +++ b/UnitTestContrib/lib/Unit/Response.pm @@ -26,9 +26,9 @@ BEGIN { $response = $t->response; return $t; }; - my $_finish = \&Foswiki::finish; - *Foswiki::finish = sub { - $_finish->(@_); + my $_demolish = \&Foswiki::DEMOLISH; + *Foswiki::demolish = sub { + $_demolish->(@_); undef $response; }; use warnings 'redefine'; diff --git a/UnitTestContrib/test/unit/AccessControlTests.pm b/UnitTestContrib/test/unit/AccessControlTests.pm index aecf2bcb02..4ae7115703 100644 --- a/UnitTestContrib/test/unit/AccessControlTests.pm +++ b/UnitTestContrib/test/unit/AccessControlTests.pm @@ -50,7 +50,7 @@ around set_up => sub { $Foswiki::cfg{DefaultUserWikiName} ); $topicObject->text(''); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $this->registerUser( 'white', 'Mr', "White", 'white@example.com' ); $MrWhite = $this->session->users->getCanonicalUserID('white'); $this->registerUser( 'blue', 'Mr', "Blue", 'blue@example.com' ); @@ -71,7 +71,7 @@ around set_up => sub { * Set ALLOWTOPICVIEW = $users_web.ReservoirDogsGroup THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; return; }; @@ -95,7 +95,7 @@ sub DENIED { "$user $mode $web.$topic" ); } - $topicObject->finish(); + undef $topicObject; return; } @@ -119,7 +119,7 @@ sub PERMITTED { "$user $mode $web.$topic" ); } - $topicObject->finish(); + undef $topicObject; return; } @@ -141,7 +141,7 @@ If DENYTOPIC is set to a list of wikinames * Set DENYTOPICVIEW = ,,MrYellow,,$users_web.MrOrange,%USERSWEB%.ReservoirDogsGroup,,, THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $this->createNewFoswikiSession(); $this->PERMITTED( "VIEW", $MrGreen ); @@ -164,7 +164,7 @@ If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) * Set DENYTOPICVIEW= THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $this->createNewFoswikiSession(); $this->PERMITTED( "VIEW", $MrGreen ); @@ -187,7 +187,7 @@ If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) * Set DENYTOPICVIEW = THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $this->createNewFoswikiSession(); $this->PERMITTED( "VIEW", $MrGreen ); @@ -210,7 +210,7 @@ If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) * Set DENYTOPICVIEW = MrBlue THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $this->createNewFoswikiSession(); $this->PERMITTED( "VIEW", $MrGreen ); @@ -234,7 +234,7 @@ If ALLOWTOPIC is set * Set ALLOWTOPICVIEW = %USERSWEB%.MrOrange THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $this->createNewFoswikiSession(); $this->PERMITTED( "VIEW", $MrOrange ); @@ -259,7 +259,7 @@ If ALLOWTOPIC is set * Set ALLOWTOPICVIEW = %USERSWEB%.MrOrange THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; my $topicquery = Unit::Request->new( initializer => "" ); $topicquery->path_info( "/" . $this->test_web . "/" . $this->test_topic ); @@ -293,7 +293,7 @@ If ALLOWTOPIC is set * Set ALLOWTOPICVIEW = %USERSWEB%.MrOrange THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # renew Foswiki, so WebPreferences gets re-read $this->createNewFoswikiSession(); @@ -331,7 +331,7 @@ THIS } ); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # renew Foswiki, so WebPreferences gets re-read $this->createNewFoswikiSession(); @@ -361,7 +361,7 @@ If DENYWEB is set to a list of wikiname * Set DENYWEBVIEW = $users_web.MrOrange %USERSWEB%.MrBlue THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # renew Foswiki, so WebPreferences gets re-read $this->createNewFoswikiSession(); @@ -369,7 +369,7 @@ THIS Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); $topicObject->text("Null points"); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $this->DENIED( "VIEW", $MrOrange ); $this->PERMITTED( "VIEW", $MrGreen ); @@ -393,7 +393,7 @@ If DENYWEB is set to a list of wikiname * Set DENYWEBVIEW = $users_web.MrOrange %USERSWEB%.MrBlue THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # renew Foswiki, so WebPreferences gets re-read $this->createNewFoswikiSession(); @@ -405,7 +405,7 @@ If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) * Set DENYTOPICVIEW = MrWhite THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $this->DENIED( "VIEW", $MrOrange ); $this->PERMITTED( "VIEW", $MrGreen ); @@ -429,7 +429,7 @@ If DENYWEB is set to a list of wikiname * Set DENYWEBVIEW = $users_web.MrOrange %USERSWEB%.MrBlue THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; ($topicObject) = Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); @@ -439,7 +439,7 @@ If DENYTOPIC is set to empty string * Set DENYTOPICVIEW = THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # Verify that the new "empty deny" rule is ignored # Also passes on Foswiki <1.2 @@ -482,7 +482,7 @@ If DENYWEB is set to the wildcard * Set DENYWEBVIEW = * THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; ($topicObject) = Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); @@ -494,7 +494,7 @@ Except ALLOW at the topic will override DENY at web. THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # renew Foswiki, so WebPreferences gets re-read $this->createNewFoswikiSession(); @@ -520,7 +520,7 @@ If DENYWEB is set to a list of wikiname * Set DENYWEBVIEW = $users_web.MrOrange %USERSWEB%.MrBlue THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; ($topicObject) = Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); @@ -530,7 +530,7 @@ If DENYTOPIC is set to empty string * Set ALLOWTOPICVIEW = * THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # Verify that the new "empty deny" rule is ignored # Also passes on Foswiki <1.2 @@ -561,7 +561,7 @@ If DENYTOPIC is set to empty string * Set ALLOWTOPICVIEW = $users_web.MrOrange %USERSWEB%.MrBlue THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # renew Foswiki, so WebPreferences gets re-read $this->createNewFoswikiSession(); @@ -589,7 +589,7 @@ If ALLOWWEB is set to a list of wikinames THIS ); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # renew Foswiki, so WebPreferences gets re-read $this->createNewFoswikiSession(); @@ -597,7 +597,7 @@ THIS Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); $topicObject->text("Null points"); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $this->DENIED( "VIEW", $MrOrange ); $this->PERMITTED( "VIEW", $MrGreen ); $this->PERMITTED( "VIEW", $MrYellow ); @@ -621,7 +621,7 @@ If ALLOWTOPIC is set THIS ); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $this->createNewFoswikiSession(); $this->PERMITTED( "VIEW", $MrOrange ); $this->DENIED( "VIEW", $MrGreen ); @@ -660,13 +660,13 @@ THIS Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); $topicObject->text($text); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $this->createNewFoswikiSession(); ($topicObject) = Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); $this->_checkSettings($topicObject); - $topicObject->finish(); + undef $topicObject; return; } @@ -686,14 +686,14 @@ sub test_setInMETA { }; $topicObject->putKeyed( 'PREFERENCE', $args ); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $this->createNewFoswikiSession(); ($topicObject) = Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); $this->_checkSettings($topicObject); - $topicObject->finish(); + undef $topicObject; return; } @@ -716,13 +716,13 @@ THIS }; $topicObject->putKeyed( 'PREFERENCE', $args ); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $this->createNewFoswikiSession(); ($topicObject) = Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); $this->_checkSettings($topicObject); - $topicObject->finish(); + undef $topicObject; return; } @@ -739,7 +739,7 @@ sub test_subweb_controls_override_parent { Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); $topicObject->text("Nowt"); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; ($topicObject) = Foswiki::Func::readTopic( $this->test_web, @@ -748,18 +748,18 @@ sub test_subweb_controls_override_parent { * Set ALLOWWEBVIEW = MrGreen THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # Now build a subweb with view restricted to MrOrange my $webObject = $this->populateNewWeb($subweb); - $webObject->finish(); + undef $webObject; ($topicObject) = Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); $topicObject->text(<<'THIS'); * Set ALLOWWEBVIEW = MrOrange THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # Ensure that MrOrange can read the subweb and MrGreen the parent web $this->createNewFoswikiSession(); @@ -788,17 +788,17 @@ sub test_subweb_inherits_from_parent { * Set FINALPREFERENCES = ALLOWWEBVIEW THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # Now build a subweb with no restrictions my $webObject = $this->populateNewWeb($subweb); - $webObject->finish(); + undef $webObject; ($topicObject) = Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); $topicObject->text(<<'THIS'); THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $this->createNewFoswikiSession(); $this->PERMITTED( "VIEW", $MrGreen, $subweb ); @@ -826,18 +826,18 @@ sub test_finalised_parent_overrides_subweb { * Set FINALPREFERENCES = ALLOWWEBVIEW THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # Now build a subweb with view restricted to MrOrange my $webObject = $this->populateNewWeb($subweb); - $webObject->finish(); + undef $webObject; ($topicObject) = Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); $topicObject->text(<<'THIS'); * Set ALLOWWEBVIEW = MrOrange THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $this->createNewFoswikiSession(); $this->DENIED( "VIEW", $MrOrange, $subweb ); @@ -866,7 +866,7 @@ anchor is preserved after login. * Set ALLOWTOPICVIEW = MrYellow THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # Request the page with the full UI my $query = Unit::Request->new( diff --git a/UnitTestContrib/test/unit/AddressTests.pm b/UnitTestContrib/test/unit/AddressTests.pm index af15d579b4..7b67d4e8cf 100644 --- a/UnitTestContrib/test/unit/AddressTests.pm +++ b/UnitTestContrib/test/unit/AddressTests.pm @@ -283,7 +283,7 @@ around set_up => sub { $this->test_topicObject( Foswiki::Func::readTopic( $this->test_web, $this->test_topic ) ); if ( $this->check_dependency('Foswiki,>=,1.2') ) { - require Foswiki::Address; + Foswiki::load_class('Foswiki::Address'); } return; @@ -387,8 +387,7 @@ sub test_roundtrips { print STDERR "Testing: $testname\n" if TRACE; $this->assert( $parsedaddrObj->equiv( $testitem->{addrObj} ), $testname ); - $parsedaddrObj->finish(); - $testitem->{addrObj}->finish(); + delete $testitem->{addrObj}; } return; @@ -419,8 +418,6 @@ sub gen_testspec_fns { . ' from non-equivalent: ' . $addrObj->stringify() ); $this->assert_str_equals( $parsedaddrObj->type(), $test->{type} ); - $parsedaddrObj->finish(); - $addrObj->finish(); return; }; @@ -561,7 +558,7 @@ sub test_meta2 { $this->assert( $parsedaddrObj->equiv($addrObj) ); $this->assert( $parsedaddrObj->type() eq 'metakey' ); $parsedaddrObj->tompath( [ 'META', 'FIELD', 2 ] ); - $this->assert( $parsedaddrObj->type() eq 'metamember' ); + $this->assert_equals( 'metamember', $parsedaddrObj->type() ); $parsedaddrObj->tompath( [ 'META', 'FIELD' ] ); $this->assert( $parsedaddrObj->type() eq 'metatype' ); $parsedaddrObj->tompath( ['META'] ); @@ -844,10 +841,10 @@ sub test_attachment_getsetters { $addrObj->attachment('Attachment.pdf'); $this->assert( $addrObj->type() eq 'attachment' ); $this->assert( $addrObj->isA('attachment') ); - $this->assert( $addrObj->attachment() eq 'Attachment.pdf', + $this->assert_equals( 'Attachment.pdf', $addrObj->attachment(), + $addrObj->stringify() ); + $this->assert_equals( "$test_web/SubWeb.Topic/Attachment.pdf\@2", $addrObj->stringify() ); - $this->assert( - $addrObj->stringify() eq "$test_web/SubWeb.Topic/Attachment.pdf\@2" ); $parsedaddrObj = Foswiki::Address->new( string => "$test_web/SubWeb.Topic/Attachment.pdf\@2", ); diff --git a/UnitTestContrib/test/unit/AdminOnlyAccessControlTests.pm b/UnitTestContrib/test/unit/AdminOnlyAccessControlTests.pm index b17fc4fa2e..0ccf562a05 100644 --- a/UnitTestContrib/test/unit/AdminOnlyAccessControlTests.pm +++ b/UnitTestContrib/test/unit/AdminOnlyAccessControlTests.pm @@ -68,7 +68,7 @@ around set_up => sub { $Foswiki::cfg{DefaultUserWikiName} ); $topicObject->text(''); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $this->registerUser( 'white', 'Mr', "White", 'white@example.com' ); $MrWhite = $this->session->users->getCanonicalUserID('white'); $this->registerUser( 'blue', 'Mr', "Blue", 'blue@example.com' ); @@ -88,7 +88,7 @@ around set_up => sub { * Set GROUP = MrWhite, $users_web.MrBlue THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; return; }; @@ -112,7 +112,6 @@ sub DENIED { "$user $mode $web.$topic" ); } - $topicObject->finish(); return; } @@ -136,7 +135,6 @@ sub PERMITTED { "$user $mode $web.$topic" ); } - $topicObject->finish(); return; } @@ -158,7 +156,7 @@ If DENYTOPIC is set to a list of wikinames * Set DENYTOPICVIEW = ,,MrYellow,,$users_web.MrOrange,%USERSWEB%.ReservoirDogsGroup,,, THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; $this->createNewFoswikiSession(); @@ -184,7 +182,7 @@ If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) * Set DENYTOPICVIEW= THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; $this->createNewFoswikiSession(); @@ -209,7 +207,7 @@ If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) * Set DENYTOPICVIEW = THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; $this->createNewFoswikiSession(); @@ -234,7 +232,7 @@ If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) * Set DENYTOPICVIEW = MrBlue THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; $this->createNewFoswikiSession(); @@ -260,7 +258,7 @@ If ALLOWTOPIC is set * Set ALLOWTOPICVIEW = %USERSWEB%.MrOrange THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; $this->createNewFoswikiSession(); @@ -287,7 +285,7 @@ If ALLOWTOPIC is set * Set ALLOWTOPICVIEW = %USERSWEB%.MrOrange THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; my $topicquery = Unit::Request->new( initializer => "" ); $topicquery->path_info( "/" . $this->test_web . "/" . $this->test_topic ); @@ -324,7 +322,7 @@ If ALLOWTOPIC is set * Set ALLOWTOPICVIEW = %USERSWEB%.MrOrange THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # renew Foswiki, so WebPreferences gets re-read $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; @@ -365,7 +363,7 @@ THIS } ); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # renew Foswiki, so WebPreferences gets re-read $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; @@ -398,7 +396,7 @@ If DENYWEB is set to a list of wikiname * Set DENYWEBVIEW = $users_web.MrOrange %USERSWEB%.MrBlue THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # renew Foswiki, so WebPreferences gets re-read $this->createNewFoswikiSession(); @@ -406,7 +404,7 @@ THIS Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); $topicObject->text("Null points"); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; $this->createNewFoswikiSession(); @@ -436,13 +434,13 @@ If ALLOWWEB is set to a list of wikinames THIS ); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; ($topicObject) = Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); $topicObject->text("Null points"); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # renew Foswiki, so WebPreferences gets re-read $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; @@ -472,7 +470,7 @@ If ALLOWTOPIC is set THIS ); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # renew Foswiki, so WebPreferences gets re-read $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; @@ -520,7 +518,7 @@ THIS Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); $topicObject->text($text); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # renew Foswiki, so WebPreferences gets re-read $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; @@ -529,7 +527,6 @@ THIS ($topicObject) = Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); $this->_checkSettings($topicObject); - $topicObject->finish(); return; } @@ -549,7 +546,7 @@ sub test_setInMETA { }; $topicObject->putKeyed( 'PREFERENCE', $args ); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # renew Foswiki, so WebPreferences gets re-read $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; @@ -559,7 +556,6 @@ sub test_setInMETA { Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); $this->_checkSettings($topicObject); - $topicObject->finish(); return; } @@ -582,7 +578,7 @@ THIS }; $topicObject->putKeyed( 'PREFERENCE', $args ); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # renew Foswiki, so WebPreferences gets re-read $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; @@ -591,7 +587,6 @@ THIS ($topicObject) = Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); $this->_checkSettings($topicObject); - $topicObject->finish(); return; } @@ -608,7 +603,7 @@ sub test_subweb_controls_override_parent { Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); $topicObject->text("Nowt"); $topicObject->save(); - $topicObject->finish(); + undef $topicObject; ($topicObject) = Foswiki::Func::readTopic( $this->test_web, @@ -617,18 +612,18 @@ sub test_subweb_controls_override_parent { * Set ALLOWWEBVIEW = MrGreen THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # Now build a subweb with view restricted to MrOrange my $webObject = $this->populateNewWeb($subweb); - $webObject->finish(); + undef $webObject; ($topicObject) = Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); $topicObject->text(<<'THIS'); * Set ALLOWWEBVIEW = MrOrange THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; $this->createNewFoswikiSession(); $this->DENIED( "VIEW", $MrOrange, $subweb ); @@ -657,17 +652,17 @@ sub test_subweb_inherits_from_parent { * Set FINALPREFERENCES = ALLOWWEBVIEW THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # Now build a subweb with no restrictions my $webObject = $this->populateNewWeb($subweb); - $webObject->finish(); + undef $webObject; ($topicObject) = Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); $topicObject->text(<<'THIS'); THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; $this->createNewFoswikiSession(); $this->DENIED( "VIEW", $MrGreen, $subweb ); @@ -696,18 +691,18 @@ sub test_finalised_parent_overrides_subweb { * Set FINALPREFERENCES = ALLOWWEBVIEW THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # Now build a subweb with view restricted to MrOrange my $webObject = $this->populateNewWeb($subweb); - $webObject->finish(); + undef $webObject; ($topicObject) = Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); $topicObject->text(<<'THIS'); * Set ALLOWWEBVIEW = MrOrange THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; $this->createNewFoswikiSession(); $this->DENIED( "VIEW", $MrOrange, $subweb ); @@ -737,7 +732,7 @@ anchor is preserved after login. * Set ALLOWTOPICVIEW = MrYellow THIS $topicObject->save(); - $topicObject->finish(); + undef $topicObject; # Request the page with the full UI my $query = Unit::Request->new( diff --git a/UnitTestContrib/test/unit/CacheTests.pm b/UnitTestContrib/test/unit/CacheTests.pm index 31b51cc6a8..b2ee8ac4f0 100644 --- a/UnitTestContrib/test/unit/CacheTests.pm +++ b/UnitTestContrib/test/unit/CacheTests.pm @@ -12,7 +12,9 @@ use Moo; use namespace::clean; extends qw(FoswikiFnTestCase); -has uifn => ( is => 'rw', ); +has uifn => ( is => 'rw', ); +has oldDbiDsn => ( is => 'rw', ); +has oldCacheDsn => ( is => 'rw', ); my $UI_FN; @@ -102,8 +104,7 @@ sub dbcheck_SQLite { } sub SQLite { - require Foswiki::PageCache::DBI::SQLite; - die $@ if $@; + Foswiki::load_package('Foswiki::PageCache::DBI::SQLite'); $Foswiki::cfg{Cache}{Implementation} = 'Foswiki::PageCache::DBI::SQLite'; $Foswiki::cfg{Cache}{DBI}{SQLite}{Filename} = "$Foswiki::cfg{WorkingDir}/${$}_sqlite.db"; @@ -115,8 +116,7 @@ sub dbcheck_PostgreSQL { } sub PostgreSQL { - require Foswiki::PageCache::DBI::PostgreSQL; - die $@ if $@; + Foswiki::load_package('Foswiki::PageCache::DBI::PostgreSQL'); $Foswiki::cfg{Cache}{Implementation} = 'Foswiki::PageCache::DBI::PostgreSQL'; $Foswiki::cfg{Cache}{Enabled} = 1; @@ -127,7 +127,7 @@ sub dbcheck_MySQL { } sub MySQL { - require Foswiki::PageCache::DBI::MySQL; + Foswiki::load_package('Foswiki::PageCache::DBI::MySQL'); $Foswiki::cfg{Cache}{Implementation} = 'Foswiki::PageCache::DBI::MySQL'; $Foswiki::cfg{Cache}{Enabled} = 1; } @@ -139,7 +139,7 @@ sub dbcheck_Generic { sub Generic { $Foswiki::cfg{Cache}{DBI}{DSN} = "dbi:SQLite:dbname=$Foswiki::cfg{WorkingDir}/${$}_generic.db"; - require Foswiki::PageCache::DBI::Generic; + Foswiki::load_package('Foswiki::PageCache::DBI::Generic'); $Foswiki::cfg{Cache}{Implementation} = 'Foswiki::PageCache::DBI::Generic'; $Foswiki::cfg{Cache}{Enabled} = 1; } @@ -193,11 +193,15 @@ around set_up => sub { $Foswiki::cfg{HttpCompress} = 0; $Foswiki::cfg{Cache}{Compress} = 0; $UI_FN ||= $this->getUIFn('view'); + $this->oldDbiDsn( $Foswiki::cfg{Cache}{DBI}{DSN} ); + $this->oldCacheDsn( $Foswiki::cfg{Cache}{DSN} ); }; around tear_down => sub { my $orig = shift; my $this = shift; + $Foswiki::cfg{Cache}{DBI}{DSN} = $this->oldDbiDsn; + $Foswiki::cfg{Cache}{DSN} = $this->oldCacheDsn; $orig->($this); unlink("$Foswiki::cfg{WorkingDir}/${$}_sqlite.db"); unlink("$Foswiki::cfg{WorkingDir}/${$}_generic.db"); diff --git a/UnitTestContrib/test/unit/FoswikiFnTestCase.pm b/UnitTestContrib/test/unit/FoswikiFnTestCase.pm index 9c341de1cf..4a9293f34b 100644 --- a/UnitTestContrib/test/unit/FoswikiFnTestCase.pm +++ b/UnitTestContrib/test/unit/FoswikiFnTestCase.pm @@ -126,7 +126,7 @@ around set_up => sub { @mails = (); $this->session->net->setMailHandler( \&FoswikiFnTestCase::sentMail ); my $webObject = $this->populateNewWeb( $this->test_web ); - $webObject->finish(); + undef $webObject; $this->clear_test_topicObject; $this->test_topicObject( Foswiki::Func::readTopic( $this->test_web, $this->test_topic ) ); @@ -134,7 +134,7 @@ around set_up => sub { $this->test_topicObject->save( forcedate => ( time() + 60 ) ); $webObject = $this->populateNewWeb( $this->users_web ); - $webObject->finish(); + undef $webObject; $this->test_user_forename('Scum'); $this->test_user_surname('Bag'); diff --git a/UnitTestContrib/test/unit/FoswikiTestCase.pm b/UnitTestContrib/test/unit/FoswikiTestCase.pm index d722a0cf74..1645df4f4c 100644 --- a/UnitTestContrib/test/unit/FoswikiTestCase.pm +++ b/UnitTestContrib/test/unit/FoswikiTestCase.pm @@ -779,7 +779,8 @@ s/((\$Foswiki::cfg\{.*?\})\s*=.*?;)(?:\n|$)/push(@moreConfig, $1) unless (eval " }; # Restores Foswiki::cfg and %ENV from backup -sub tear_down { +around tear_down => sub { + my $orig = shift; my $this = shift; if ( $this->has_session ) { @@ -811,7 +812,7 @@ sub tear_down { delete $Foswiki::Meta::VALIDATE{$thing} unless $Foswiki::Meta::VALIDATE{$thing}->{_default}; } -} +}; sub _copy { my $n = shift; @@ -1075,9 +1076,9 @@ sub createNewFoswikiSession { sub finishFoswikiSession { my ($this) = @_; - $this->session->finish() if $this->has_session; - ASSERT( !$Foswiki::Plugins::SESSION ) if SINGLE_SINGLETONS; + #$this->session->finish() if $this->has_session; $this->clear_session; + ASSERT( !$Foswiki::Plugins::SESSION ) if SINGLE_SINGLETONS; return; } diff --git a/core/lib/Foswiki.pm b/core/lib/Foswiki.pm index b84a8ddfdc..51bd2e198d 100644 --- a/core/lib/Foswiki.pm +++ b/core/lib/Foswiki.pm @@ -2612,76 +2612,80 @@ 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 { +#sub finish { +# my $this = shift; +# +# # Print any macros that are never loaded +# #print STDERR "NEVER USED\n"; +# #for my $i (keys %macros) { +# # print STDERR "\t$i\n" unless defined $macros{$i}; +# #} +# foreach ( values %{ $this->forms } ) { +# $_->finish() if $_; +# } +# $this->clear_forms; +# foreach my $key ( +# qw(prefs plugins users templates renderer zones net +# store search attach access i18n cache logger) +# ) +# { +# my $hasMethod = "has_$key"; +# my $clearMethod = "clear_$key"; +# if ( $this->$hasMethod ) { +# $this->$key->finish if defined $this->$key; +# $this->$clearMethod; +# } +# +# } +# +# $this->clear_request; +# $this->clear_digester; +# $this->clear_urlHost; +# $this->clear_webName; +# $this->clear_topicName; +# $this->clear_invalidWeb; +# $this->clear_invalidTopic; +# $this->clear_context; +# $this->clear_remoteUser; +# $this->clear_requestedWebName; # Web name before renaming +# $this->clear_scriptUrlPath; +# $this->clear_user; +# $this->clear_response; +# $this->clear_sandbox; +# $this->clear_heap; +# $this->_clear_baseStoreClass; +# $this->_clear_macros; +# undef $this->{web}; +# undef $this->{topic}; +# undef $this->{_addedToHEAD}; +# +# #undef $this->{DebugVerificationCode}; # from Foswiki::UI::Register +# if (SINGLE_SINGLETONS_TRACE) { +# require Data::Dumper; +# print STDERR "finish $this: " +# . Data::Dumper->Dump( [ [caller], [ caller(1) ] ] ); +# } +# if (SINGLE_SINGLETONS) { +# ASSERT( defined $Foswiki::Plugins::SESSION ); +# ASSERT( $Foswiki::Plugins::SESSION == $this ); +# ASSERT( $Foswiki::Plugins::SESSION->isa('Foswiki') ); +# } +# +# if (DEBUG) { +# my $remaining = join ',', +# grep { defined $this->{$_} && $_ !~ /^__/ } keys %$this; +# ASSERT( 0, +# "Fields with defined values in " +# . ref($this) +# . "->finish(): " +# . $remaining ) +# if $remaining; +# } +#} + +sub DEMOLISH { my $this = shift; - - # Print any macros that are never loaded - #print STDERR "NEVER USED\n"; - #for my $i (keys %macros) { - # print STDERR "\t$i\n" unless defined $macros{$i}; - #} - foreach ( values %{ $this->forms } ) { - $_->finish() if $_; - } - $this->clear_forms; - foreach my $key ( - qw(prefs plugins users templates renderer zones net - store search attach access i18n cache logger) - ) - { - my $hasMethod = "has_$key"; - my $clearMethod = "clear_$key"; - if ( $this->$hasMethod ) { - $this->$key->finish if defined $this->$key; - $this->$clearMethod; - } - - } - - $this->clear_request; - $this->clear_digester; - $this->clear_urlHost; - $this->clear_webName; - $this->clear_topicName; - $this->clear_invalidWeb; - $this->clear_invalidTopic; - $this->clear_context; - $this->clear_remoteUser; - $this->clear_requestedWebName; # Web name before renaming - $this->clear_scriptUrlPath; - $this->clear_user; - $this->clear_response; - $this->clear_sandbox; - $this->clear_heap; - $this->_clear_baseStoreClass; - $this->_clear_macros; - undef $this->{web}; - undef $this->{topic}; - undef $this->{_addedToHEAD}; - - #undef $this->{DebugVerificationCode}; # from Foswiki::UI::Register - if (SINGLE_SINGLETONS_TRACE) { - require Data::Dumper; - print STDERR "finish $this: " - . Data::Dumper->Dump( [ [caller], [ caller(1) ] ] ); - } - if (SINGLE_SINGLETONS) { - ASSERT( defined $Foswiki::Plugins::SESSION ); - ASSERT( $Foswiki::Plugins::SESSION == $this ); - ASSERT( $Foswiki::Plugins::SESSION->isa('Foswiki') ); - } undef $Foswiki::Plugins::SESSION; - - if (DEBUG) { - my $remaining = join ',', - grep { defined $this->{$_} && $_ !~ /^__/ } keys %$this; - ASSERT( 0, - "Fields with defined values in " - . ref($this) - . "->finish(): " - . $remaining ) - if $remaining; - } } =begin TML diff --git a/core/lib/Foswiki/Access.pm b/core/lib/Foswiki/Access.pm index 42bf7e8876..7a31eb0af3 100644 --- a/core/lib/Foswiki/Access.pm +++ b/core/lib/Foswiki/Access.pm @@ -27,9 +27,10 @@ BEGIN { } has session => ( - is => 'rw', - clearer => 1, - isa => Foswiki::Object::isaCLASS( 'session', 'Foswiki', noUndef => 1 ), + is => 'rw', + clearer => 1, + weak_ref => 1, + isa => Foswiki::Object::isaCLASS( 'session', 'Foswiki', noUndef => 1 ), ); has failure => ( is => 'rw', @@ -85,11 +86,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; - $this->clear_failure; - $this->clear_session; -} +#sub finish { +# my $this = shift; +# $this->clear_failure; +# $this->clear_session; +#} =begin TML diff --git a/core/lib/Foswiki/Address.pm b/core/lib/Foswiki/Address.pm index cfe5017dfe..a5a9d31f32 100644 --- a/core/lib/Foswiki/Address.pm +++ b/core/lib/Foswiki/Address.pm @@ -198,7 +198,7 @@ has root => ( is => 'rw', trigger => \&_validationTrigger, ); -has web => ( is => 'rw', ); +has _web => ( is => 'rw', init_args => 'web', ); has webpath => ( is => 'rw', trigger => sub { $_[0]->_invalidate; }, @@ -208,11 +208,15 @@ has topic => ( is => 'rw', trigger => \&_validationTrigger, ); -has rev => ( is => 'rw', ); +has _rev => ( is => 'rw', init_arg => 'rev', ); has tompath => ( - is => 'rw', - isa => Foswiki::Object::isaARRAY( __PACKAGE__ . "::tompath", noEmpty => 1 ), - trigger => \&_validationTrigger, + is => 'rw', + + # SMELL It seems that Moo has a bug with execution order when both isa and + # trigger are defined. In this case trigger is called before new value is + # assigned to the attribute. + #isa => Foswiki::Object::isaARRAY( __PACKAGE__ . "::tompath", noEmpty => 1 ), + trigger => sub { $_[0]->_validationTrigger; }, ); has attachment => ( is => 'rw', @@ -480,31 +484,6 @@ sub _new { =begin TML ----++ ClassMethod finish( ) - -Clean up the object, releasing any memory stored in it. - -=cut - -sub finish { - my ($this) = @_; - - $this->{root} = undef; - $this->{web} = undef; - $this->{webpath} = undef; - $this->{topic} = undef; - $this->{rev} = undef; - $this->{tompath} = undef; - $this->{attachment} = undef; - $this->{_isA} = undef; - $this->{_type} = undef; - $this->{stringified} = undef; - - return; -} - -=begin TML - ---++ PRIVATE ClassMethod _parse( $string, \%opts ) -> $success Parse the given string using options provided and update the instance with the @@ -660,7 +639,7 @@ sub _parse { ASSERT( $opts->{isA} or defined $opts->{existAs} ) if DEBUG; if ( $path =~ s/\@([-\+]?\d+)$// ) { - # $this->{rev} = $1; + # $this->rev( $1 ); $opts->{rev} = $1; } @@ -1229,43 +1208,43 @@ sub stringify { # If there's a valid address; and check that we haven't already computed # the stringification before if ( !defined $stringified ) { - if ( $this->{webpath} ) { + if ( $this->webpath ) { $stringified = - join( STRINGIFIED_WEB_SEPARATOR, @{ $this->{webpath} } ); - if ( $this->{topic} ) { - $stringified .= STRINGIFIED_TOPIC_SEPARATOR . $this->{topic}; - if ( $this->{tompath} ) { - ASSERT( ref( $this->{tompath} ) eq 'ARRAY' - and scalar( @{ $this->{tompath} } ) ) + join( STRINGIFIED_WEB_SEPARATOR, @{ $this->webpath } ); + if ( $this->topic ) { + $stringified .= STRINGIFIED_TOPIC_SEPARATOR . $this->topic; + if ( $this->tompath ) { + ASSERT( ref( $this->tompath ) eq 'ARRAY' + and scalar( @{ $this->tompath } ) ) if DEBUG; print STDERR 'tompath: ' - . Data::Dumper->Dump( [ $this->{tompath} ] ) + . Data::Dumper->Dump( [ $this->tompath ] ) if TRACEATTACH; print STDERR 'attachment: ' - . Data::Dumper->Dump( [ $this->{attachment} ] ) + . Data::Dumper->Dump( [ $this->attachment ] ) if TRACEATTACH; ASSERT( - $this->{tompath}->[0] ne 'attachment' - or not $this->{tompath}->[1] - or ( $this->{attachment} - and $this->{attachment} eq $this->{tompath}->[1] ) + $this->tompath->[0] ne 'attachment' + or not $this->tompath->[1] + or ( $this->attachment + and $this->attachment eq $this->tompath->[1] ) ) if DEBUG; - if ( $this->{tompath}->[0] eq 'attachment' - and scalar( @{ $this->{tompath} } ) == 2 ) + if ( $this->tompath->[0] eq 'attachment' + and scalar( @{ $this->tompath } ) == 2 ) { - $stringified .= '/' . $this->{tompath}->[1]; - if ( defined $this->{rev} ) { - $stringified .= '@' . $this->{rev}; + $stringified .= '/' . $this->tompath->[1]; + if ( defined $this->_rev ) { + $stringified .= '@' . $this->_rev; } } else { - if ( defined $this->{rev} ) { - $stringified .= '@' . $this->{rev}; + if ( defined $this->_rev ) { + $stringified .= '@' . $this->_rev; } $stringified = - '\'' . $stringified . '\'/' . $this->{tompath}->[0]; - if ( $this->{tompath}->[1] ) { - my @path = @{ $this->{tompath} }; + '\'' . $stringified . '\'/' . $this->tompath->[0]; + if ( $this->tompath->[1] ) { + my @path = @{ $this->tompath }; my $root = shift(@path); if ( $root eq 'META' and scalar(@path) ) { @@ -1305,8 +1284,8 @@ sub stringify { } } } - elsif ( defined $this->{rev} ) { - $stringified .= '@' . $this->{rev}; + elsif ( defined $this->_rev ) { + $stringified .= '@' . $this->_rev; } } else { @@ -1314,12 +1293,12 @@ sub stringify { } } else { - ASSERT( $this->{root} ); + ASSERT( $this->root ); $stringified = '/'; } } - print STDERR "stringify(): $this->{stringified}\n" - if TRACE2 and $this->{stringified}; + print STDERR "stringify(): ", $this->stringified, "\n" + if TRACE2 and $this->stringified; return $this->stringified($stringified); } @@ -1364,9 +1343,8 @@ Get/set by web string =cut -around web => sub { - my $orig = shift; - my $this = shift; +sub web { + my $this = shift; my ($web) = @_; ASSERT( @@ -1379,13 +1357,13 @@ around web => sub { } # XXX vrurg Would this work for a lazy attribute builder? - if ( not $this->{web} and defined( $this->webpath ) ) { - $orig->( $this, join( '/', @{ $this->webpath } ) ); + if ( not $this->_web and defined( $this->webpath ) ) { + $this->_web( join( '/', @{ $this->webpath } ) ); } - print STDERR "web(): no web part!\n" if TRACE and not $this->{web}; + print STDERR "web(): no web part!\n" if TRACE and not $this->_web; - return $orig->($this); -}; + return $this->_web; +} =begin TML @@ -1469,11 +1447,11 @@ Get/set the rev =cut -around rev => sub { +sub rev { my ( $orig, $this, $rev ) = @_; if ( scalar(@_) == 2 ) { - $this->{rev} = $rev; + $this->_rev($rev); $this->_invalidate(); ASSERT( $this->isValid() ) if DEBUG; } @@ -1481,8 +1459,8 @@ around rev => sub { $this->isValid(); } - return $this->{rev}; -}; + return $this->_rev; +} =begin TML @@ -1650,9 +1628,9 @@ sub isValid { $this->_isA( {} ); } ASSERT( - ( !defined $this->{rev} || $this->{rev} =~ m/^[-\+]?\d+$/ ), + ( !defined $this->_rev || $this->_rev =~ m/^[-\+]?\d+$/ ), "rev '" - . ( defined $this->{rev} ? $this->{rev} : 'undef' ) + . ( defined $this->_rev ? $this->_rev : 'undef' ) . "' is numeric" ) if DEBUG; } @@ -1678,7 +1656,7 @@ sub _trace_have_valid { my ( $this, $what ) = @_; print STDERR "isValid(): have $what => '" - . $this->_trace_stringify( $this->{$what} ) . "'\n" + . $this->_trace_stringify( $this->$what ) . "'\n" if TRACEVALID; } @@ -1686,7 +1664,7 @@ sub _trace_is_valid { my ( $this, $what ) = @_; print STDERR "isValid(): type is $what => '" - . $this->_trace_stringify( $this->{$what} ) . "'\n" + . $this->_trace_stringify( $this->$what ) . "'\n" if TRACEVALID; } @@ -1733,26 +1711,26 @@ sub equiv { # Confirm the ->type() is sane ASSERT( - ( not defined $this->{tompath} and not defined $other->{tompath} ) - or ( defined $this->{tompath} - and defined $other->{tompath} - and ref( $this->{tompath} ) eq 'ARRAY' - and ref( $other->{tompath} ) eq 'ARRAY' - and scalar( @{ $this->{tompath} } ) - and scalar( @{ $other->{tompath} } ) - and scalar( @{ $this->{tompath} } ) == - scalar( @{ $other->{tompath} } ) ) + ( not defined $this->tompath and not defined $other->tompath ) + or ( defined $this->tompath + and defined $other->tompath + and ref( $this->tompath ) eq 'ARRAY' + and ref( $other->tompath ) eq 'ARRAY' + and scalar( @{ $this->tompath } ) + and scalar( @{ $other->tompath } ) + and scalar( @{ $this->tompath } ) == + scalar( @{ $other->tompath } ) ) ) if DEBUG; ASSERT( - ( not defined $this->{tompath} and not defined $other->{tompath} ) - or ( defined $this->{tompath} - and defined $other->{tompath} - and $this->{tompath}->[0] eq $other->{tompath}->[0] ) + ( not defined $this->tompath and not defined $other->tompath ) + or ( defined $this->tompath + and defined $other->tompath + and $this->tompath->[0] eq $other->tompath->[0] ) ) if DEBUG; - if ( $this->{webpath} ) { - if ( $this->_eq( $this->{webpath}, $other->{webpath} ) ) { - if ( $this->_eq( $this->{topic}, $other->{topic} ) ) { - if ( $this->_eq( $this->{tompath}, $other->{tompath} ) ) { + if ( $this->webpath ) { + if ( $this->_eq( $this->webpath, $other->webpath ) ) { + if ( $this->_eq( $this->topic, $other->topic ) ) { + if ( $this->_eq( $this->tompath, $other->tompath ) ) { $equal = 1; } elsif (TRACE) { @@ -1767,8 +1745,8 @@ sub equiv { print STDERR "equiv(): webpath wasn't equal\n"; } } - elsif ( $this->{root} ) { - if ( $other->{root} ) { + elsif ( $this->root ) { + if ( $other->root ) { $equal = 1; } elsif (TRACE) { diff --git a/core/lib/Foswiki/Exception.pm b/core/lib/Foswiki/Exception.pm index b289256b22..d7c41a6faa 100644 --- a/core/lib/Foswiki/Exception.pm +++ b/core/lib/Foswiki/Exception.pm @@ -256,6 +256,9 @@ use Moo; extends qw(Foswiki::Exception); # To cover perl/system errors. +sub BUILD { + my $this = shift; +} package Foswiki::Exception::Engine; use Moo; diff --git a/core/lib/Foswiki/LoginManager.pm b/core/lib/Foswiki/LoginManager.pm index ef4d91ec58..427a04ce7c 100644 --- a/core/lib/Foswiki/LoginManager.pm +++ b/core/lib/Foswiki/LoginManager.pm @@ -235,10 +235,15 @@ 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 { +#sub finish { +# my $this = shift; +# $this->complete(); # call to flush the session if not already done +# $this->_clear_cgisession; +#} + +sub DEMOLISH { my $this = shift; - $this->complete(); # call to flush the session if not already done - $this->_clear_cgisession; + $this->complete; } =begin TML diff --git a/core/lib/Foswiki/Meta.pm b/core/lib/Foswiki/Meta.pm index e8d57cb053..a751b72b29 100644 --- a/core/lib/Foswiki/Meta.pm +++ b/core/lib/Foswiki/Meta.pm @@ -665,29 +665,34 @@ gets called before an object you have created goes out of scope. # 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->unload(); - - # SMELL vrurg Generally, it's not needed to clear these attributes manually - # as this will be done automatically during normal object destruction. - $this->clear_web; - $this->clear_topic; - $this->clear_session; - if (DEBUG) { - - #someone keeps adding random references to Meta so to shake them out.. - #if its an intentional ref to an object, please add it to the undef's above. - -#SMELL: Sven noticed during development that something is adding a $this->store to a meta obj - havn't found it yet -#ASSERT(not defined($this->store)) if DEBUG; - - use Scalar::Util qw(blessed); - foreach my $key (%$this) { +#sub finish { +# my $this = shift; +# $this->unload(); +# +# # SMELL vrurg Generally, it's not needed to clear these attributes manually +# # as this will be done automatically during normal object destruction. +# $this->clear_web; +# $this->clear_topic; +# $this->clear_session; +# if (DEBUG) { +# +# #someone keeps adding random references to Meta so to shake them out.. +# #if its an intentional ref to an object, please add it to the undef's above. +# +##SMELL: Sven noticed during development that something is adding a $this->store to a meta obj - havn't found it yet +##ASSERT(not defined($this->store)) if DEBUG; +# +# use Scalar::Util qw(blessed); +# foreach my $key (%$this) { +# +# #ASSERT(not defined(blessed($this->{$key}))); +# } +# } +#} - #ASSERT(not defined(blessed($this->{$key}))); - } - } +sub DEMOLISH { + my $this = shift; + $this->unload; } # Assert helpers diff --git a/core/lib/Foswiki/MetaCache.pm b/core/lib/Foswiki/MetaCache.pm index f00dce047a..6726575221 100644 --- a/core/lib/Foswiki/MetaCache.pm +++ b/core/lib/Foswiki/MetaCache.pm @@ -86,27 +86,30 @@ Break circular references. =cut -sub finish { +sub DEMOLISH { my $this = shift; #undef $this->{session}; #must clear cache every request until the cache is hooked up to Store's save - foreach my $cuid ( keys( %{ $this->{cache} } ) ) { - foreach my $web ( keys( %{ $this->{cache}->{$cuid} } ) ) { - foreach my $topic ( keys( %{ $this->{cache}->{$cuid}->{$web} } ) ) { - undef $this->{cache}->{$cuid}{$web}{$topic}; - $this->{undef_count}++; + foreach my $cuid ( keys( %{ $this->cache } ) ) { + foreach my $web ( keys( %{ $this->cache->{$cuid} } ) ) { + foreach my $topic ( keys( %{ $this->cache->{$cuid}->{$web} } ) ) { + undef $this->cache->{$cuid}{$web}{$topic}; + $this->undef_count( $this->undef_count + 1 ); } - undef $this->{cache}->{$cuid}{$web}; + undef $this->cache->{$cuid}{$web}; } - undef $this->{cache}->{$cuid}; + undef $this->cache->{$cuid}; } - undef $this->{cache}; if (TRACE) { - print STDERR -"MetaCache: new: $this->{new_count} get: $this->{get_count} undef: $this->{undef_count} \n"; + print STDERR "MetaCache: new: " + . $this->new_count + . " get: " + . $this->get_count + . " undef: " + . $this->undef_count . " \n"; } return; diff --git a/core/lib/Foswiki/Object.pm b/core/lib/Foswiki/Object.pm index 3edf832ad1..2177308f72 100644 --- a/core/lib/Foswiki/Object.pm +++ b/core/lib/Foswiki/Object.pm @@ -20,6 +20,8 @@ features. =cut use Foswiki::Exception; +use Carp; + use Moo; use namespace::clean; @@ -138,23 +140,38 @@ sub BUILD { } -sub finish { - - # Plug for objects with no finish() method. Temporary, until the destruction - # stage is reviewed. -} +#sub finish { +# +# # Plug for objects with no finish() method. Temporary, until the destruction +# # stage is reviewed. +# #Foswki::Exception->throw( text => "Methods finish() called." ); +#} sub DEMOLISH { my $this = shift; - $this->_clear__orig_file; - $this->_clear__orig_line; + + #say STDERR ref($this), "::DEMOLISH" if DEBUG; if ( $this->can('finish') ) { + say STDERR Carp::longmess( + ref($this) . " supports finish() but it shouldn't." ); # SMELL every Foswiki::Object ancestor has to use DEMOLISH as the standard. # XXX We have to generate a warning if this condition is met. $this->finish; } + if (DEBUG) { + foreach my $key ( keys %{$this} ) { + unless ( $this->can($key) ) { + say STDERR "Key $key on ", ref($this), + " isn't a valid attribute."; + if ( UNIVERSAL::isa( $this->{key}, 'Foswiki::Object' ) ) { + say STDERR " $key is a Foswiki::Object created in ", + $this->{key}->__orig_file, ":", $this->{key}->__orig_line; + } + } + } + } } sub _normalizeAttributeName { diff --git a/core/lib/Foswiki/PageCache.pm b/core/lib/Foswiki/PageCache.pm index 3b283c7aa3..cf11e2a301 100644 --- a/core/lib/Foswiki/PageCache.pm +++ b/core/lib/Foswiki/PageCache.pm @@ -54,15 +54,23 @@ rendering the related yet again. =cut package Foswiki::PageCache; +use v5.14; -use strict; -use warnings; use Foswiki::Time (); use Foswiki::Attrs (); use Foswiki::Plugins (); -use Error qw( :try ); +use Try::Tiny; use CGI::Util (); +use Moo; +use namespace::clean; +extends qw(Foswiki::Object); + +has webDeps => ( is => 'rw', lazy => 1, clearer => 1, default => sub { {} }, ); +has deps => ( is => 'rw', lazy => 1, default => sub { {} }, ); +has _isCacheable => ( is => 'rw', lazy => 1, default => sub { {} }, ); +has variationKey => ( is => 'rw', ); + BEGIN { if ( $Foswiki::cfg{UseLocale} ) { require locale; @@ -81,12 +89,6 @@ Construct a new page cache =cut -sub new { - my ($class) = @_; - - return bless( {}, $class ); -} - =begin TML ---++ ObjectMethod genVariationKey() -> $key @@ -119,12 +121,12 @@ information from the current session and url params, as follows: sub genVariationKey { my $this = shift; - my $variationKey = $this->{variationKey}; + my $variationKey = $this->variationKey; return $variationKey if defined $variationKey; my $session = $Foswiki::Plugins::SESSION; - my $request = $session->{request}; - my $action = substr( ( $request->{action} || 'view' ), 0, 4 ); + my $request = $session->request; + my $action = substr( ( $request->action || 'view' ), 0, 4 ); my $serverName = $request->server_name || $Foswiki::cfg{DefaultUrlHost}; my $serverPort = $request->server_port || 80; $variationKey = '::' . $serverName . '::' . $serverPort . '::' . $action; @@ -192,7 +194,7 @@ m/^(_.*|VALIDATION|REMEMBER|FOSWIKISTRIKEONE.*|VALID_ACTIONS.*|BREADCRUMB_TRAIL| Foswiki::Func::writeDebug("variation key = '$variationKey'") if TRACE; # cache it - $this->{variationKey} = $variationKey; + $this->variationKey($variationKey); return $variationKey; } @@ -210,9 +212,9 @@ sub cachePage { my ( $this, $contentType, $data ) = @_; my $session = $Foswiki::Plugins::SESSION; - my $request = $session->{request}; - my $web = $session->{webName}; - my $topic = $session->{topicName}; + my $request = $session->request; + my $web = $session->webName; + my $topic = $session->topicName; $web =~ s/\//./g; Foswiki::Func::writeDebug("called cachePage($web, $topic)") if TRACE; @@ -257,7 +259,7 @@ sub cachePage { $lastModified = Foswiki::Time::formatTime( $time, '$http', 'gmtime' ); } - my $headers = $session->{response}->headers(); + my $headers = $session->response->headers(); my $status = $headers->{Status} || 200; my $variation = { contenttype => $contentType, @@ -271,7 +273,7 @@ sub cachePage { # get cache-expiry preferences and add it to the bucket if available my $expire = $request->param("cache_expire"); - $expire = $session->{prefs}->getPreference('CACHEEXPIRE') + $expire = $session->prefs->getPreference('CACHEEXPIRE') unless defined $expire; $variation->{expire} = CGI::Util::expire_calc($expire) if defined $expire; @@ -311,22 +313,22 @@ sub getPage { # check url param my $session = $Foswiki::Plugins::SESSION; - my $refresh = $session->{request}->param('refresh') || ''; + my $refresh = $session->request->param('refresh') || ''; if ( $refresh eq 'all' ) { - if ( $session->{users}->isAdmin( $session->{user} ) ) { + if ( $session->users->isAdmin( $session->user ) ) { $this->deleteAll(); } else { my $session = $Foswiki::Plugins::SESSION; - my $request = $session->{request}; - my $action = substr( ( $request->{action} || 'view' ), 0, 4 ); + my $request = $session->request; + my $action = substr( ( $request->action || 'view' ), 0, 4 ); unless ( $action eq 'rest' ) { throw Foswiki::OopsException( - 'accessdenied', - def => 'cache_refresh', - web => $web, - topic => $topic, + template => 'accessdenied', + def => 'cache_refresh', + web => $web, + topic => $topic, ); } } @@ -395,7 +397,7 @@ sub isCacheable { my $webTopic = $web . '.' . $topic; - my $isCacheable = $this->{isCacheable}{$webTopic}; + my $isCacheable = $this->_isCacheable->{$webTopic}; return $isCacheable if defined $isCacheable; #Foswiki::Func::writeDebug("... checking") if TRACE; @@ -406,28 +408,28 @@ sub isCacheable { my $session = $Foswiki::Plugins::SESSION; # check for errors parsing the url path - $isCacheable = 0 if $session->{invalidWeb} || $session->{invalidTopic}; + $isCacheable = 0 if $session->invalidWeb || $session->invalidTopic; # POSTs and HEADs aren't cacheable - my $method = $session->{request}->method; + my $method = $session->request->method; $isCacheable = 0 if $method && $method =~ m/^(?:POST|HEAD)$/; if ($isCacheable) { # check prefs value - my $flag = $session->{prefs}->getPreference('CACHEABLE'); + my $flag = $session->prefs->getPreference('CACHEABLE'); $isCacheable = 0 if defined $flag && !Foswiki::isTrue($flag); } # don't cache 401 Not authorized responses - my $headers = $session->{response}->headers(); + my $headers = $session->response->headers(); my $status = $headers->{Status}; $isCacheable = 0 if $status && $status eq 401; # TODO: give plugins a chance - create a callback to intercept cacheability #Foswiki::Func::writeDebug("isCacheable=$isCacheable") if TRACE; - $this->{isCacheable}{$webTopic} = $isCacheable; + $this->_isCacheable->{$webTopic} = $isCacheable; return $isCacheable; } @@ -464,7 +466,7 @@ sub addDependency { } # collect them; defer writing them to the database til we cache this page - $this->{deps}{$depWebTopic} = 1; + $this->deps->{$depWebTopic} = 1; } =begin TML @@ -494,14 +496,14 @@ Returns dependencies that hold for all topics in a web. sub getWebDependencies { my ( $this, $web ) = @_; - unless ( defined $this->{webDeps} ) { + unless ( defined $this->webDeps ) { my $session = $Foswiki::Plugins::SESSION; my $webDeps = - $session->{prefs}->getPreference( 'WEBDEPENDENCIES', $web ) + $session->prefs->getPreference( 'WEBDEPENDENCIES', $web ) || $Foswiki::cfg{Cache}{WebDependencies} || ''; - $this->{webDeps} = (); + $this->clear_webDeps; # normalize topics foreach my $dep ( split( /\s*,\s*/, $webDeps ) ) { @@ -510,10 +512,10 @@ sub getWebDependencies { Foswiki::Func::writeDebug("found webdep $depWeb.$depTopic") if TRACE; - $this->{webDeps}{ $depWeb . '.' . $depTopic } = 1; + $this->webDeps->{ $depWeb . '.' . $depTopic } = 1; } } - my @result = keys %{ $this->{webDeps} }; + my @result = keys %{ $this->webDeps }; return \@result; } @@ -534,7 +536,7 @@ are collected during the rendering process. sub setDependencies { my ( $this, $web, $topic, $variationKey, @topicDeps ) = @_; - @topicDeps = keys %{ $this->{deps} } unless @topicDeps; + @topicDeps = keys %{ $this->deps } unless @topicDeps; die("virtual method"); } @@ -630,7 +632,7 @@ sub renderDirtyAreas { # remember the current page length to recompute the content length below my $found = 0; my $topicObj = - new Foswiki::Meta( $session, $session->{webName}, $session->{topicName} ); + new Foswiki::Meta( $session, $session->webName, $session->topicName ); # expand dirt while ( $$text =~ @@ -660,7 +662,7 @@ sub _handleDirtyArea { # add dirtyarea params my $params = new Foswiki::Attrs($args); my $session = $Foswiki::Plugins::SESSION; - my $prefs = $session->{prefs}; + my $prefs = $session->prefs; $prefs->pushTopicContext( $topicObj->web, $topicObj->topic ); $params->remove('_RAW'); @@ -668,7 +670,14 @@ sub _handleDirtyArea { try { $text = $topicObj->expandMacros($text); $text = $topicObj->renderTML($text); - }; + } + catch { + if ( !ref($_) || $_->isa('Foswiki::Exception::Fatal') ) { + + # Do not hide critical errors. + Foswiki::Exception::Fatal->rethrow($_); + } + } finally { $prefs->popTopicContext(); }; @@ -677,17 +686,6 @@ sub _handleDirtyArea { return $text; } -=begin TML - ----++ ObjectMethod finish() - -clean up finally - -=cut - -sub finish { -} - 1; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/lib/Foswiki/PageCache/DBI.pm b/core/lib/Foswiki/PageCache/DBI.pm index 487cd000ad..44eb1ed9d1 100644 --- a/core/lib/Foswiki/PageCache/DBI.pm +++ b/core/lib/Foswiki/PageCache/DBI.pm @@ -9,17 +9,17 @@ Implements a Foswiki::PageCache using a DBI compatible backend. =cut package Foswiki::PageCache::DBI; +use v5.14; -use strict; -use warnings; - +use Try::Tiny; use Foswiki::PageCache (); use DBI (); -use Error qw(:try); -use Foswiki::Sandbox (); -use Foswiki::Plugins (); +use Foswiki::Sandbox (); +use Foswiki::Plugins (); -@Foswiki::PageCache::DBI::ISA = ('Foswiki::PageCache'); +use Moo; +use namespace::clean; +extends qw(Foswiki::PageCache); # Enable output use constant TRACE => 0; @@ -36,29 +36,50 @@ Construct a new page cache and makes sure the database is ready =cut -sub new { - my $class = shift; - - my $tablePrefix = $Foswiki::cfg{Cache}{DBI}{TablePrefix} || 'foswiki_cache'; - - my $this = { - cacheDir => $Foswiki::cfg{Cache}{RootDir} - || $Foswiki::cfg{WorkingDir} . '/cache', - - dsn => $Foswiki::cfg{Cache}{DBI}{DSN}, - username => $Foswiki::cfg{Cache}{DBI}{Username}, - password => $Foswiki::cfg{Cache}{DBI}{Password}, - - pagesTable => $tablePrefix . '_pages', - pagesIndex => $tablePrefix . '_pages_index', - depsTable => $tablePrefix . '_deps', - depsIndex => $tablePrefix . '_deps_index', - - @_ - }; - - return bless( $this, $class ); -} +has _tablePrefix => ( + is => 'ro', + default => + sub { return $Foswiki::cfg{Cache}{DBI}{TablePrefix} || 'foswiki_cache'; } +); +has pagesTable => ( + is => 'rw', + lazy => 1, + default => sub { return $_[0]->_tablePrefix . '_pages' }, +); +has pagesIndex => ( + is => 'rw', + lazy => 1, + default => sub { return $_[0]->_tablePrefix . '_pages_index' }, +); +has depsTable => ( + is => 'rw', + lazy => 1, + default => sub { return $_[0]->_tablePrefix . '_deps' }, +); +has depsIndex => ( + is => 'rw', + lazy => 1, + default => sub { return $_[0]->_tablePrefix . '_deps_index' }, +); +has cacheDir => ( + is => 'ro', + default => sub { + return $Foswiki::cfg{Cache}{RootDir} + || $Foswiki::cfg{WorkingDir} . '/cache'; + }, +); +has dsn => ( + is => 'rw', + lazy => 1, + default => sub { return $Foswiki::cfg{Cache}{DBI}{DSN}; }, +); +has username => ( is => 'rw', default => $Foswiki::cfg{Cache}{DBI}{Username}, ); +has password => ( is => 'rw', default => $Foswiki::cfg{Cache}{DBI}{Password}, ); +has dbh => ( is => 'rw', ); +has _doneInit => ( is => 'rw', default => 0 ); +has _insert_page => ( is => 'rw', ); +has _select_md5 => ( is => 'rw', ); +has _select_rev_md5 => ( is => 'rw', ); =begin TML @@ -71,16 +92,15 @@ Initializes and connects to the database sub init { my $this = shift; - return if $this->{_doneInit}; - $this->{_doneInit} = 1; + return if $this->_doneInit; my $error; try { $this->connect; } - catch Error with { - $error = shift; + catch { + $error = ref($_) ? $_->stringify : $_; my $msg; if ( defined $DBI::errstr ) { $msg = @@ -102,8 +122,12 @@ sub init { try { $this->createTables; } - catch Error with { - $error = shift; + catch { + if ( !$DBI::err ) { + Foswiki::Exception::Fatal->rethrow($_); + } + + $error = ref($_) ? $_->stringify : $_; my $msg = "ERROR: unable to create tables in Foswiki::PageCache::DBI: " @@ -112,12 +136,14 @@ sub init { print STDERR $msg . "\n"; $Foswiki::cfg{Cache}{Enabled} = 0; - $this->{dbh}->rollback; - $this->{dbh}->disconnect; + $this->dbh->rollback; + $this->dbh->disconnect; }; return if $error; - mkdir $this->{cacheDir} unless -d $this->{cacheDir}; + mkdir $this->cacheDir unless -d $this->cacheDir; + + $this->_doneInit(1); return $this; } @@ -144,11 +170,12 @@ sub setPageVariation { my $error; try { - $this->{dbh}->begin_work; + $this->dbh->begin_work; - unless ( defined $this->{_insert_page} ) { - $this->{_insert_page} = $this->{dbh}->prepare(<{pagesTable} + unless ( defined $this->_insert_page ) { + my $pagesTable = $this->pagesTable; + $this->_insert_page( $this->dbh->prepare(<{_insert_page}->errstr ); + ) or die( "Can't execute statement: " . $this->_insert_page->errstr ); - $this->{dbh}->commit; + $this->dbh->commit; } - catch Error with { - local $this->{dbh}->{RaiseError} = 0; - $this->{dbh}->rollback; + catch { + local $this->dbh->{RaiseError} = 0; + $this->dbh->rollback; $error = 1; writeDebug("transaction error at setPageVariation"); }; @@ -186,7 +212,7 @@ HERE my $FILE; my $fileName = Foswiki::Sandbox::normalizeFileName( - $this->{cacheDir} . '/' . $variation->{md5} ); + $this->cacheDir . '/' . $variation->{md5} ); #writeDebug("saving data of $webTopic into $fileName"); open( $FILE, '>:encoding(utf-8)', $fileName ) @@ -213,8 +239,9 @@ sub getPageVariation { #writeDebug("getPageVariation($webTopic, $variationKey)"); - my $sth = $this->{dbh}->prepare(<{pagesTable} + my $pagesTable = $this->pagesTable; + my $sth = $this->dbh->prepare(<{cacheDir} . '/' . $variation->{md5}; + my $fileName = $this->cacheDir . '/' . $variation->{md5}; open( $FILE, '<:encoding(utf-8)', $fileName ) or return; local $/ = undef; $variation->{data} = <$FILE>; @@ -251,10 +278,10 @@ sub deleteAll { $this->rebuild(); - opendir( my $dh, $this->{cacheDir} ); - my @files = map { - Foswiki::Sandbox::normalizeFileName( $this->{cacheDir} . '/' . $_ ) - } grep { !/^\./ } readdir $dh; + opendir( my $dh, $this->cacheDir ); + my @files = + map { Foswiki::Sandbox::normalizeFileName( $this->cacheDir . '/' . $_ ) } + grep { !/^\./ } readdir $dh; closedir $dh; #writeDebug("cleaning up @files"); @@ -280,7 +307,7 @@ sub deletePage { $webTopic .= '.' . $topic if $topic; try { - $this->{dbh}->begin_work; + $this->dbh->begin_work; # delete page if ( defined $variationKey ) { @@ -291,44 +318,51 @@ sub deletePage { Foswiki::encode_utf8( $web . $topic . $variationKey ) ); my $fileName = Foswiki::Sandbox::normalizeFileName( - $this->{cacheDir} . '/' . $md5 ); + $this->cacheDir . '/' . $md5 ); #writeDebug("deleting $fileName for $webTopic"); unlink $fileName; - $this->{dbh}->do( -"delete from $this->{pagesTable} where topic = ? and variation = ?", + $this->dbh->do( + "delete from " + . $this->pagesTable + . " where topic = ? and variation = ?", undef, $webTopic, $variationKey ); } else { # get all filenames and delete them - unless ( defined $this->{_select_md5} ) { - $this->{_select_md5} = $this->{dbh}->prepare(<{pagesTable} where topic = ? and variation = ? -HERE + unless ( defined $this->_select_md5 ) { + $this->_select_md5( + $this->dbh->prepare( + "select md5 from " + . $this->pagesTable + . " where topic = ? and variation = ?" + ) + ); } - $this->{_select_md5}->execute( $webTopic, $variationKey ); - while ( my ($md5) = $this->{_select_md5}->fetchrow_array() ) { - my $fileName = $this->{cacheDir} . '/' . $md5; + $this->_select_md5->execute( $webTopic, $variationKey ); + while ( my ($md5) = $this->_select_md5->fetchrow_array() ) { + my $fileName = $this->cacheDir . '/' . $md5; #writeDebug("deleting $fileName for $webTopic"); unlink $fileName; } #writeDebug("DELETE page $webTopic"); - $this->{dbh}->do( "delete from $this->{pagesTable} where topic = ?", + $this->dbh->do( + "delete from " . $this->pagesTable . " where topic = ?", undef, $webTopic ); } $this->deleteDependencies( $web, $topic, $variationKey ); - $this->{dbh}->commit; + $this->dbh->commit; } - catch Error with { - local $this->{dbh}->{RaiseError} = 0; - $this->{dbh}->rollback; + catch { + local $this->dbh->{RaiseError} = 0; + $this->dbh->rollback; writeDebug("transaction error at deletePage"); }; } @@ -353,15 +387,18 @@ sub deleteDependencies { if ( defined $variationKey ) { #writeDebug("DELETE dependencies of $webTopic variation=".$variationKey); - $this->{dbh}->do( -"delete from $this->{depsTable} where from_topic = ? and variation = ?", + $this->dbh->do( + "delete from " + . $this->depsTable + . " where from_topic = ? and variation = ?", undef, $webTopic, $variationKey ); } else { #writeDebug("DELETE dependencies of $webTopic"); - $this->{dbh}->do( "delete from $this->{depsTable} where from_topic = ?", + $this->dbh->do( + "delete from " . $this->depsTable . " where from_topic = ?", undef, $webTopic ); } } @@ -377,34 +414,38 @@ See Foswiki::PageCache::setDependencies() for more information sub setDependencies { my ( $this, $web, $topic, $variationKey, @topicDeps ) = @_; - @topicDeps = keys %{ $this->{deps} } unless @topicDeps; + @topicDeps = keys %{ $this->deps } unless @topicDeps; my $fromWebTopic = $web . '.' . $topic; try { - $this->{dbh}->begin_work; - - unless ( defined $this->{_insert_dep} ) { - $this->{_insert_dep} = $this->{dbh}->prepare(<{depsTable} (from_topic, variation, to_topic) values (?, ?, ?) -HERE + $this->dbh->begin_work; + + unless ( defined $this->_insert_dep ) { + $this->_insert_dep( + $this->dbh->prepare( + "insert into " + . $this->depsTable + . " (from_topic, variation, to_topic) values (?, ?, ?)" + ) + ); } foreach my $toWebTopic (@topicDeps) { next if $toWebTopic eq $fromWebTopic; #writeDebug( "INSERT dependency $fromWebTopic, $variationKey, $toWebTopic"); - $this->{_insert_dep} - ->execute( $fromWebTopic, $variationKey, $toWebTopic ) + $this->_insert_dep->execute( $fromWebTopic, $variationKey, + $toWebTopic ) or - die( "Can't execute statement: " . $this->{_insert_dep}->errstr ); + die( "Can't execute statement: " . $this->_insert_dep->errstr ); } - $this->{dbh}->commit; + $this->dbh->commit; } - catch Error with { - local $this->{dbh}->{RaiseError} = 0; - $this->{dbh}->rollback; + catch { + local $this->dbh->{RaiseError} = 0; + $this->dbh->rollback; writeDebug("transaction error at setDependencies"); }; } @@ -426,16 +467,18 @@ sub getDependencies { my $webTopic = $web . '.' . $topic; if ( defined $variationKey ) { - $sth = $this->{dbh}->prepare(<{depsTable} where from_topic = ? and variation = ? -HERE + $sth = + $this->dbh->prepare( "select distinct to_topic " + . $this->depsTable + . " where from_topic = ? and variation = ?" ); $sth->execute( $webTopic, $variationKey ) or die( "Can't execute statement: " . $sth->errstr ); } else { - $sth = $this->{dbh}->prepare(<{depsTable} where from_topic = ? -HERE + $sth = + $this->dbh->prepare( "select distinct to_topic " + . $this->depsTable + . " where from_topic = ?" ); $sth->execute($webTopic) or die( "Can't execute statement: " . $sth->errstr ); } @@ -475,32 +518,34 @@ sub fireDependency { my $error; try { - $this->{dbh}->begin_work; + my ( $pagesTable, $depsTable ) = + ( $this->pagesTable, $this->depsTable ); + $this->dbh->begin_work; # (1) get all md5s and unline the files holding the blob - unless ( $this->{_select_rev_md5} ) { - $this->{_select_rev_md5} = $this->{dbh}->prepare(<{pagesTable} as pages join $this->{depsTable} as deps on + unless ( $this->_select_rev_md5 ) { + $this->_select_rev_md5( $this->dbh->prepare(<{_select_rev_md5}->execute($webTopic); - while ( my ($md5) = $this->{_select_rev_md5}->fetchrow_array ) { - my $fileName = $this->{cacheDir} . '/' . $md5; + $this->_select_rev_md5->execute($webTopic); + while ( my ($md5) = $this->_select_rev_md5->fetchrow_array ) { + my $fileName = $this->cacheDir . '/' . $md5; #writeDebug("deleting $fileName for $webTopic"); unlink $fileName; } # (2) delete the page entries that used $web.$topic - $this->{dbh}->do(<{pagesTable} where ( - select count(*) > 0 from $this->{depsTable} as deps - where deps.from_topic = $this->{pagesTable}.topic and - deps.variation = $this->{pagesTable}.variation and + $this->dbh->do(< 0 from ${depsTable} as deps + where deps.from_topic = ${pagesTable}.topic and + deps.variation = ${pagesTable}.variation and deps.to_topic = '$webTopic' ) HERE @@ -508,15 +553,15 @@ HERE # (3) delete the deps of topics that we just removed # SMELL: yes, I know cascaded deletes would have been better, but that # doesn't seem to work on mysql and sqlite. postgresql is fine, but the rest is ... - $this->{dbh}->do(<{depsTable} where - from_topic not in ( select distinct topic from $this->{pagesTable} ) + $this->dbh->do(<{dbh}->commit; + $this->dbh->commit; } - catch Error with { - local $this->{dbh}->{RaiseError} = 0; - $this->{dbh}->rollback; + catch { + local $this->dbh->{RaiseError} = 0; + $this->dbh->rollback; $error = 1; writeDebug("transaction error at fireDependency"); }; @@ -542,26 +587,28 @@ connects to the database sub connect { my $this = shift; - unless ( defined $this->{dbh} ) { - - $this->{dbh} = DBI->connect( - $this->{dsn}, - $this->{username}, - $this->{password}, - { - PrintError => 0, - RaiseError => 1, - AutoCommit => 1, - ShowErrorStatement => 1, - } + unless ( defined $this->dbh ) { + + $this->dbh( + DBI->connect( + $this->dsn, + $this->username, + $this->password, + { + PrintError => 0, + RaiseError => 1, + AutoCommit => 1, + ShowErrorStatement => 1, + } + ) ); - throw Error::Simple( - "Can't open database $this->{dsn}: " . $DBI::errstr ) - unless defined $this->{dbh}; + Foswiki::Exception::Fatal->throw( + text => "Can't open database " . $this->dsn . ": " . $DBI::errstr ) + unless defined $this->dbh; } - return $this->{dbh}; + return $this->dbh; } =begin TML @@ -576,7 +623,9 @@ sub createTables { my $this = shift; # test whether the table exists - eval { $this->{dbh}->do("select topic from $this->{pagesTable} limit 1"); }; + eval { + $this->dbh->do( "select topic from " . $this->pagesTable . " limit 1" ); + }; if ($@) { writeDebug("test result: $@"); @@ -596,8 +645,10 @@ sub createTables { sub _createPagesTable { my $this = shift; - $this->{dbh}->do(<{pagesTable} ( + my $pagesTable = $this->pagesTable; + + $this->dbh->do(<{dbh} - ->do("create index $this->{pagesIndex} on $this->{pagesTable} (topic)"); + $this->dbh->do( "create index " + . $this->pagesIndex . " on " + . $this->pagesTable + . " (topic)" ); } sub _createDepsTable { my $this = shift; - $this->{dbh}->do(<{depsTable} ( + my $depsTable = $this->depsTable; + + $this->dbh->do(<{dbh}->do( -"create index $this->{depsIndex} on $this->{depsTable} (from_topic, to_topic)" - ); + $this->dbh->do( "create index " + . $this->depsIndex . " on " + . $this->depsTable + . " (from_topic, to_topic)" ); } =begin TML @@ -649,8 +705,8 @@ sub rebuild { #writeDebug("rebuild database"); eval { - $this->{dbh}->do("drop table $this->{pagesTable}"); - $this->{dbh}->do("drop table $this->{depsTable}"); + $this->dbh->do( "drop table " . $this->pagesTable ); + $this->dbh->do( "drop table " . $this->depsTable ); }; if ($@) { @@ -668,36 +724,13 @@ cleans up the mess we left behind =cut -sub finish { +sub DEMOLISH { my $this = shift; #writeDebug("called finish"); - - if ( $this->{_insert_page} ) { - $this->{_insert_page}->finish; - undef $this->{_insert_page}; - } - - if ( $this->{_insert_dep} ) { - $this->{_insert_dep}->finish; - undef $this->{_insert_dep}; - } - - if ( $this->{_select_md5} ) { - $this->{_select_md5}->finish; - undef $this->{_select_md5}; - } - - if ( $this->{_select_rev_md5} ) { - $this->{_select_rev_md5}->finish; - undef $this->{_select_rev_md5}; - } - - if ( $this->{dbh} ) { - $this->{dbh}->disconnect; - undef $this->{dbh}; + if ( $this->dbh ) { + $this->dbh->disconnect; } - } 1; diff --git a/core/lib/Foswiki/PageCache/DBI/Generic.pm b/core/lib/Foswiki/PageCache/DBI/Generic.pm index f3697f3f75..e325db43bf 100644 --- a/core/lib/Foswiki/PageCache/DBI/Generic.pm +++ b/core/lib/Foswiki/PageCache/DBI/Generic.pm @@ -10,12 +10,10 @@ specificly tailord towards your database. =cut package Foswiki::PageCache::DBI::Generic; +use v5.14; -use strict; -use warnings; - -use Foswiki::PageCache::DBI (); -@Foswiki::PageCache::DBI::Generic::ISA = ('Foswiki::PageCache::DBI'); +use Moo; +extends qw(Foswiki::PageCache::DBI); =begin TML @@ -25,12 +23,10 @@ Construct a new page cache and makes sure the database is ready =cut -sub new { - my $class = shift; - - my $this = bless( $class->SUPER::new(@_), $class ); +sub BUILD { + my $this = shift; - return $this->init; + $this->init; } 1; diff --git a/core/lib/Foswiki/PageCache/DBI/MySQL.pm b/core/lib/Foswiki/PageCache/DBI/MySQL.pm index d2ba994960..87eb0b4ab1 100644 --- a/core/lib/Foswiki/PageCache/DBI/MySQL.pm +++ b/core/lib/Foswiki/PageCache/DBI/MySQL.pm @@ -9,12 +9,10 @@ Implements a Foswiki::PageCache::DBI using mysql =cut package Foswiki::PageCache::DBI::MySQL; +use v5.14; -use strict; -use warnings; - -use Foswiki::PageCache::DBI (); -@Foswiki::PageCache::DBI::MySQL::ISA = ('Foswiki::PageCache::DBI'); +use Moo; +extends qw(Foswiki::PageCache::DBI); =begin TML @@ -24,24 +22,41 @@ Construct a new page cache and makes sure the database is ready =cut -sub new { +has database => ( + is => 'rw', + lazy => 1, + default => $Foswiki::cfg{Cache}{DBI}{MySQL}{Database} || 'foswiki', +); +has host => ( + is => 'rw', + lazy => 1, + default => $Foswiki::cfg{Cache}{DBI}{MySQL}{Host} || 'localhost', +); +has port => ( + is => 'rw', + lazy => 1, + default => $Foswiki::cfg{Cache}{DBI}{MySQL}{Port} || '', +); + +around BUILDARGS => sub { + my $orig = shift; my $class = shift; - - my $this = bless( - $class->SUPER::new( - database => $Foswiki::cfg{Cache}{DBI}{MySQL}{Database} || 'foswiki', - host => $Foswiki::cfg{Cache}{DBI}{MySQL}{Host} || 'localhost', - port => $Foswiki::cfg{Cache}{DBI}{MySQL}{Port} || '', - username => $Foswiki::cfg{Cache}{DBI}{MySQL}{Username}, - password => $Foswiki::cfg{Cache}{DBI}{MySQL}{Password}, - @_ - ), - $class + return $orig->( + $class, + username => $Foswiki::cfg{Cache}{DBI}{MySQL}{Username}, + password => $Foswiki::cfg{Cache}{DBI}{MySQL}{Password}, + @_, ); +}; + +sub BUILD { + my $this = shift; - $this->{dsn} = 'dbi:mysql:database=' . $this->{database}; - $this->{dsn} .= ';host=' . $this->{host}; - $this->{dsn} .= ';port=' . $this->{port} if $this->{port}; + my $dsn = 'dbi:mysql:database=' . $this->database; + $dsn .= ';host=' . $this->host; + $dsn .= ';port=' . $this->port if $this->port; + + $this->dsn($dsn); return $this->init; } @@ -49,8 +64,10 @@ sub new { sub _createPagesTable { my $this = shift; - $this->{dbh}->do(<{pagesTable} ( + my $pagesTable = $this->pagesTable; + + $this->dbh->do(<{dbh} - ->do("create index $this->{pagesIndex} on $this->{pagesTable} (topic)"); + $this->dbh->do( "create index " + . $this->pagesIndex . " on " + . $this->pagesTable + . " (topic)" ); } sub _createDepsTable { my $this = shift; - $this->{dbh}->do(<{depsTable} ( + my $depsTable = $this->depsTable; + $this->dbh->do(<{dbh}->do( -"create index $this->{depsIndex} on $this->{depsTable} (from_topic, to_topic)" - ); + $this->dbh->do( "create index " + . $this->depsIndex . " on " + . $this->depsTable + . " (from_topic, to_topic)" ); } 1; diff --git a/core/lib/Foswiki/PageCache/DBI/PostgreSQL.pm b/core/lib/Foswiki/PageCache/DBI/PostgreSQL.pm index 37c69d882d..30d422d455 100644 --- a/core/lib/Foswiki/PageCache/DBI/PostgreSQL.pm +++ b/core/lib/Foswiki/PageCache/DBI/PostgreSQL.pm @@ -9,12 +9,10 @@ Implements a Foswiki::PageCache::DBI using postgresql =cut package Foswiki::PageCache::DBI::PostgreSQL; +use v5.14; -use strict; -use warnings; - -use Foswiki::PageCache::DBI (); -@Foswiki::PageCache::DBI::PostgreSQL::ISA = ('Foswiki::PageCache::DBI'); +use Moo; +extends qw(Foswiki::PageCache::DBI); =begin TML @@ -24,25 +22,41 @@ Construct a new page cache and makes sure the database is ready =cut -sub new { +has database => ( + is => 'rw', + lazy => 1, + default => $Foswiki::cfg{Cache}{DBI}{PostgreSQL}{Database} || 'foswiki', +); +has host => ( + is => 'rw', + lazy => 1, + default => $Foswiki::cfg{Cache}{DBI}{PostgreSQL}{Host} || 'localhost', +); +has port => ( + is => 'rw', + lazy => 1, + default => $Foswiki::cfg{Cache}{DBI}{PostgreSQL}{Port} || '', +); + +around BUILDARGS => sub { + my $orig = shift; my $class = shift; - - my $this = bless( - $class->SUPER::new( - database => $Foswiki::cfg{Cache}{DBI}{PostgreSQL}{Database} - || 'foswiki', - host => $Foswiki::cfg{Cache}{DBI}{PostgreSQL}{Host} || 'localhost', - port => $Foswiki::cfg{Cache}{DBI}{PostgreSQL}{Port} || '', - username => $Foswiki::cfg{Cache}{DBI}{PostgreSQL}{Username}, - password => $Foswiki::cfg{Cache}{DBI}{PostgreSQL}{Password}, - @_ - ), - $class + return $orig->( + $class, + username => $Foswiki::cfg{Cache}{DBI}{PostgreSQL}{Username}, + password => $Foswiki::cfg{Cache}{DBI}{PostgreSQL}{Password}, + @_, ); +}; + +sub BUILD { + my $this = shift; + + my $dsn = 'dbi:Pg:dbname=' . $this->database; + $dsn .= ';host=' . $this->host; + $dsn .= ';port=' . $this->port if $this->port; - $this->{dsn} = 'dbi:Pg:dbname=' . $this->{database}; - $this->{dsn} .= ';host=' . $this->{host}; - $this->{dsn} .= ';port=' . $this->{port} if $this->{port}; + $this->dsn($dsn); return $this->init; } diff --git a/core/lib/Foswiki/PageCache/DBI/SQLite.pm b/core/lib/Foswiki/PageCache/DBI/SQLite.pm index 2dc0dcb346..52448fe2d5 100644 --- a/core/lib/Foswiki/PageCache/DBI/SQLite.pm +++ b/core/lib/Foswiki/PageCache/DBI/SQLite.pm @@ -9,12 +9,10 @@ Implements a Foswiki::PageCache::DBI using sqlite =cut package Foswiki::PageCache::DBI::SQLite; +use v5.14; -use strict; -use warnings; - -use Foswiki::PageCache::DBI (); -@Foswiki::PageCache::DBI::SQLite::ISA = ('Foswiki::PageCache::DBI'); +use Moo; +extends qw(Foswiki::PageCache::DBI); =begin TML @@ -24,19 +22,17 @@ Construct a new page cache and makes sure the database is ready =cut -sub new { - my $class = shift; +has filename => ( + is => 'rw', + lazy => 1, + default => $Foswiki::cfg{Cache}{DBI}{SQLite}{Filename} + || $Foswiki::cfg{WorkingDir} . '/sqlite.db', +); - my $this = bless( - $class->SUPER::new( - filename => $Foswiki::cfg{Cache}{DBI}{SQLite}{Filename}, - @_ - ), - $class - ); +sub BUILD { + my $this = shift; - $this->{filename} ||= $Foswiki::cfg{WorkingDir} . '/sqlite.db'; - $this->{dsn} = 'dbi:SQLite:dbname=' . $this->{filename}; + $this->dsn( 'dbi:SQLite:dbname=' . $this->filename ); return $this->init; } diff --git a/core/lib/Foswiki/Plugins.pm b/core/lib/Foswiki/Plugins.pm index dcc039140c..98347c0e53 100644 --- a/core/lib/Foswiki/Plugins.pm +++ b/core/lib/Foswiki/Plugins.pm @@ -114,26 +114,9 @@ sub BUILD { return $this; } -=begin TML - ----++ ObjectMethod finish() -Break circular references. - -=cut - -# 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 { +sub DEMOLISH { my $this = shift; - $this->dispatch('finishPlugin'); - - $this->clear_registeredHandlers; - foreach ( @{ $this->plugins } ) { - $_->finish() if $_; - } - $this->clear_plugins; } =begin TML diff --git a/core/lib/Foswiki/Prefs.pm b/core/lib/Foswiki/Prefs.pm index 0b2b62cf5c..6db595241b 100644 --- a/core/lib/Foswiki/Prefs.pm +++ b/core/lib/Foswiki/Prefs.pm @@ -160,27 +160,27 @@ 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->clear_main; - $this->clear_prefix; - $this->clear_session; - $this->clear_contexts; - if ( $this->has_paths ) { - foreach my $back ( values %{ $this->paths } ) { - $back->finish() if $back; - } - } - $this->clear_paths; - if ( $this->has_webprefs ) { - foreach my $webStack ( values %{ $this->webprefs } ) { - $webStack->finish() if $webStack; - } - } - $this->clear_webprefs; - $this->clear_internals; -} +#sub finish { +# my $this = shift; +# +# $this->clear_main; +# $this->clear_prefix; +# $this->clear_session; +# $this->clear_contexts; +# if ( $this->has_paths ) { +# foreach my $back ( values %{ $this->paths } ) { +# $back->finish() if $back; +# } +# } +# $this->clear_paths; +# if ( $this->has_webprefs ) { +# foreach my $webStack ( values %{ $this->webprefs } ) { +# $webStack->finish() if $webStack; +# } +# } +# $this->clear_webprefs; +# $this->clear_internals; +#} # Get a backend object corresponding to the given $web,$topic sub _getBackend { diff --git a/core/lib/Foswiki/Prefs/Stack.pm b/core/lib/Foswiki/Prefs/Stack.pm index 3ec094d69a..f3d96801da 100644 --- a/core/lib/Foswiki/Prefs/Stack.pm +++ b/core/lib/Foswiki/Prefs/Stack.pm @@ -84,17 +84,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; - $this->clear_final; - if ( $this->has_levels ) { - foreach my $back ( @{ $this->levels } ) { - $back->finish() if $back; - } - } - $this->clear_levels; - $this->clear_map; -} +#sub finish { +# my $this = shift; +# $this->clear_final; +# if ( $this->has_levels ) { +# foreach my $back ( @{ $this->levels } ) { +# $back->finish() if $back; +# } +# } +# $this->clear_levels; +# $this->clear_map; +#} =begin TML diff --git a/core/lib/Foswiki/Prefs/TopicRAM.pm b/core/lib/Foswiki/Prefs/TopicRAM.pm index 5476d17a33..945acc6dff 100644 --- a/core/lib/Foswiki/Prefs/TopicRAM.pm +++ b/core/lib/Foswiki/Prefs/TopicRAM.pm @@ -57,8 +57,6 @@ sub BUILD { } } -sub finish { } - sub prefs { my $this = shift; return keys %{ $this->values }; diff --git a/core/lib/Foswiki/Prefs/Web.pm b/core/lib/Foswiki/Prefs/Web.pm index 5ca364b283..a3442670f3 100644 --- a/core/lib/Foswiki/Prefs/Web.pm +++ b/core/lib/Foswiki/Prefs/Web.pm @@ -48,13 +48,13 @@ 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; - - # SMELL What if stack wasn't cloned but is used by some other object at this - # time? Is it possible at all? - $this->{stack}->finish() if $this->{stack}; -} +#sub finish { +# my $this = shift; +# +# # SMELL What if stack wasn't cloned but is used by some other object at this +# # time? Is it possible at all? +# $this->stack->finish() if $this->{stack}; +#} =begin TML diff --git a/core/lib/Foswiki/Serialise.pm b/core/lib/Foswiki/Serialise.pm index b78cdea551..767c681e5f 100644 --- a/core/lib/Foswiki/Serialise.pm +++ b/core/lib/Foswiki/Serialise.pm @@ -126,13 +126,10 @@ this, except perhaps from the unit test framework; see Item11349. =cut -sub finish { +sub DEMOLISH { my ($this) = @_; while ( my ( $name, $cereal ) = each %serialisers ) { - if ( $cereal->can('finish') ) { - $cereal->finish(); - } delete $serialisers{$name}; } diff --git a/core/lib/Foswiki/UI.pm b/core/lib/Foswiki/UI.pm index 9edc87f30c..aa6f9edd37 100644 --- a/core/lib/Foswiki/UI.pm +++ b/core/lib/Foswiki/UI.pm @@ -499,7 +499,7 @@ sub _execute { } } }; - $session->finish() if $session; + undef $session; return $res; } diff --git a/core/lib/Foswiki/Users.pm b/core/lib/Foswiki/Users.pm index 7db385a645..c1458d1d85 100644 --- a/core/lib/Foswiki/Users.pm +++ b/core/lib/Foswiki/Users.pm @@ -206,40 +206,6 @@ sub loadSession { =begin TML ----++ ObjectMethod finish() -Break circular references. - -=cut - -# 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. -around finish => sub { - my $orig = shift; - my $this = shift; - - #$this->loginManager->finish() if $this->loginManager; - #$this->basemapping->finish() if $this->basemapping; - - #$this->mapping->finish() - # if $this->mapping - # && $this->mapping ne $this->basemapping; - - $this->clear_loginManager; - $this->clear_basemapping; - $this->clear_mapping; - $this->clear_session; - $this->clear_cUID2WikiName; - $this->clear_cUID2Login; - $this->clear_wikiName2cUID; - $this->clear_login2cUID; - $this->_clear_isAdmin; - - $orig->( $this, @_ ); -}; - -=begin TML - ---++ ObjectMethod loginTemplateName () -> templateFile allows UserMappings to come with customised login screens - that should preffereably only over-ride the UI function