1# please insert nothing before this line: -*- mode: cperl; cperl-indent-level: 4; cperl-continued-statement-offset: 4; indent-tabs-mode: nil -*-
2package TestHooks::push_handlers;
3
4# test various ways to push handlers
5
6use strict;
7use warnings FATAL => 'all';
8
9use Apache2::RequestRec ();
10use Apache2::RequestIO ();
11use Apache2::RequestUtil ();
12
13use Apache2::Const -compile => qw(OK DECLINED DONE);
14
15sub handler {
16    my $r = shift;
17
18    $r->handler("modperl");
19
20    $r->push_handlers(PerlResponseHandler => \&coderef);
21    $r->push_handlers(PerlResponseHandler =>
22        \&TestHooks::push_handlers::full_coderef);
23
24    $r->push_handlers(PerlResponseHandler =>
25        [\&coderef1, __PACKAGE__.'::coderef2', \&coderef3]);
26
27    $r->push_handlers(PerlResponseHandler =>
28        sub { return say(shift, "anonymous") });
29
30    $r->push_handlers(PerlResponseHandler =>
31        [sub { return say(shift, "anonymous1") },
32         \&coderef4,
33         sub { return say(shift, "anonymous3") },
34        ]);
35
36    $r->push_handlers(PerlResponseHandler => \&end);
37
38    return Apache2::Const::DECLINED;
39}
40
41sub end { return Apache2::Const::DONE }
42sub say { shift->print(shift,"\n"); return Apache2::Const::DECLINED }
43
44sub conf {
45    # this one is configured from httpd.conf
46    my $r= shift;
47    $r->content_type('text/plain');
48    return say($r, "conf");
49}
50
51sub conf1        { return say(shift, "conf1")        }
52sub conf2        { return say(shift, "conf2")        }
53sub coderef      { return say(shift, "coderef")      }
54sub coderef1     { return say(shift, "coderef1")     }
55sub coderef2     { return say(shift, "coderef2")     }
56sub coderef3     { return say(shift, "coderef3")     }
57sub coderef4     { return say(shift, "coderef4")     }
58sub full_coderef { return say(shift, "full_coderef") }
59
601;
61__DATA__
62<NoAutoConfig>
63  <Location /TestHooks__push_handlers>
64      SetHandler modperl
65      PerlHeaderParserHandler TestHooks::push_handlers
66      PerlResponseHandler     TestHooks::push_handlers::conf
67      PerlResponseHandler     TestHooks::push_handlers::conf1 TestHooks::push_handlers::conf2
68  </Location>
69</NoAutoConfig>
70
71