Nile
view release on metacpan or search on metacpan
lib/Nile.pm view on Meta::CPAN
use Nile::DBI;
use Nile::Setting;
use Nile::Timer;
use Nile::HTTP::Request;
use Nile::HTTP::Response;
#use base 'Import::Base';
use Import::Into;
use Module::Load;
use Module::Runtime qw(use_module);
our @EXPORT_MODULES = (
#strict => [],
#warnings => [],
Moose => [],
utf8 => [],
#'File::Spec' => [],
#'File::Basename' => [],
Cwd => [],
'Nile::Say' => [],
'MooseX::MethodAttributes' => [],
);
use base 'Exporter';
our @EXPORT = qw();
our @EXPORT_OK = qw();
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sub import {
my ($class, @args) = @_;
my ($package, $script) = caller;
# import list of modules to the calling package
my @modules = @EXPORT_MODULES;
while (@modules) {
my $module = shift @modules;
my $imports = ref $modules[0] eq 'ARRAY' ? shift @modules : [];
use_module($module)->import::into($package, @{$imports});
}
#------------------------------------------------------
$class->detect_app_path($script);
#------------------------------------------------------
my $caller = $class.'::';
{
no strict 'refs';
@{$caller.'EXPORT'} = @EXPORT;
foreach my $sub (@EXPORT) {
next if (*{"$caller$sub"}{CODE});
*{"$caller$sub"} = \*{$sub};
}
}
$class->export_to_level(1, $class, @args);
#------------------------------------------------------
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sub detect_app_path {
my ($self, $script) = @_;
$script ||= (caller)[1];
my ($vol, $dirs, $name) = File::Spec->splitpath(File::Spec->rel2abs($script));
if (-d (my $fulldir = File::Spec->catdir($dirs, $name))) {
$dirs = $fulldir;
$name = "";
}
my $path = $vol? File::Spec->catpath($vol, $dirs) : File::Spec->catdir($dirs);
$ENV{NILE_APP_DIR} = $path;
return ($path);
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sub BUILD { # our sub new {...}
my ($self, $arg) = @_;
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
=head2 init()
use Nile;
my $app = Nile->new();
$app->init({
# base application path, auto detected if not set
path => dirname(File::Spec->rel2abs(__FILE__)),
# load config files, default extension is xml
config => [ qw(config) ],
# force run mode if not auto detected by default. modes: "psgi", "fcgi" (direct), "cgi" (direct)
#mode => "fcgi", # psgi, cgi, fcgi
});
Initialize the application with the shared and safe sessions settings.
=cut
has 'init' => (
is => 'rw',
isa => 'HashRef',
default => sub { +{} }
);
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
=head2 var()
See L<Nile::Var>.
=cut
has 'var' => (
is => 'rw',
lazy => 1,
default => sub {
shift->object ("Nile::Var", @_);
}
);
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
( run in 2.100 seconds using v1.01-cache-2.11-cpan-302cb4679cc )