Skip to content

Commit

Permalink
Item13897: Minor adjustments
Browse files Browse the repository at this point in the history
- Converted few missed modules.

- Session object destroy stage fix.

! Bootstrap mode doesn't start.
  • Loading branch information
vrurg committed Mar 15, 2016
1 parent dae8e37 commit 4976d59
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 156 deletions.
2 changes: 1 addition & 1 deletion EditRowPlugin/lib/Foswiki/Plugins/EditRowPlugin/Get.pm
Expand Up @@ -89,7 +89,7 @@ sub process {
)
{
$result = $table->getCell($urps);
$table->finish();
undef $table;
last LINE;
}
}
Expand Down
2 changes: 1 addition & 1 deletion EditRowPlugin/lib/Foswiki/Plugins/EditRowPlugin/Save.pm
Expand Up @@ -168,7 +168,7 @@ sub process {
}
}
$line = $table->stringify();
$table->finish();
undef $table;
$nlines .= $line;
}
else {
Expand Down
2 changes: 1 addition & 1 deletion EditRowPlugin/lib/Foswiki/Plugins/EditRowPlugin/View.pm
Expand Up @@ -217,7 +217,7 @@ sub process {
$line .= '</form>' if $table->attrs->{js} ne 'ignored';
}

$table->finish();
#$table->finish;

# If this is an included topic, mark the table as having
# being included so we don't attempt to reprocess it
Expand Down
1 change: 1 addition & 0 deletions UnitTestContrib/lib/Unit/TestRunner.pm
Expand Up @@ -33,6 +33,7 @@ BEGIN {
eval "use Devel::Leak::Object qw{ GLOBAL_bless };";
die $@ if $@;
$Devel::Leak::Object::TRACKSOURCELINES = 1;
$Devel::Leak::Object::TRACKSTACK = 1;
}
}

Expand Down
2 changes: 1 addition & 1 deletion UnitTestContrib/test/unit/Fn_SEP.pm
@@ -1,8 +1,8 @@
use strict;

# tests for the correct expansion of SEP

package Fn_SEP;
use v5.14;

use Foswiki;

Expand Down
8 changes: 5 additions & 3 deletions UnitTestContrib/test/unit/FoswikiTestCase.pm
Expand Up @@ -45,9 +45,9 @@ extends 'Unit::TestCase';

