line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::Engine::Middleware::FillInForm; |
2
|
1
|
|
|
1
|
|
449
|
use HTTP::Engine::Middleware; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
3
|
1
|
|
|
1
|
|
4
|
use HTML::FillInForm; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
171
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
has 'autorun_on_post' => ( |
6
|
|
|
|
|
|
|
is => 'ro', |
7
|
|
|
|
|
|
|
isa => 'Bool', |
8
|
|
|
|
|
|
|
default => 0, |
9
|
|
|
|
|
|
|
); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
middleware_method 'HTTP::Engine::Response::fillin_form' => sub { |
12
|
2
|
|
|
2
|
|
11
|
my ($self, $fdat) = @_; |
13
|
2
|
|
|
|
|
7
|
$self->{__PACKAGE__ . '::flag'}++; |
14
|
2
|
|
|
|
|
3
|
$self->{__PACKAGE__ . '::fdat'} = $fdat; |
15
|
2
|
|
|
|
|
10
|
return $self; # I love method chain |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
after_handle { |
19
|
|
|
|
|
|
|
my ( $c, $self, $req, $res ) = @_; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
if ($res->{__PACKAGE__ . '::flag'} || ($self->autorun_on_post && $req->method eq 'POST')) { |
22
|
|
|
|
|
|
|
my $fdat = $res->{__PACKAGE__ . '::fdat'} || $req; |
23
|
|
|
|
|
|
|
my $body = HTML::FillInForm->fill(\( $res->body ), $fdat); |
24
|
|
|
|
|
|
|
$res->body($body); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$res; |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
__MIDDLEWARE__ |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
__END__ |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 NAME |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
HTTP::Engine::Middleware::FillInForm - fill-in-form stuff |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 SYNOPSIS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $mw = HTTP::Engine::Middleware->new; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$mw->install('HTTP::Engine::Middleware::FillInForm'); |
43
|
|
|
|
|
|
|
# or |
44
|
|
|
|
|
|
|
$mw->install( |
45
|
|
|
|
|
|
|
'HTTP::Engine::Middleware::FillInForm' => { |
46
|
|
|
|
|
|
|
autorun_on_post => 1 |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
HTTP::Engine->new( |
51
|
|
|
|
|
|
|
interface => { |
52
|
|
|
|
|
|
|
module => 'YourFavoriteInterfaceHere', |
53
|
|
|
|
|
|
|
request_handler => $mw->handler( |
54
|
|
|
|
|
|
|
sub { |
55
|
|
|
|
|
|
|
HTTP::Engine::Response->new( |
56
|
|
|
|
|
|
|
body => '<form><input type="text" name="foo" /></form>' |
57
|
|
|
|
|
|
|
)->fillin_form() # when no args, fill-in-form from request params. |
58
|
|
|
|
|
|
|
# or |
59
|
|
|
|
|
|
|
HTTP::Engine::Response->new( |
60
|
|
|
|
|
|
|
body => '<form><input type="text" name="foo" /></form>' |
61
|
|
|
|
|
|
|
)->fillin_form({'foo' => 'bar'}) |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
), |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
)->run(); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 AUTHORS |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Tokuhiro Matsuno |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 SEE ALSO |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
L<HTML::FillInForm> |
74
|
|
|
|
|
|
|
|