Nile::App - App base class for the Nile framework.
$obj = $app->object("Nile::MyClass", @args); $obj = $app->object("Nile::Plugin::MyClass", @args); $obj = $app->object("Nile::Module::MyClass", @args); #... $app = $obj->app; $request = $app->request; $response = $app->response;
Creates and returns an object. This automatically adds the method app to the object and sets it to the current context so your object or class can access the current instance.
$app->start;
Set the application startup variables.
my $mode = $app->mode;
Returns the current application mode PSGI, FCGI or CGI.
See Nile::Config.
See Nile::Router.
See Nile::Lang.
# uri mode: 0=full, 1=absolute, 2=relative $app->uri_mode(1);
Set the uri mode. The values allowed are: 0= full, 1=absolute, 2=relative
$url = $app->uri_for("/users", [$mode]);
Returns the uri for specific action or route. The mode parameter is optional. The mode values allowed are: 0= full, 1=absolute, 2=relative.
# 1=enabled, 0=disabled $app->debug(1);
Enable or disable debugging flag.
$app->bm->lap("start task"); .... $app->bm->lap("end task"); say $app->bm->stop->summary; # NAME TIME CUMULATIVE PERCENTAGE # start task 0.123 0.123 34.462% # end task 0.234 0.357 65.530% # _stop_ 0.000 0.357 0.008% say "Total time: " . $app->bm->total_time;
Benchmark specific parts of your code. This is a Benchmark::Stopwatch object.
See Nile::File.
See Nile::XML.
See Nile::Setting.
See Nile::MIME.
See Nile::Dispatcher.
Returns Log::Tiny object.
$app->log->info("application run start"); $app->log->DEBUG("application run start"); $app->log->ERROR("application run start"); $app->log->INFO("application run start"); $app->log->ANYTHING("application run start"); Log object L<Log::Tiny> supports unlimited log categories.
$app->start_logger();
Start the log object and open the log file for writing logs.
$app->stop_logger();
Stops the log object and close the log file.
# start the timer $app->timer->start; # do some operations... # get time elapsed since start called say $app->timer->lap; # do some other operations... # get time elapsed since last lap called say $app->timer->lap; # get another timer object, timer automatically starts my $timer = $app->timer->new; say $timer->lap; #... say $timer->lap; #... say $timer->total;
Returns Nile::Timer object. See Nile::Timer for more details.
# get time elapsed since app started say $app->run_time->lap; # do some other operations... # get time elapsed since last lap called say $app->run_time->lap;
Returns Nile::Timer object. Timer automatically starts with the application.
See Nile::Var.
$request_uri = $app->env->{REQUEST_URI};
Plack/PSGI env object.
See Nile::Request.
See Nile::Response.
See Nile::Plugin.
# add helper method to the framework $app->helper($method => $coderef); # add method "echo" $app->helper("echo" => sub{shift; say @_;}); # access the helper method normal from plugins and modules $app->echo("Helper echo example.");
# add attr to the framework $app->attr($name => $default); # add attribute "PI" $app->attr("PI" => 4 * atan2(1, 1)); # or $app->attr("PI" => sub{4 * atan2(1, 1)}); # get the attribute value say $app->PI; # set the the attribute value to new value $app->PI(3.14159265358979);
my $response = $app->ua->get('http://example.com/'); say $response->{content} if length $response->{content}; $response = $app->ua->get($url, \%options); $response = $app->ua->head($url); $response = $app->ua->post_form($url, $form_data); $response = $app->ua->post_form($url, $form_data, \%options);
Simple HTTP client. This is a HTTP::Tiny object.
my $uri = $app->uri('http://mewsoft.com/');
Returns URI object.
$app->charset('utf8'); $charset = $app->charset;
Set or return the charset for encoding and decoding. Default is utf8.
utf8
See Nile::Serializer.
See Nile::Deserializer.
# load module Nile::Module::Home::Contact and create a new object $contact = $me->module("Home::Contact"); # to get another new instance $contact1 = $me->module("Home::MyModule")->new(); # or $contact2 = $contact->new(); # if you are calling from inside the Home module, you can just use $contact = $me->module("Contact"); # of course you can load sub classes $send = $me->module("Home::Contact::Send"); # if you are calling from inside the Home module, you can just use $send = $me->module("Contact::Send"); # all the above is the same as use Nile::Module::Home::Contact; $contact = Nile::Module::Home::Contact->new(); $contact->main() if ($contact->can("main"));
Load modules classes.
See Nile::Hook.
See Nile::Filter.
See session plugin Nile::Plugin::Session.
$user_lang = $app->detect_user_language;
Detects and retuns the user langauge.
Returns Nile::View object.
Returns Nile::Database object.
@themes = $app->theme_list;
Returns themes names installed.
@langs = $app->lang_list;
Returns languages names installed.
$app->dump({...});
Print object to the STDOUT. Same as say Dumper (@_);.
say Dumper (@_);
if ($app->is_loaded("Nile::SomeModule")) { #... } if ($app->is_loaded("Nile/SomeModule.pm")) { #... }
Returns true if module is loaded, false otherwise.
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.
$str_utf8 = $app->utf8_safe($str);
Encode data in utf8 safely.
$encoded = $app->encode($data);
Encode data using the current "charset".
$data = $app->decode($encoded);
Decode data using the current "charset".
$app->instance_isa($object, $class);
Test for an object of a particular class in a strictly correct manner.
Returns the object itself or undef if the value provided is not an object of that type.
undef
$app->abort("error message"); $app->abort("error title", "error message");
Stop and quit the application and display message to the user. See Nile::Abort module.
This project is available on github at https://github.com/mewsoft/Nile.
Please visit the project's homepage at https://metacpan.org/release/Nile.
Source repository is at https://github.com/mewsoft/Nile.
See Nile for details about the complete framework.
Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org> Website: http://www.mewsoft.com
Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى mewsoft@cpan.org, support@mewsoft.com, https://github.com/mewsoft/Nile, http://www.mewsoft.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Nile, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Nile
CPAN shell
perl -MCPAN -e shell install Nile
For more information on module installation, please visit the detailed CPAN module installation guide.