#!/usr/bin/perl
package RVL::FrontController;
##LICENSE##
use strict;
use warnings;
use RVL::Request;
use RVL::Registry;
use RVL::Output;
use RVL::CpHandle;
use Smart::Comments '###', '####';
use Class::Std::Utils;
{
sub new {
my ($class, $opt) = @_;
#my ($newClass) = bless anon_scalar(), $class;
my ($newClass) = bless( {}, $class);
return $newClass;
}
=help
Main invocation, init tasks plus main process.
use constant
=cut
sub run {
my ($this) = shift;
RVL::FrontController::init();
RVL::logMessage('', __CONSTANT__::RVL_LOG_DEBUG);
$this = (!$this) ? RVL::FrontController->new() : $this;
my ($req) = RVL::Request::singleton();
my ($input) = RVL::Registry::singleton();
$input->setRequest(\$req);
my ($output) = RVL::Output::singleton();
require 'RVL/Task/Process.pm';
my ($oCustomTask) = $this->customFilterChain(\$input);
if ($oCustomTask eq 0) {
my ($oTask) =
RVL::Task::Init->new(
RVL::Task::SetupORM->new(
RVL::Task::ResolveManager->new(
RVL::Task::LicenseCycle->new(
RVL::Task::LoadCpHandle->new(
RVL::Task::LoadLibsModule->new(
RVL::Task::CreateSession->new(
RVL::Task::SetupLangSupport->new(
RVL::Task::SetupLocale->new(
RVL::Task::AuthenticateRequest->new(
RVL::Task::SetupPerms->new(
## post-process (order: bottom up)
RVL::Task::BuildHeaders->new(
RVL::Task::BuildView->new(
RVL::Task::SetupGui->new(
RVL::Task::BuildOutputData->new(
RVL::MainProcess->new()
)))))))))))))));
$oTask->process(\$input, \$output);
} else {
$oCustomTask->process(\$input, \$output);
}
print $output->{data};
}
sub customFilterChain {
my ($this, $input) = @_;
my ($req) = ${$input}->getRequest();
my ($reqType) = ${$req}->getRequestType();
if ($reqType eq 'Browser' || $reqType eq 'Cli') {
return 0;
} elsif ($reqType eq 'Ajax') {
RVL::logMessage('Call Ajax Task', __CONSTANT__::RVL_LOG_DEBUG);
require 'RVL/Task/AuthenticateAjaxRequest.pm';
require 'RVL/Task/CustomBuildOutputData.pm';
require 'RVL/Task/BuildAjaxHeaders.pm';
require 'RVL/Task/BuildAjaxView.pm';
require 'RVL/Task/ExecuteAjaxAction.pm';
return RVL::Task::Init->new(
RVL::Task::SetupORM->new(
RVL::Task::ResolveManager->new(
RVL::Task::LoadCpHandle->new(
RVL::Task::LoadLibsModule->new(
RVL::Task::CreateSession->new(
RVL::Task::SetupLangSupport->new(
RVL::Task::AuthenticateAjaxRequest->new(
RVL::Task::BuildAjaxHeaders->new(
RVL::Task::BuildAjaxView->new(
RVL::Task::CustomBuildOutputData->new(
RVL::Task::ExecuteAjaxAction->new(
))))))))))));
} else {
return 0;
}
}
sub init {
require 'data/languages.pl';
require 'RVL/TaskRunner.pm';
require 'RVL/Task/Init.pm';
my ($c) = RVL::Config::singleton();
my ($conf) = $c->getAll();
my ($oRunner) = RVL::TaskRunner->new();
$oRunner->addData($conf);
$oRunner->addTask(RVL::Task::SetupConstantsStart->new());
$oRunner->addTask(RVL::Task::SetupConstantsFinish->new());
$oRunner->addTask(RVL::Task::LoadPlatform->new());
#$oRunner->addTask(RVL::Task::LoadCpHandle->new());
#$oRunner->addTask(RVL::Task::LoadLibsModule->new());
$oRunner->main();
}
}
=head
=cut
package RVL::InstanceProcess;
use strict;
use warnings;
use Class::Std::Utils;
{
# class attribute
my (@props);
sub new {
my ($class, $opt) = @_;
my ($newClass) = bless anon_scalar(), $class;
return $newClass;
}
sub singleton {
my ($class) = __PACKAGE__;
if (!defined $RVL::INSTANCE{$class}) {
$RVL::INSTANCE{$class} = $class->new();
}
return $RVL::INSTANCE{$class}
}
sub set {
my ($this, $task) = @_;
unshift(@props, $task);
}
sub get {
my ($this) = @_;
return (@props == 0) ? 0 : shift @props;
}
}
=head
=cut
package RVL::ProcessRequest;
use strict;
use warnings;
use Class::Std::Utils;
{
sub new {
my ($class, $opt) = @_;
my ($this) = bless anon_scalar(), $class;
my ($ident) = ident($this);
return $this;
}
sub process {
my ($this, $input, $output) = @_;
}
}
=head
=cut
package RVL::DecorateProcess;
use strict;
use warnings;
use base qw(RVL::ProcessRequest);
use Class::Std::Utils;
{
my (@processRequest);
sub new {
my ($class, $opt) = @_;
my ($this) = $class->SUPER::new($opt);
my ($ident) = ident($this);
if (defined $opt) {
my ($oInsPro) = RVL::InstanceProcess::singleton();
$oInsPro->set($opt);
}
return $this;
}
sub process {
my ($this, $input, $output) = @_;
my ($ident) = ident($this);
my ($oInsPro) = RVL::InstanceProcess::singleton();
my ($class) = $oInsPro->get();
return 1 if (!$class);
$class->process($input, $output);
}
}
=head
=cut
package RVL::MainProcess;
use base qw(RVL::DecorateProcess);
use Class::Std::Utils;
{
sub new {
my ($class, $opt) = @_;
my ($newClass) = bless anon_scalar(), $class;
return $newClass;
}
sub process {
my ($this, $input, $output) = @_;
RVL::logMessage('', __CONSTANT__::RVL_LOG_DEBUG);
my ($req) = ${$input}->getRequest();
my ($mgr) = ${$input}->get('manager');
eval {
${$mgr}->validate(${$req}, $input);
${$input}->aggregate($output);
if (${$mgr}->isValid()) {
my ($ok) = ${$mgr}->process($input, $output);
}
RVL::Manager::display($output);
${$mgr}->display($output);
};
if ($@) {
RVL::fatalErrors($@);
}
$this->SUPER::process($input, $output);
}
}
1;
__END__;
Copyright 2K16 - 2K18 Indonesian Hacker Rulez