Navigation Menu

Skip to content

Commit

Permalink
Item13897: Very intermidiate commit.
Browse files Browse the repository at this point in the history
Just preserving what's been done so far.

- Added Foswiki::Macros to cope with all kind of macros/tags handling
including registration and expansion.

- In process of converting Foswiki::UI into a class. Plans are to move
request handling completly from Foswiki::UI into Foswiki::App.

- Moved a bunch of methods from Foswiki.pm into Foswiki::App.

- SwitchBoard configuration key is now set by Foswiki::Config. I consider
it reasonable to have all hard-coded settings not stored in external files
are to be set at a single location.

- Foswiki::Engine, Foswiki::Request are all Foswiki::AppObject now.
  • Loading branch information
vrurg committed Mar 25, 2016
1 parent a5c6cc8 commit 3736ccf
Show file tree
Hide file tree
Showing 8 changed files with 1,216 additions and 1,222 deletions.
1,053 changes: 0 additions & 1,053 deletions core/lib/Foswiki.pm

Large diffs are not rendered by default.

86 changes: 84 additions & 2 deletions core/lib/Foswiki/App.pm
Expand Up @@ -13,7 +13,7 @@ extends qw(Foswiki::Object);

=begin TML
---+!! package Foswiki::App
---+!! Class Foswiki::App
The core class of the project responsible for low-level and code glue
functionality.
Expand Down Expand Up @@ -44,6 +44,29 @@ has request => (
isa =>
Foswiki::Object::isaCLASS( 'request', 'Foswiki::Request', noUndef => 1, ),
);
has macros => (
is => 'rw',
lazy => 1,
default => sub { return $_[0]->create('Foswiki::Macros'); },
isa =>
Foswiki::Object::isaCLASS( 'macros', 'Foswiki::Macros', noUndef => 1, ),
);
has context => (
is => 'rw',
lazy => 1,
clearer => 1,
default => sub { {} },
);
has ui => (
is => 'rw',
lazy => 1,
default => sub {
return $_[0]->create('Foswiki::UI');
},
);

# App-local $Foswiki::system_message.
has system_message => ( is => 'rw', );

=begin TML
Expand Down Expand Up @@ -161,14 +184,73 @@ sub create {
return $class->new( app => $this, @_ );
}

=begin TML
---++ ObjectMethod enterContext( $id, $val )
Add the context id $id into the set of active contexts. The $val
can be anything you like, but should always evaluate to boolean
TRUE.
An example of the use of contexts is in the use of tag
expansion. The commonTagsHandler in plugins is called every
time tags need to be expanded, and the context of that expansion
is signalled by the expanding module using a context id. So the
forms module adds the context id "form" before invoking common
tags expansion.
Contexts are not just useful for tag expansion; they are also
relevant when rendering.
Contexts are intended for use mainly by plugins. Core modules can
use $session->inContext( $id ) to determine if a context is active.
=cut

sub enterContext {
my ( $this, $id, $val ) = @_;
$val ||= 1;
$this->context->{$id} = $val;
}

=begin TML
---++ ObjectMethod leaveContext( $id )
Remove the context id $id from the set of active contexts.
(see =enterContext= for more information on contexts)
=cut

sub leaveContext {
my ( $this, $id ) = @_;
my $res = $this->context->{$id};
delete $this->context->{$id};
return $res;
}

=begin TML
---++ ObjectMethod inContext( $id )
Return the value for the given context id
(see =enterContext= for more information on contexts)
=cut

sub inContext {
my ( $this, $id ) = @_;
return $this->context->{$id};
}

sub _prepareEngine {
my $this = shift;
my $env = $this->env;
my $engine;

# Foswiki::Engine has to determine what environment are we run within and
# return an object of corresponding class.
$engine = Foswiki::Engine::start( env => $env );
$engine = Foswiki::Engine::start( env => $env, app => $this, );

return $engine;
}
Expand Down
146 changes: 144 additions & 2 deletions core/lib/Foswiki/Config.pm
Expand Up @@ -93,6 +93,8 @@ sub BUILD {
$this->data->{isVALID} =
$this->readConfig( $this->noExpand, $this->noSpec, $this->configSpec,
$this->noLocal, );

$this->_populatePresets;
}

sub _workOutOS {
Expand Down Expand Up @@ -512,8 +514,7 @@ BOOTS
chomp $system_message;
$system_message .= $warn . "\n";
}
return ( $system_message || '' );

$this->bootstrapMessage( $system_message // '' );
}

=begin TML
Expand Down Expand Up @@ -673,6 +674,147 @@ sub setBootstrap {
push( @{ $this->data->{BOOTSTRAP} }, @BOOTSTRAP );
}

