Nile

 view release on metacpan or  search on metacpan

lib/Nile.pm  view on Meta::CPAN

    
    $app->load_once("Module::SomeModule");

Load modules if not already loaded.

=cut

sub load_once {
    my ($self, $module, @arg) = @_;
    if (!exists $self->loaded_modules->{$module}) {
        load $module;
        $self->loaded_modules->{$module} = 1;
    }
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
=head2 load_class()
    
    $app->load_class("Module::SomeModule");

Load modules if not already loaded.

=cut

sub load_class {
    my ($self, $module, @arg) = @_;

    if (!$self->is_loaded($module)) {
        load $module;
    }
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
=head2 cli_mode()
    
    if ($app->cli_mode) {
        say "Running from the command line";
    }
    else {
        say "Running from web server";
    }

Returns true if running from the command line interface, false if called from web server.

=cut

sub cli_mode {
    my ($self) = @_;
    
    if  (exists $ENV{REQUEST_METHOD} || defined $ENV{GATEWAY_INTERFACE} ||  exists $ENV{HTTP_HOST}){
        return 0;
    }
    
    # PSGI
    if  (exists $self->env->{REQUEST_METHOD} || defined $self->env->{GATEWAY_INTERFACE} ||  exists $self->env->{HTTP_HOST}){
        return 0;
    }
    
    # CLI
    return 1;

    #if (-t STDIN) { }
    #use IO::Interactive qw(is_interactive interactive busy);if ( is_interactive() ) {print "Running interactively\n";}
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
=head2 error()
    
    $app->error("error message");

Fatal errors with custom error message. This is the same as C<croak> in L<CGI::Carp|CGI::Carp/croak>.

=cut

sub error {
    my $self = shift;
    goto &CGI::Carp::croak;
}

=head2 errors()
    
    $app->errors("error message");

Fatal errors with custom error message and full starcktrace. This is the same as C<confess> in L<CGI::Carp|CGI::Carp/confess>.

=cut

sub errors {
    my $self = shift;
    goto &CGI::Carp::confess;
}

=head2 warn()
    
    $app->warn("warning  message");

Display warning message. This is the same as C<carp> in L<CGI::Carp|CGI::Carp/carp>.

To view warnings in the browser, switch to the view source mode since warnings appear as
a comment at the top of the page.

=cut

sub warn {
    my $self = shift;
    # warnings appear commented at the top of the page, use view source
    warningsToBrowser(1) unless ($self->cli_mode);
    goto &CGI::Carp::carp;
}

=head2 warns()
    
    $app->warns("warning  message");

Display warning message and full starcktrace. This is the same as C<cluck> in L<CGI::Carp|CGI::Carp/cluck>.

To view warnings in the browser, switch to the view source mode since warnings appear as
a comment at the top of the page.

=cut

sub warns {
    my $self = shift;
    # warnings appear commented at the top of the page, use view source



( run in 2.440 seconds using v1.01-cache-2.11-cpan-600a1bdf6e4 )