App-CELL

 view release on metacpan or  search on metacpan

lib/App/CELL.pm  view on Meta::CPAN


App::CELL - Configuration, Error-handling, Localization, and Logging



=head1 VERSION

Version 0.231

=cut

our $VERSION = '0.231';



=head1 SYNOPSIS

    # imagine you have a script/app called 'foo' . . . 

    use Log::Any::Adapter ( 'File', "/var/tmp/foo.log" );
    use App::CELL qw( $CELL $log $meta $site );

    # load config params and messages from sitedir
    my $status = $CELL->load( sitedir => '/etc/foo' );
    return $status unless $status->ok;

    # set appname to FOO_APPNAME (a config param just loaded from sitedir)
    $CELL->appname( $CELL->FOO_APPNAME || "foo" );

    # write to the log
    $log->notice("Configuration loaded from /etc/foo");

    # get value of site configuration parameter FOO_PARAM
    my $val = $site->FOO_PARAM;

    # get a list of all supported languages
    my @supp_lang = $CELL->supported_languages;

    # determine if a language is supported
    print "sk supported" if $CELL->language_supported('sk');

    # get message object and text in default language
    $status = $CELL->msg('FOO_INFO_MSG');
    my $fmsg = $status->payload if $status->ok;
    my $text = $fmsg->text;

    # get message object and text in default language
    # (message that takes arguments)
    $fmsg = $CELL->msg('BAR_ARGS_MSG', "arg1", "arg2");
    print $fmsg->text, "\n";

    # get text of message in a different language
    my $sk_text = $fmsg->lang('sk')->text;




=head1 DESCRIPTION

This is the top-level module of App::CELL, the Configuration,
Error-handling, Localization, and Logging framework for applications (or
scripts) written in Perl.

For details, read the POD in the L<App::CELL> distro. For an introduction,
read L<App::CELL::Guide>.



=head1 EXPORTS

This module provides the following exports:

=over 

=item C<$CELL> - App::CELL singleton object

=item C<$log> - App::CELL::Log singleton object

=item C<$meta> - App::CELL::Config singleton object

=item C<$core> - App::CELL::Config singleton object

=item C<$site> - App::CELL::Config singleton object

=back

=cut 

use Exporter qw( import );
our @EXPORT_OK = qw( $CELL $log $meta $core $site );

our $CELL = bless { 
        appname  => __PACKAGE__,
        enviro   => '',
    }, __PACKAGE__;

# ($log is imported from App::CELL::Log)
# ($meta, $core, and $site are imported from App::CELL::Config)



=head1 METHODS


=head2 appname

If no argument is given, returns the C<appname> -- i.e. the name of the
application or script that is using L<App::CELL> for its configuration,
error handling, etc.

If an argument is given, assumes that it denotes the desired C<appname> and sets
it. Also initializes the logger.

=cut

sub appname { 
    my @ARGS = @_;
    return $CELL->{appname} if not @ARGS; 
    $CELL->{appname} = $ARGS[0];
    $log->ident( $CELL->{'appname'} );
}



( run in 0.497 second using v1.01-cache-2.11-cpan-e1769b4cff6 )