1# $Id: /mirror/gungho/lib/Gungho/Handler/Inline.pm 8911 2007-11-12T01:12:09.994728Z lestrrat  $
2#
3# Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp>
4# Copyright (c) 2007 Kazuho Oku
5# All rights reserved.
6
7package Gungho::Handler::Inline;
8use strict;
9use warnings;
10use base qw(Gungho::Handler);
11use Gungho::Request;
12
13__PACKAGE__->mk_accessors($_) for qw(callback);
14
15
16sub setup {
17    my $self = shift;
18    my $callback = $self->config->{callback};
19    die "``callback'' not supplied\n" unless ref $callback eq 'CODE';
20    $self->callback($callback);
21    $self->next::method(@_);
22}
23
24sub handle_response {
25    my ($self, $c, $req, $res) = @_;
26
27    my @args = (
28        Class::Inspector->loaded('Gungho::Inline') &&
29            &Gungho::Inline::OLD_PARAMETER_LIST ?
30        ($req, $res, $c, $self) :
31        ($self, $c, $req, $res)
32    );
33    $self->callback->(@args);
34}
35
361;
37
38__END__
39
40=head1 NAME
41
42Gungho::Handler::Inline - Inline Handler
43
44=head1 DESCRIPTION
45
46Sometimes you don't need the full power of an independent Gungho Handler
47and or Handler. In those cases, Gungho::Handler::Inline saves you from
48creating a separate package for a Handler.
49
50You can simply pass a code reference as the the provider config:
51
52  Gungho->run(
53    {
54       handler => sub { ... }
55    }
56  );
57
58And it will be called via Gungho::Handler::Inline.
59
60The code reference you specified will be called as if it were a method
61in the Gungho::Handler::Inline package.
62
63=head1 METHODS
64
65=head2 setup
66
67=head2 handle_response
68
69=cut