App-CELL
view release on metacpan or search on metacpan
lib/App/CELL/Load.pm view on Meta::CPAN
my $status = message_files( $sitedir_candidate );
my $messages_loaded = _report_load_status( $sitedir_candidate, 'sitedir', 'message', $status );
$status = meta_core_site_files( $sitedir_candidate );
my $params_loaded = _report_load_status( $sitedir_candidate, 'sitedir', 'config params', $status );
#
# sitedir candidate is accepted only if something is actually
# loaded
#
if ( $messages_loaded->ok or $params_loaded->ok ) {
$meta->set( 'CELL_META_SITEDIR_LOADED',
( $meta->CELL_META_SITEDIR_LOADED + 1 ) );
push @sitedir, $sitedir_candidate;
$meta->set( 'CELL_META_SITEDIR_LIST', \@sitedir );
}
}
# check that at least sharedir has really been loaded
SANITY: {
my $results = [];
# remember, message constructor returns a status object
my $status = App::CELL::Message->new( code => 'CELL_LOAD_SANITY_MESSAGE' );
if ( $status->ok ) {
my $msgobj = $status->payload;
push @$results, (
$meta->CELL_LOAD_SANITY_META,
$core->CELL_LOAD_SANITY_CORE,
$site->CELL_LOAD_SANITY_SITE,
$msgobj->text(),
);
my $cmp_arrays_result = cmp_arrays(
$results,
[ 'Baz', 'Bar', 'Foo', 'This is a sanity testing message' ],
);
last SANITY if $cmp_arrays_result;
}
return App::CELL::Status->new(
level => 'ERR',
code => 'CELL_LOAD_FAILED_SANITY',
);
}
$log->debug( "Leaving App::CELL::Load::init", cell => 1 )
if $meta->CELL_META_LOAD_VERBOSE;
return App::CELL::Status->ok;
}
sub _report_load_status {
my ( $dir_path, $dir_desc, $what, $status ) = @_;
my $return_status = App::CELL::Status->ok;
my $quantitems = ${ $status->payload }{quantitems} || 0;
my $quantfiles = ${ $status->payload }{quantfiles} || 0;
if ( $quantitems == 0 ) {
$return_status = App::CELL::Status->new(
level => 'WARN',
code => 'CELL_DIR_WALKED_NOTHING_FOUND',
args => [ $what, $dir_desc, $dir_path, $quantfiles ],
caller => [ CORE::caller() ],
cell => 1,
);
}
# trigger a log message: note that we can't use an OK status here
# because log messages for those are suppressed
App::CELL::Status->new (
level => 'INFO',
code => 'CELL_DIR_WALKED_ITEMS_LOADED',
args => [ $quantitems, $what, $quantfiles, $dir_desc, $dir_path ],
caller => [ CORE::caller() ],
cell => 1,
) if ( $dir_desc eq 'sitedir' ) or ( $dir_desc eq 'sharedir' and $meta->CELL_META_LOAD_VERBOSE );
return $return_status;
}
=head2 message_files
Loads message files from the given directory. Takes: full path to
configuration directory. Returns: result hash containing 'quantfiles'
(total number of files processed) and 'count' (total number of
messages loaded).
=cut
sub message_files {
my $confdir = shift;
my %reshash;
$reshash{quantfiles} = 0;
$reshash{quantitems} = 0;
my $file_list = find_files( 'message', $confdir );
if ( @$file_list ) {
$log->info( "Found message files: " . join( ',', @$file_list ),
cell => 1 ) if $meta->CELL_META_LOAD_VERBOSE;
} else {
$log->warn( "No message files found in $confdir", cell => 1 )
if $meta->CELL_META_LOAD_VERBOSE;
}
foreach my $file ( @$file_list ) {
$reshash{quantfiles} += 1;
die "INTERNAL ERROR (App::CELL::Message::mesg is not a reference)" if not ref( $App::CELL::Message::mesg );
$reshash{quantitems} += parse_message_file(
File => $file,
Dest => $App::CELL::Message::mesg,
);
}
return App::CELL::Status->new(
level => 'OK',
payload => \%reshash,
);
}
=head2 meta_core_site_files
Loads meta, core, and site config files from the given directory. Takes:
full path to configuration directory. Returns: result hash containing
'quantfiles' (total number of files processed) and 'count' (total number of
configuration parameters loaded).
=cut
sub meta_core_site_files {
my $confdir = shift;
my %reshash;
( run in 1.260 second using v1.01-cache-2.11-cpan-97f6503c9c8 )