From 358b10438b145e841438bb2917091720b5d83bb2 Mon Sep 17 00:00:00 2001 From: Vadim Belman Date: Fri, 5 May 2017 21:37:50 -0400 Subject: [PATCH] Item14237: Better support for extensions at early stages of the app life. - Config and extensions are now being loaded in a two-stage process where first basic config class is used to initialize the config. Then extensions are loaded. After that the process is repeated but at this point the config could be loaded with a help of an extension. - Added 'initStage' attribute to inidicate what is the current stage of app initialization. Makes sense until contexts could be used. - Added declaration of OOSPECS feature. - Fixed a bug with deep recursion in create() method. --- core/lib/Foswiki/App.pm | 38 ++++++++++++++++++++++---------------- core/lib/Foswiki/Config.pm | 6 ++---- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/core/lib/Foswiki/App.pm b/core/lib/Foswiki/App.pm index 435ce70fff..c4788ebb0a 100644 --- a/core/lib/Foswiki/App.pm +++ b/core/lib/Foswiki/App.pm @@ -47,6 +47,11 @@ features_provided PREF_SET_URLS => [ undef, undef, undef ], PSGI => [ 2.99, undef, undef, -desc => 'PSGI support', ], UNICODE => [ 2.0, undef, undef, -desc => 'Unicode core', ], + OOSPECS => [ + 2.99, undef, undef, + -desc => "Perl Specs", + -proposal => "OOConfigSpecsFormat", + ], ; has access => ( @@ -114,6 +119,7 @@ has extensions => ( is => 'ro', lazy => 1, predicate => 1, + clearer => 1, builder => 'prepareExtensions', ); has forms => ( @@ -345,22 +351,17 @@ sub BUILD { $Foswiki::app = $this; - $this->initStage('initConfig'); - - unless ( $this->cfg->data->{isVALID} ) { - $this->cfg->bootstrapSystemSettings; - } - - $this->initStage('extLoad'); - - $this->extensions->initialize; - - $this->clear_cfg; - - $this->initStage('reConfig'); + for my $stNum ( 1 .. 2 ) { + $this->clear_cfg; + $this->initStage( 'readConfig' . $stNum ); + unless ( $this->cfg->data->{isVALID} ) { + $this->cfg->bootstrapSystemSettings; + } + $this->initStage( 'loadExtensions' . $stNum ); - unless ( $this->cfg->data->{isVALID} ) { - $this->cfg->bootstrapSystemSettings; + # Reload extensions based on the configuration information. + $this->clear_extensions; + $this->extensions->initialize; } $this->initStage('postConfig'); @@ -658,7 +659,12 @@ sub create { Foswiki::load_class($class); - $class = $this->extensions->mapClass($class); + if ( $this->has_extensions ) { + + # Avoid referring to extensions if we're on very early stages of the app + # existance. + $class = $this->extensions->mapClass($class); + } my $object; diff --git a/core/lib/Foswiki/Config.pm b/core/lib/Foswiki/Config.pm index 51ea2a501d..069eaeca00 100644 --- a/core/lib/Foswiki/Config.pm +++ b/core/lib/Foswiki/Config.pm @@ -297,9 +297,7 @@ has _lscRecords => ( ); # Current position in _lscRecords list. -has _lscRecPos => ( - is => 'rw', -); +has _lscRecPos => ( is => 'rw', ); # Configuration shortcut attributes. @@ -772,7 +770,7 @@ pluggable read => sub { # SMELL Docs missing pluggable readLSCStart => sub { - my $this = shift; + my $this = shift; my %params = @_; $this->_clear_lscRecords;