Amon2
view release on metacpan or search on metacpan
lib/Amon2.pm view on Meta::CPAN
sub debug_mode { $ENV{AMON2_DEBUG} ? 1 : 0 }
sub add_config {
my ($class, $key, $hash) = @_; $hash or Carp::croak("missing args: \$hash");
Carp::cluck("Amon2->add_config() method was deprecated.");
# This method will be deprecated.
$class->config->{$key} = +{
%{$class->config->{$key} || +{}},
%{$hash},
};
}
# -------------------------------------------------------------------------
# Pluggable things.
sub load_plugins {
my ($class, @args) = @_;
while (@args) {
my $module = shift @args;
my $conf = @args>0 && ref($args[0]) eq 'HASH' ? shift @args : undef;
$class->load_plugin($module, $conf);
}
}
sub load_plugin {
my ($class, $module, $conf) = @_;
$module = Plack::Util::load_class($module, 'Amon2::Plugin');
$module->init($class, $conf);
}
# -------------------------------------------------------------------------
# Local context maker.
sub make_local_context {
my $class = shift;
## Mo critic.
eval sprintf(q{
package %s;
sub context { $%s::CONTEXT }
sub set_context { $%s::CONTEXT = $_[1] }
sub context_guard {
Amon2::ContextGuard->new($_[0], \$%s::CONTEXT);
}
}, $class, $class, $class, $class);
die $@ if $@;
}
1;
__END__
=encoding utf-8
=head1 NAME
Amon2 - lightweight web application framework
=head1 SYNOPSIS
package MyApp;
use parent qw/Amon2/;
use Amon2::Config::Simple;
sub load_config { Amon2::Config::Simple->load(shift) }
=head1 DESCRIPTION
Amon2 is simple, readable, extensible, B<STABLE>, B<FAST> web application framework based on L<Plack>.
=head1 METHODS
=head2 CLASS METHODS for C<< Amon2 >> class
=over 4
=item my $c = MyApp->context();
Get the context object.
=item MyApp->set_context($c)
Set your context object(INTERNAL USE ONLY).
=back
=head1 CLASS METHODS for inherited class
=over 4
=item C<< MyApp->config() >>
This method returns configuration information. It is generated by C<< MyApp->load_config() >>.
=item C<< MyApp->mode_name() >>
This is a mode name for Amon2. The default implementation of this method is:
sub mode_name { $ENV{PLACK_ENV} }
You can override this method if you want to determine the mode by other method.
=item C<< MyApp->new() >>
Create new context object.
=item C<< MyApp->bootstrap() >>
my $c = MyApp->bootstrap();
Create new context object and set it to global context. When you are writing CLI script, setup the global context object by this method.
=item C<< MyApp->base_dir() >>
This method returns the application base directory.
=item C<< MyApp->load_plugin($module_name[, \%config]) >>
This method loads the plugin for the application.
I<$module_name> package name of the plugin. You can write it as two form like L<DBIx::Class>:
__PACKAGE__->load_plugin("Web::CSRFDefender"); # => loads Amon2::Plugin::Web::CSRFDefender
If you want to load a plugin in your own name space, use the '+' character before a package name, like following:
__PACKAGE__->load_plugin("+MyApp::Plugin::Foo"); # => loads MyApp::Plugin::Foo
=item C<< MyApp->load_plugins($module_name[, \%config ], ...) >>
( run in 2.202 seconds using v1.01-cache-2.11-cpan-e1769b4cff6 )