Version 0.3
[blog.pm-common-perl-mods.git] / MojoX-Dispatcher-FilterChain / t / 03chain.t
blob022046ecde0424789a85aba6354cd7f7e3e282ba
1 #!perl
3 use strict;
4 use warnings;
6 use Test::More tests => 4;
8 use_ok('MojoX::Dispatcher::FilterChain');
9 use_ok('MojoX::Dispatcher::FilterChain::Context');
11 my $c = MojoX::Dispatcher::FilterChain::Context->new();
13 my $chain = MojoX::Dispatcher::FilterChain->new();
15 $chain->add(FilterFirst->new());
16 $chain->add(FilterIntercept->new());
17 $chain->add(FilterLast->new());
19 $chain->process($c);
21 is($c->stash->{foo}, 'bar');
22 ok(not defined $c->stash->{last});
26 package FilterFirst;
27 use base 'MojoX::FilterChain::Base';
28 use MojoX::FilterChain::Constants;
30 sub run {
31     my ($self, $c) = @_;
32     $c->stash->{foo} = 'bar';
33     return NEXT;
37 package FilterIntercept;
38 use base 'MojoX::FilterChain::Base';
39 use MojoX::FilterChain::Constants;
41 sub run {
42     return LAST;
46 package FilterLast;
47 use base 'MojoX::FilterChain::Base';
48 use MojoX::FilterChain::Constants;
50 sub run {
51     my ($self, $c) = @_;
52     $c->stash->{last} = 1;
53     return LAST;