has session => (
is => 'rw',
weak_ref => 1,
predicate => 1,
clearer => 1,
weak_ref => 1,
isa => Foswiki::Object::isaCLASS( 'session', 'Foswiki', strictMatch => 1, ),
);
has twiki => ( is => 'rw', );
Expand Down Expand Up @@ -1057,8 +1057,8 @@ __DO NOT CALL session->finish() yourself__
sub createNewFoswikiSession {
my ( $this, $user, $query, @args ) = @_;

$this->clear_test_topicObject if $this->has_test_topicObject;
$this->clear_session if $this->session;
$this->clear_test_topicObject;
$this->clear_session;
ASSERT( !defined $Foswiki::Plugins::SESSION ) if SINGLE_SINGLETONS;
$Foswiki::cfg{Store}{Implementation} ||= 'Foswiki::Store::PlainFile';
$this->session( Foswiki->new( user => $user, request => $query, @args ) );
Expand All @@ -1077,6 +1077,8 @@ sub finishFoswikiSession {
my ($this) = @_;

#$this->session->finish() if $this->has_session;
#use Devel::Refcount;
#say STDERR "session refcount: ", Devel::Refcount::refcount($this->session);
$this->clear_session;
ASSERT( !$Foswiki::Plugins::SESSION ) if SINGLE_SINGLETONS;

Expand Down
38 changes: 19 additions & 19 deletions core/lib/Foswiki.pm
Expand Up @@ -122,7 +122,7 @@ has attach => (
predicate => 1,
default => sub {
require Foswiki::Attach;
new Foswiki::Attach( $_[0] );
new Foswiki::Attach( session => $_[0] );
},
);
has cache => (
Expand Down Expand Up @@ -335,7 +335,7 @@ has templates => (
clearer => 1,
default => sub {
require Foswiki::Templates;
return Foswiki::Templates->new( $_[0] );
return Foswiki::Templates->new( session => $_[0] );
},
);
has topicName => (
Expand Down Expand Up @@ -1106,6 +1106,17 @@ sub BUILD {
. Data::Dumper->Dump( [ [caller], [ caller(1) ] ] );
}

# This is required in case we get an exception during
# initialisation, so that we have a session to handle it with.
ASSERT( !$Foswiki::Plugins::SESSION ) if SINGLE_SINGLETONS;

$Foswiki::Plugins::SESSION = $this;

ASSERT( $Foswiki::Plugins::SESSION,
"\$Foswiki::Plugins::SESSION was most likely unexpectedly cleared by destructor."
);
ASSERT( $Foswiki::Plugins::SESSION->isa('Foswiki') ) if DEBUG;

my $query = $this->request;

# Phase 2 of Bootstrap. Web settings require that the Foswiki request
Expand All @@ -1124,21 +1135,6 @@ sub BUILD {
}
}

# This is required in case we get an exception during
# initialisation, so that we have a session to handle it with.
ASSERT( !$Foswiki::Plugins::SESSION ) if SINGLE_SINGLETONS;

# SMELL This global session variable not to exists whatsoever! There're two
# ways around this variable to ever exists: a singleton object or every
# piece of code requiring access to session to be a part of an object. Yet,
# a singleton object doesn't solve a problem with multi-session environments
# where code may serve few different requests at once. Think of requests on
# hold waiting for some data from external sources while concurring requests
# are being processed.
$Foswiki::Plugins::SESSION = $this;

ASSERT( $Foswiki::Plugins::SESSION->isa('Foswiki') ) if DEBUG;

# construct the store object
my $base = $Foswiki::cfg{Store}{Implementation}
|| 'Foswiki::Store::PlainFile';
Expand Down Expand Up @@ -2686,8 +2682,12 @@ Break circular references.
sub DEMOLISH {
my $this = shift;

#$this->clear_plugins;
undef $Foswiki::Plugins::SESSION;
$this->clear_plugins;
$this->clear_forms;
if ( $this == $Foswiki::Plugins::SESSION ) {
#say STDERR $this, " Here we clear the old Plugins::SESSION";
undef $Foswiki::Plugins::SESSION;
}
}

=begin TML
Expand Down
46 changes: 21 additions & 25 deletions core/lib/Foswiki/Attach.pm
Expand Up @@ -9,12 +9,15 @@ A singleton object of this class is used to deal with attachments to topics.
=cut

package Foswiki::Attach;
use v5.14;

use strict;
use warnings;
use Assert;
use Unicode::Normalize;

use Moo;
use namespace::clean;
extends qw(Foswiki::Object);

BEGIN {
if ( $Foswiki::cfg{UseLocale} ) {
require locale;
Expand All @@ -24,36 +27,29 @@ BEGIN {

our $MARKER = "\0";

has session => (
is => 'rw',
clearer => 1,
required => 1,
weak_ref => 1,
isa => Foswiki::Object::isaCLASS( 'session', 'Foswiki', noUndef => 1 ),
);

=begin TML
---++ ClassMethod new($session)
---++ ClassMethod new(session => $session)
Constructor.
=cut

sub new {
my ( $class, $session ) = @_;
my $this = bless( { session => $session }, $class );

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 {
my $this = shift;
undef $this->{session};
}

=begin TML
---++ ObjectMethod renderMetaData( $topicObject, $args ) -> $text
Expand Down Expand Up @@ -97,7 +93,7 @@ sub renderMetaData {
my @attachments = $topicObject->find('FILEATTACHMENT');
return '' unless @attachments;

my $templates = $this->{session}->templates;
my $templates = $this->session->templates;
$templates->readTemplate($tmplname);

my $rows = '';
Expand Down Expand Up @@ -146,15 +142,15 @@ Generate a version history table for a single attachment
sub formatVersions {
my ( $this, $topicObject, %attrs ) = @_;

my $users = $this->{session}->{users};
my $users = $this->session->users;

$attrs{name} =
Foswiki::Sandbox::untaint( $attrs{name},
\&Foswiki::Sandbox::validateAttachmentName );

my $revIt = $topicObject->getRevisionHistory( $attrs{name} );

my $templates = $this->{session}->templates;
my $templates = $this->session->templates;
$templates->readTemplate('attachtables');

my $header = $templates->expandTemplate('ATTACH:versions:header');
Expand Down Expand Up @@ -208,7 +204,7 @@ s/%R_(\w+)%/_expandRowAttrs( $this, $1, $topicObject, $info, $attachmentNum, $is
sub _expandAttrs {
my ( $this, $attr, $topicObject, $info, $attachmentNum ) = @_;
my $file = $info->{name} || '';
my $users = $this->{session}->{users};
my $users = $this->session->users;

require Foswiki::Time;

Expand All @@ -226,7 +222,7 @@ sub _expandAttrs {
return $1;
}
elsif ( $attr eq 'URL' ) {
return $this->{session}->getScriptUrl(
return $this->session->getScriptUrl(
0, 'viewfile', $topicObject->web, $topicObject->topic,
rev => $info->{version} || undef,
filename => $file
Expand Down Expand Up @@ -306,7 +302,7 @@ sub _expandRowAttrs {
sub _cUID {
my ( $this, $info ) = @_;

my $users = $this->{session}->{users};
my $users = $this->session->users;
my $user = $info->{author} || $info->{user} || 'UnknownUser';
my $cUID;
if ($user) {
Expand Down Expand Up @@ -372,7 +368,7 @@ sub getAttachmentLink {

my $fileLink = '';
my $imgSize = '';
my $prefs = $this->{session}->{prefs};
my $prefs = $this->session->prefs;

if ( $attName =~ m/\.(gif|jpg|jpeg|png)$/i ) {

Expand Down
8 changes: 4 additions & 4 deletions core/lib/Foswiki/I18N.pm
Expand Up @@ -41,7 +41,7 @@ has _lh => (
clearer => 1,
builder => '_initLanguageHandler',
);
has _session => (
has session => (
is => 'rw',
weak_ref => 1,
init_arg => 'session',
Expand Down Expand Up @@ -112,7 +112,7 @@ sub _loadLexicon {
"
)
{
$this->_session->logger->log( 'warning',
$this->session->logger->log( 'warning',
"I18N - Error loading language $lang: $@\n" );
}
}
Expand All @@ -121,7 +121,7 @@ sub _loadLexicon {
sub _initI18N {
my $this = shift;

my $session = $this->_session;
my $session = $this->session;
my $initialised = 0;

# no languages enabled is the same as disabling
Expand Down Expand Up @@ -177,7 +177,7 @@ sub _initI18N {
sub _initLanguageHandler {
my $this = shift;

my $session = $this->_session;
my $session = $this->session;
my $lh;

# guesses the language from the CGI environment
Expand Down

0 comments on commit 4976d59

Please sign in to comment.