# Preset values that are hard-coded and not coming from external sources.
sub _populatePresets {
my $this = shift;

$this->data->{SwitchBoard} //= {};

# package - perl package that contains the method for this request
# function - name of the function in package
# context - hash of context vars to define
# allow - hash of HTTP methods to allow (all others are denied)
# deny - hash of HTTP methods that are denied (all others are allowed)
# 'deny' is not tested if 'allow' is defined

# The switchboard can contain entries either as hashes or as arrays.
# The array format specifies [0] package, [1] function, [2] context
# and should be used when declaring scripts from plugins that must work
# with Foswiki 1.0.0 and 1.0.4.

$this->data->{SwitchBoard}{attach} = {
package => 'Foswiki::UI::Attach',
function => 'attach',
context => { attach => 1 },
};
$this->data->{SwitchBoard}{changes} = {
package => 'Foswiki::UI::Changes',
function => 'changes',
context => { changes => 1 },
};
$this->data->{SwitchBoard}{configure} = {
package => 'Foswiki::UI::Configure',
function => 'configure'
};
$this->data->{SwitchBoard}{edit} = {
package => 'Foswiki::UI::Edit',
function => 'edit',
context => { edit => 1 },
};
$this->data->{SwitchBoard}{jsonrpc} = {
package => 'Foswiki::Contrib::JsonRpcContrib',
function => 'dispatch',
context => { jsonrpc => 1 },
};
$this->data->{SwitchBoard}{login} = {
package => undef,
function => 'logon',
context => { ( login => 1, logon => 1 ) },
};
$this->data->{SwitchBoard}{logon} = {
package => undef,
function => 'logon',
context => { ( login => 1, logon => 1 ) },
};
$this->data->{SwitchBoard}{manage} = {
package => 'Foswiki::UI::Manage',
function => 'manage',
context => { manage => 1 },
allow => { POST => 1 },
};
$this->data->{SwitchBoard}{oops} = {
package => 'Foswiki::UI::Oops',
function => 'oops_cgi',
context => { oops => 1 },
};
$this->data->{SwitchBoard}{preview} = {
package => 'Foswiki::UI::Preview',
function => 'preview',
context => { preview => 1 },
};
$this->data->{SwitchBoard}{previewauth} =
$this->data->{SwitchBoard}{preview};
$this->data->{SwitchBoard}{rdiff} = {
package => 'Foswiki::UI::RDiff',
function => 'diff',
context => { diff => 1 },
};
$this->data->{SwitchBoard}{rdiffauth} = $this->data->{SwitchBoard}{rdiff};
$this->data->{SwitchBoard}{register} = {
package => 'Foswiki::UI::Register',
function => 'register_cgi',
context => { register => 1 },

# method verify must allow GET; protect in Foswiki::UI::Register
#allow => { POST => 1 },
};
$this->data->{SwitchBoard}{rename} = {
package => 'Foswiki::UI::Rename',
function => 'rename',
context => { rename => 1 },

# Rename is 2 stage; protect in Foswiki::UI::Rename
#allow => { POST => 1 },
};
$this->data->{SwitchBoard}{resetpasswd} = {
package => 'Foswiki::UI::Passwords',
function => 'resetPassword',
context => { resetpasswd => 1 },
allow => { POST => 1 },
};
$this->data->{SwitchBoard}{rest} = {
package => 'Foswiki::UI::Rest',
function => 'rest',
context => { rest => 1 },
};
$this->data->{SwitchBoard}{restauth} = $this->data->{SwitchBoard}{rest};
$this->data->{SwitchBoard}{save} = {
package => 'Foswiki::UI::Save',
function => 'save',
context => { save => 1 },
allow => { POST => 1 },
};
$this->data->{SwitchBoard}{search} = {
package => 'Foswiki::UI::Search',
function => 'search',
context => { search => 1 },
};
$this->data->{SwitchBoard}{statistics} = {
package => 'Foswiki::UI::Statistics',
function => 'statistics',
context => { statistics => 1 },
};
$this->data->{SwitchBoard}{upload} = {
package => 'Foswiki::UI::Upload',
function => 'upload',
context => { upload => 1 },
allow => { POST => 1 },
};
$this->data->{SwitchBoard}{viewfile} = {
package => 'Foswiki::UI::Viewfile',
function => 'viewfile',
context => { viewfile => 1 },
};
$this->data->{SwitchBoard}{viewfileauth} =
$this->data->{SwitchBoard}{viewfile};
$this->data->{SwitchBoard}{view} = {
package => 'Foswiki::UI::View',
function => 'view',
context => { view => 1 },
};
$this->data->{SwitchBoard}{viewauth} = $this->data->{SwitchBoard}{view};
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Expand Down
4 changes: 2 additions & 2 deletions core/lib/Foswiki/Engine.pm
Expand Up @@ -22,7 +22,7 @@ use Unicode::Normalize;

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

BEGIN {
if ( $Foswiki::cfg{UseLocale} ) {
Expand Down Expand Up @@ -131,7 +131,7 @@ sub prepare {
}

try {
$req = Foswiki::Request->new();
$req = $this->create('Foswiki::Request');
$this->prepareConnection($req);
$this->prepareQueryParameters($req);
$this->prepareHeaders($req);
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Exception.pm
Expand Up @@ -249,7 +249,7 @@ package Foswiki::Exception::ASSERT;
use Moo;
extends qw(Foswiki::Exception);

# This class is to distinguish ASSERT-generated exceptions only.
# This class is only for distinguishing ASSERT-generated exceptions.

sub BUILD {

Expand Down

0 comments on commit 3736ccf

Please sign in to comment.