App-CELL
view release on metacpan or search on metacpan
lib/App/CELL.pm view on Meta::CPAN
=head2 sitedir
Get the C<sitedir> attribute, i.e. the full path of the site configuration
directory (available only after sitedir has been successfully loaded)
=cut
sub sitedir {
return '' if not $App::CELL::Load::sitedir;
return $App::CELL::Load::sitedir;
}
=head2 supported_languages
Get list of supported languages. Equivalent to:
$site->CELL_SUPP_LANG || [ 'en ]
=cut
sub supported_languages {
return App::CELL::Message::supported_languages();
}
=head2 language_supported
Determine if a given language is supported.
=cut
sub language_supported {
return App::CELL::Message::language_supported( $_[1] );
}
=head2 C<load>
Attempt to load messages and configuration parameters from the sharedir
and, possibly, the sitedir as well.
Takes: a PARAMHASH that should include at least one of C<enviro> or
C<sitedir> (if both are given, C<enviro> takes precedence with C<sitedir>
as a fallback). The PARAMHASH can also include a C<verbose> parameter
which, when set to a true value, causes the load routine to log more
verbosely.
Returns: an C<App::CELL::Status> object, which could be any of the
following:
OK success
WARN previous call already succeeded, nothing to do
ERR failure
On success, it also sets the C<CELL_META_START_DATETIME> meta parameter.
=cut
sub load {
my $class = shift;
my ( %ARGS ) = validate( @_, {
enviro => { type => SCALAR, optional => 1 },
sitedir => { type => SCALAR, optional => 1 },
verbose => { type => SCALAR, default => 0 },
} );
my $status;
$log->info( "CELL version $VERSION called from " . (caller)[0] .
" with arguments " . stringify_args( \%ARGS ),
cell => 1, suppress_caller => 1 );
# we only get past this next call if at least the sharedir loads
# successfully (sitedir is optional)
$status = App::CELL::Load::init( %ARGS );
return $status unless $status->ok;
$log->info( "App::CELL has finished loading messages and site conf params",
cell => 1 ) if $meta->CELL_META_LOAD_VERBOSE;
$log->show_caller( $site->CELL_LOG_SHOW_CALLER );
$log->debug_mode ( $site->CELL_DEBUG_MODE );
$App::CELL::Message::supp_lang = $site->CELL_SUPP_LANG || [ 'en' ];
$App::CELL::Message::def_lang = $site->CELL_DEF_LANG || 'en';
$meta->set( 'CELL_META_START_DATETIME', utc_timestamp() );
$log->info( "**************** App::CELL $VERSION loaded and ready ****************",
cell => 1, suppress_caller => 1 );
return App::CELL::Status->ok;
}
=head2 Status constructors
The following "factory" makes a bunch of status constructor methods
(wrappers for App::CELL::Status->new )
=cut
BEGIN {
foreach (@App::CELL::Log::permitted_levels) {
no strict 'refs';
my $level_uc = $_;
my $level_lc = lc $_;
*{"status_$level_lc"} = sub {
my ( $self, $code, @ARGS ) = @_;
if ( @ARGS % 2 ) { # odd number of arguments
$log->warn( "status_$level_lc called with odd number (" .
scalar @ARGS .
") of arguments; discarding the arguments!" );
@ARGS = ();
}
my %ARGS = @ARGS;
return App::CELL::Status->new(
level => $level_uc,
code => $code,
caller => [ CORE::caller() ],
%ARGS,
);
}
( run in 0.768 second using v1.01-cache-2.11-cpan-39bf76dae61 )