App-MFILE-WWW
view release on metacpan or search on metacpan
lib/App/MFILE/WWW.pm view on Meta::CPAN
=head1 DEVELOPMENT NOTES
=head2 UTF-8
In conformance with the JSON standard, all data passing to and from the
server are assumed to be encoded in UTF-8. Users who need to use non-ASCII
characters should check their browser's settings.
=head2 Deployment
To minimize latency, L<App::MFILE::WWW> can be deployed on the same server
as the back-end (e.g. L<App::Dochazka::REST>), but this is not required.
=head1 PACKAGE VARIABLES
For convenience, the following variables are declared with package scope:
=cut
my $dist_dir = File::ShareDir::dist_dir( 'App-MFILE-WWW' );
=head1 FUNCTIONS
=head2 init
Initialization routine - run from C<bin/mfile-www>, the server startup script.
This routine loads configuration parameters from files in the distro and site
configuration directories, and sets up logging.
FIXME: This code could be moved into the startup script.
=cut
sub init {
my %ARGS = validate( @_, {
mode => { type => SCALAR, optional => 1 }, # 'STANDALONE' or 'DDIST', defaults to 'STANDALONE'
ddist_sharedir => { type => SCALAR, optional => 1 },
sitedir => { type => SCALAR, optional => 1 },
debug_mode => { type => SCALAR, optional => 1 },
} );
# * determine mode
my $mode = $ARGS{'mode'} || 'STANDALONE';
if ( $mode =~ m/^(standalone|ddist)$/i ) {
if ( $mode =~ m/^ddist$/i ) {
$mode = 'DDIST';
} else {
$mode = 'STANDALONE';
}
}
# * load site configuration
my $status = _load_config( %ARGS );
return $status if $status->not_ok;
# * mode-specific meta configuration
$meta->set( 'META_WWW_STANDALONE_MODE', ( $mode eq 'STANDALONE' ) );
# * set up logging
return $CELL->status_not_ok( "MFILE_APPNAME not set!" ) if not $site->MFILE_APPNAME;
my $debug_mode;
if ( exists $ARGS{'debug_mode'} ) {
$debug_mode = $ARGS{'debug_mode'};
} else {
$debug_mode = $site->MFILE_WWW_DEBUG_MODE || 0;
}
unlink $site->MFILE_WWW_LOG_FILE if $site->MFILE_WWW_LOG_FILE_RESET;
Log::Any::Adapter->set('File', $site->MFILE_WWW_LOG_FILE );
$log->init( ident => $site->MFILE_APPNAME, debug_mode => $debug_mode );
$log->info( "Initializing " . $site->MFILE_APPNAME );
return $CELL->status_ok;
}
sub _load_config {
my %ARGS = @_;
my $status;
my $sitedir_loaded = 0;
#Log::Any::Adapter->set( 'File', "$ENV{HOME}/.mfile-www-early-debug.log" );
#$log->init( ident => 'MFILE-WWW', debug_mode => 1 );
# always load the App::MFILE::WWW distro sharedir
my $target = File::Spec->catfile( $dist_dir, 'config' );
print "Loading App::MFILE::WWW configuration parameters from $target\n";
$status = $CELL->load( sitedir => $target );
return $status if $status->not_ok;
# load additional sitedir if provided by caller in argument list
if ( $ARGS{sitedir} ) {
$target = $ARGS{sitedir};
print "Loading App::MFILE::WWW configuration parameters from $target\n";
$status = $CELL->load( sitedir => $target );
return $status if $status->not_ok;
$sitedir_loaded = 1;
}
# if ddist_sharedir was given, attempt to load configuration from that, too
if ( $ARGS{ddist_sharedir} and ! $sitedir_loaded ) {
$target = File::Spec->catfile( $ARGS{ddist_sharedir}, 'config' );
print "Loading App::MFILE::WWW configuration parameters from $target\n";
$status = $CELL->load( sitedir => $target );
return $status if $status->not_ok;
}
return $CELL->status_ok;
}
1;
( run in 0.637 second using v1.01-cache-2.11-cpan-39bf76dae61 )