Skip to content

Commit

Permalink
Item14152: Cherry picked of some changes from commit 505aef1
Browse files Browse the repository at this point in the history
- TBM Fixed Foswiki::App cleanup upon early failure, before login manager
initialized.

- Foswiki::Config now calls unAssignGLOB upon destruction.

- Fixes and cleanups.
  • Loading branch information
vrurg committed Sep 19, 2016
1 parent 3a0d9d8 commit 8d05d64
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 28 deletions.
4 changes: 3 additions & 1 deletion UnitTestContrib/lib/Unit/TestApp.pm
Expand Up @@ -95,7 +95,9 @@ sub cloneEnv {
my $this = shift;

# SMELL Use Foswiki::Object internals.
return $this->_cloneData( $this->env, 'env' );
my $clonedEnv = $this->_cloneData( $this->env, 'env' );
$this->_clear__clone_heap;
return $clonedEnv;
}

sub registerCallbacks {
Expand Down
3 changes: 1 addition & 2 deletions UnitTestContrib/lib/Unit/TestCase.pm
Expand Up @@ -20,8 +20,7 @@ use Foswiki::Exception ();
use Text::Diff ();
require File::Temp;

use Moo;
use namespace::clean;
use Foswiki::Class;
extends 'Foswiki::Object';

$Carp::Verbose = 1;
Expand Down
4 changes: 2 additions & 2 deletions UnitTestContrib/test/bin/TestRunner.pl
Expand Up @@ -29,8 +29,8 @@ sub _findRelativeTo {
BEGIN {
if ( not defined $ENV{FOSWIKI_ASSERTS} or $ENV{FOSWIKI_ASSERTS} eq 'soft' )
{
print
"exporting FOSWIKI_ASSERTS=1 for extra checking; disable by exporting FOSWIKI_ASSERTS=0\n";
say STDERR
"exporting FOSWIKI_ASSERTS=1 for extra checking; disable by exporting FOSWIKI_ASSERTS=0";
$ENV{FOSWIKI_ASSERTS} = 1;
}

Expand Down
13 changes: 6 additions & 7 deletions UnitTestContrib/test/unit/FoswikiTestCase.pm
Expand Up @@ -24,14 +24,14 @@ use Scalar::Util qw(blessed);
require Digest::MD5;
require Foswiki::Validation;

use Foswiki();
use Foswiki::Meta();
use Foswiki::Plugins();
use Foswiki::Store();
use Foswiki ();
use Foswiki::Meta ();
use Foswiki::Plugins ();
use Foswiki::Store ();

#use Unit::Response();
use Try::Tiny;
use Storable();
use Storable ();

use constant SINGLE_SINGLETONS => 0;
use constant TRACE => 0;
Expand All @@ -44,8 +44,7 @@ my $cleanup = $ENV{FOSWIKI_DEBUG_KEEP} ? 0 : 1;

our $didOnlyOnceChecks = 0;

use Moo;
use namespace::clean;
use Foswiki::Class;
extends qw(Unit::TestCase);
with qw(Foswiki::Aux::Localize Unit::FoswikiTestRole);

Expand Down
8 changes: 5 additions & 3 deletions core/lib/Foswiki.pm
Expand Up @@ -62,9 +62,11 @@ use Try::Tiny;

use Assert;
use Exporter qw(import);
our @EXPORT_OK =
qw(%regex urlEncode urlDecode make_params load_package load_class
expandStandardEscapes findCaller findCallerByPrefix isTrue);
our @EXPORT_OK = qw(
%regex urlEncode urlDecode make_params load_package load_class
expandStandardEscapes findCaller findCallerByPrefix isTrue
fetchGlobal getNS
);

sub SINGLE_SINGLETONS { 0 }
sub SINGLE_SINGLETONS_TRACE { 0 }
Expand Down
15 changes: 6 additions & 9 deletions core/lib/Foswiki/App.pm
Expand Up @@ -406,8 +406,10 @@ sub DEMOLISH {
my $this = shift;
my ($in_global) = @_;

$this->users->loginManager->complete;

# Make sure not to do this if incomplete initialization happened or we're
# doomed for "(in cleanup)" messages.
$this->users->loginManager->complete
if $this->has_users && $this->users->has_loginManager;
}

=begin TML
Expand Down Expand Up @@ -607,13 +609,8 @@ sub create {

Foswiki::load_class($class);

my $object;
if ( $class->does('Foswiki::AppObject') ) {
$object = $class->new( app => $this, @_ );
}
else {
$object = $class->new(@_);
}
my $object = $class->new( app => $this, @_ );

return $object;
}

Expand Down
19 changes: 17 additions & 2 deletions core/lib/Foswiki/Config.pm
@@ -1,7 +1,6 @@
# See bottom of file for license and copyright information

package Foswiki::Config;
use v5.14;

=begin TML
Expand All @@ -22,7 +21,7 @@ use Try::Tiny;
use Foswiki qw(urlEncode urlDecode make_params);
use Foswiki::Configure::FileUtil;

use Foswiki::Class qw(app);
use Foswiki::Class qw(app extensible);
extends qw(Foswiki::Object);
with qw(Foswiki::Aux::Localize);

Expand Down Expand Up @@ -157,6 +156,11 @@ sub BUILD {
$this->_setupGlobals;
}

sub DEMOLISH {
my $this = shift;
$this->unAssignGLOB;
}

sub _workOutOS {
my $this = shift;
unless ( $this->data->{DetailedOS} ) {
Expand Down Expand Up @@ -1760,6 +1764,17 @@ sub assignGLOB {
*Foswiki::cfg = $data;
}

sub unAssignGLOB {
my $this = shift;

my $glob = Foswiki::getNS('Foswiki');

if ( *{ $glob->{cfg} }{HASH} eq $this->data ) {
my %empty;
*Foswiki::cfg = \%empty;
}
}

# Check if $Foswiki::cfg is an alias to this object's data attribute. Useful for
# debugging only.
sub _validateBindings {
Expand Down
11 changes: 10 additions & 1 deletion core/lib/Foswiki/Object.pm
@@ -1,7 +1,6 @@
# See bottom of file for license and copyright information

package Foswiki::Object;
use v5.14;

=begin TML
Expand Down Expand Up @@ -442,6 +441,16 @@ sub isaCLASS {
);
}

sub _traceMsg {
my $this = shift;

if (DEBUG) {
my ( $pkg, $file, $line ) = caller;

say STDERR $pkg, "(line ", $line, ", obj ", $this, "): ", @_;
}
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Users.pm
Expand Up @@ -87,7 +87,7 @@ has basemapping => (
'basemapping', 'Foswiki::Object', does => 'Foswiki::UserMapping',
),
);
has loginManager => ( is => 'rw', );
has loginManager => ( is => 'rw', predicate => 1, );
has login2cUID => (
is => 'rw',
lazy => 1,
Expand Down

0 comments on commit 8d05d64

Please sign in to comment.