Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Item13897: Outline for the session object replacement.
App.pm contains first strokes to the new core class.
- Loading branch information
Showing
1 changed file
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
# See bottom of file for license and copyright information | ||
|
||
package Foswiki::App; | ||
use v5.14; | ||
|
||
use Cwd; | ||
|
||
use Moo; | ||
use namespace::clean; | ||
extends qw(Foswiki::Object); | ||
with qw(Foswiki::Config); | ||
|
||
=begin TML | ||
---+!! package Foswiki::App | ||
The core class of the project responsible for low-level and code glue | ||
functionality. | ||
=cut | ||
|
||
has cfg => ( | ||
is => 'rw', | ||
lazy => 1, | ||
default => \&_readConfig, | ||
isa => Foswiki::Object::isaCLASS( 'cfg', 'Foswiki::Config', noUndef => 1, ), | ||
); | ||
has env => ( | ||
is => 'rw', | ||
required => 1, | ||
); | ||
has engine => ( | ||
is => 'rw', | ||
lazy => 1, | ||
default => \&_prepareEngine, | ||
isa => | ||
Foswiki::Object::isaCLASS( 'engine', 'Foswiki::Engine', noUndef => 1, ), | ||
); | ||
has request => ( | ||
is => 'rw', | ||
lazy => 1, | ||
default => \&_prepareRequest, | ||
isa => | ||
Foswiki::Object::isaCLASS( 'request', 'Foswiki::Request', noUndef => 1, ), | ||
); | ||
|
||
=begin TML | ||
---++ ClassMethod new([%parameters]) | ||
The following keys could be defined in =%parameters= hash: | ||
|*Key*|*Type*|*Description*| | ||
|=env=|hashref|Environment hash such as shell environment or PSGI env| | ||
=cut | ||
|
||
around BUILDARGS => sub { | ||
my $orig = shift; | ||
my $class = shift; | ||
my %params = @_; | ||
|
||
return $orig->( $class, %params ); | ||
}; | ||
|
||
sub BUILD { | ||
my $this = shift; | ||
my $params = shift; | ||
|
||
if ( $this->cfg->{isBOOTSTRAPPING} ) { | ||
|
||
#code | ||
} | ||
|
||
} | ||
|
||
=begin TML | ||
---++ StaticMethod run([%parameters]) | ||
Starts application, prepares and initiates request processing. The following | ||
keys could be defined in =%parameters= hash: | ||
|*Key*|*Type*|*Description*| | ||
|=env=|hashref|Environment hash such as shell environment or PSGI env| | ||
=cut | ||
|
||
sub run { | ||
my %params = @_; | ||
|
||
my $app; | ||
|
||
# We use shell environment by default. PSGI would supply its own env | ||
# hashref. | ||
$params{env} //= \%ENV; | ||
|
||
# Use current working dir for fetching the initial setlib.cfg | ||
$params{env}{PWD} //= getcwd; | ||
|
||
try { | ||
$app = Foswiki::App->new(%params); | ||
$app->handleRequest; | ||
} | ||
catch { | ||
my $e = $_; | ||
|
||
# Low-level report of errors to user. | ||
if ( $app && $app->engine ) { | ||
|
||
# TODO Send error output to user using the initialized engine. | ||
...; | ||
} | ||
else { | ||
# Propagade the error using the most primitive way. | ||
die( ref($e) ? $e->stringify : $e ); | ||
} | ||
}; | ||
} | ||
|
||
sub handleRequest { | ||
|
||
} | ||
|
||
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 ); | ||
|
||
return $engine; | ||
} | ||
|
||
sub _prepareRequest { | ||
my $this = shift; | ||
my $request = $this->engine->prepare; | ||
return $request; | ||
} | ||
|
||
sub _readConfig { | ||
my $this = shift; | ||
my $cfg = Foswiki::Config->new( env => $this->env ); | ||
return $cfg; | ||
} | ||
|
||
1; | ||
__END__ | ||
Foswiki - The Free and Open Source Wiki, http://foswiki.org/ | ||
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors | ||
are listed in the AUTHORS file in the root of this distribution. | ||
NOTE: Please extend that file, not this notice. | ||
Additional copyrights apply to some or all of the code in this | ||
file as follows: | ||
Copyright (C) 1999-2007 Peter Thoeny, peter@thoeny.org | ||
and TWiki Contributors. All Rights Reserved. TWiki Contributors | ||
are listed in the AUTHORS file in the root of this distribution. | ||
Copyright (C) 2005 Martin at Cleaver.org | ||
Copyright (C) 2005-2007 TWiki Contributors | ||
and also based/inspired on Catalyst framework, whose Author is | ||
Sebastian Riedel. Refer to | ||
http://search.cpan.org/~mramberg/Catalyst-Runtime-5.7010/lib/Catalyst.pm | ||
for more credit and liscence details. | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation; either version 2 | ||
of the License, or (at your option) any later version. For | ||
more details read LICENSE in the root of this distribution. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
As per the GPL, removal of this notice is prohibited. |