Amon2
view release on metacpan or search on metacpan
You can override this method if you want to determine the mode by other method.
- `MyApp->new()`
Create new context object.
- `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.
- `MyApp->base_dir()`
This method returns the application base directory.
- `MyApp->load_plugin($module_name[, \%config])`
This method loads the plugin for the application.
_$module\_name_ package name of the plugin. You can write it as two form like [DBIx::Class](https://metacpan.org/pod/DBIx%3A%3AClass):
**((EXPERIMENTAL))**
This method returns a boolean value. It returns true when $ENV{AMON2\_DEBUG} is true value, false otherwise.
You can override this method if you need.
# PROJECT LOCAL MODE
**THIS MODE IS HIGHLY EXPERIMENTAL**
Normally, Amon2's context is stored in a global variable.
This module makes the context to project local.
It means, normally context class using Amon2 use `$Amon2::CONTEXT` in each project, but context class using ["PROJECT LOCAL MODE"](#project-local-mode) use `$MyApp::CONTEXT`.
**It means you can't use code depend `<Amon2-`context>> and `<Amon2-`context>> under this mode.**>
## NOTES ABOUT create\_request
Older [Amon2::Web::Request](https://metacpan.org/pod/Amon2%3A%3AWeb%3A%3ARequest) has only 1 argument like following, it uses `Amon2->context` to get encoding:
lib/Amon2.pm view on Meta::CPAN
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>:
lib/Amon2.pm view on Meta::CPAN
This method returns a boolean value. It returns true when $ENV{AMON2_DEBUG} is true value, false otherwise.
You can override this method if you need.
=back
=head1 PROJECT LOCAL MODE
B<THIS MODE IS HIGHLY EXPERIMENTAL>
Normally, Amon2's context is stored in a global variable.
This module makes the context to project local.
It means, normally context class using Amon2 use C<$Amon2::CONTEXT> in each project, but context class using L</PROJECT LOCAL MODE> use C<$MyApp::CONTEXT>.
B<<< It means you can't use code depend C<<Amon2->context>> and C<<Amon2->context>> under this mode. >>>>
=head2 NOTES ABOUT create_request
Older L<Amon2::Web::Request> has only 1 argument like following, it uses C<< Amon2->context >> to get encoding:
share/flavor/Large/t/07_mech_links.t view on Meta::CPAN
my $mech = shift;
my @links;
my $parser = HTML::TokeParser->new( \( $mech->content ) );
while ( my $token = $parser->get_tag( keys %link_tags ) ) {
push @links, $token->[1]->{ $link_tags{ $token->[0] } };
}
return grep { m{^/} } @links;
}
for my $psgi (glob('script/*-server')) {
subtest $psgi => sub {
my $app = Plack::Util::load_psgi($psgi);
my $mech = Test::WWW::Mechanize::PSGI->new( app => $app );
$mech->credentials( 'admin', 'admin' );
$mech->get_ok('/');
my @links = _extract_links($mech);
for (@links) {
$mech->get('/');
share/flavor/Minimum/Build.PL view on Meta::CPAN
$prereq->{build} ? %{$prereq->{build}->{requires}} : (),
$prereq->{test} ? %{$prereq->{test}->{requires}} : (),
},
configure_requires => {
%{$prereq->{configure}->{requires}},
},
requires => {
perl => '5.008001',
%{$prereq->{runtime}->{requires}},
},
script_files => [glob('script/*'), glob('bin/*')],
no_index => { 'directory' => [ 'inc' ] },
name => '<% $module %>',
module_name => '<% $module %>',
author => 'Some Person <person@example.com>',
dist_abstract => 'A web site based on Amon2',
test_files => (-d '.git' || $ENV{RELEASE_TESTING}) ? 't/ xt/' : 't/',
recursive_test_files => 1,
t/100_core/017_local_context.t view on Meta::CPAN
package Foo;
use parent qw(Amon2);
__PACKAGE__->make_local_context();
}
subtest 'simple set context' => sub {
is(Foo->context(), undef);
my $c = Foo->new();
Foo->set_context($c);
is(Foo->context(), $c, 'context was set');
is(Amon2->context(), undef, 'global context does not set');
Foo->set_context(undef); # teardown
};
subtest 'context_guard' => sub {
is(Foo->context(), undef);
my $c = Foo->new();
{
my $guard = $c->context_guard();
is(Foo->context(), $c, 'context was set');
is(Amon2->context(), undef, 'global context does not set');
}
is(Foo->context(), undef, 'context was gone');
is(Amon2->context(), undef, 'global context does not set');
};
subtest 'bootstrap' => sub {
is(Foo->context(), undef);
my $c = Foo->bootstrap();
is(Foo->context(), $c, 'context was set');
is(Amon2->context(), undef, 'global context does not set');
};
done_testing;
( run in 1.412 second using v1.01-cache-2.11-cpan-99c4e6809bf )