| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# $Id: /mirror/gungho/lib/Gungho/Inline.pm 39015 2008-01-16T15:58:40.917983Z lestrrat $ |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp> |
|
4
|
|
|
|
|
|
|
# Copyright (c) 2007 Kazuho Oku |
|
5
|
|
|
|
|
|
|
# All rights reserved. |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Gungho::Inline; |
|
8
|
1
|
|
|
1
|
|
1158
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
21
|
|
|
9
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
18
|
|
|
10
|
1
|
|
|
1
|
|
3
|
use base qw(Gungho); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
11
|
|
|
11
|
1
|
|
|
1
|
|
27
|
use Gungho::Request; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
BEGIN |
|
14
|
|
|
|
|
|
|
{ |
|
15
|
|
|
|
|
|
|
if (! __PACKAGE__->can('OLD_PARAMETER_LIST')) { |
|
16
|
|
|
|
|
|
|
my $old_parameter_list = $ENV{GUNGHO_INLINE_OLD_PARAMETER_LIST} || 0; |
|
17
|
|
|
|
|
|
|
eval "sub OLD_PARAMETER_LIST() { $old_parameter_list } "; |
|
18
|
|
|
|
|
|
|
die if $@; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub bootstrap |
|
23
|
|
|
|
|
|
|
{ |
|
24
|
|
|
|
|
|
|
my $class = shift; |
|
25
|
|
|
|
|
|
|
if (&OLD_PARAMETER_LIST) { |
|
26
|
|
|
|
|
|
|
$class->_setup_old_parameters(@_); |
|
27
|
|
|
|
|
|
|
} else { |
|
28
|
|
|
|
|
|
|
my $config = $class->load_config(shift); |
|
29
|
|
|
|
|
|
|
my $opts = shift || {}; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
foreach my $k qw(provider handler) { |
|
32
|
|
|
|
|
|
|
if ($opts->{$k} && ref $opts->{$k} eq 'CODE') { |
|
33
|
|
|
|
|
|
|
$config->{$k} = { |
|
34
|
|
|
|
|
|
|
module => qw(Inline), |
|
35
|
|
|
|
|
|
|
config => { |
|
36
|
|
|
|
|
|
|
callback => $opts->{$k}, |
|
37
|
|
|
|
|
|
|
}, |
|
38
|
|
|
|
|
|
|
}; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
@_ = ($config); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$class->next::method(@_); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _setup_old_parameters |
|
48
|
|
|
|
|
|
|
{ |
|
49
|
|
|
|
|
|
|
my $class = shift; |
|
50
|
|
|
|
|
|
|
my $config = shift; |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
foreach my $k qw(provider handler) { |
|
53
|
|
|
|
|
|
|
if ($config->{$k} && ref $config->{$k} eq 'CODE') { |
|
54
|
|
|
|
|
|
|
$config->{$k} = { |
|
55
|
|
|
|
|
|
|
module => qw(Inline), |
|
56
|
|
|
|
|
|
|
config => { |
|
57
|
|
|
|
|
|
|
callback => $config->{$k}, |
|
58
|
|
|
|
|
|
|
}, |
|
59
|
|
|
|
|
|
|
}; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__END__ |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 NAME |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Gungho::Inline - Inline Your Providers And Handlers (Deprecated) |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
use Gungho::Inline; |
|
75
|
|
|
|
|
|
|
use IO::Select; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Gungho::Inline->run( |
|
78
|
|
|
|
|
|
|
$config, |
|
79
|
|
|
|
|
|
|
{ |
|
80
|
|
|
|
|
|
|
provider => sub { |
|
81
|
|
|
|
|
|
|
my ($provider, $c) = @_; |
|
82
|
|
|
|
|
|
|
while (IO::Select->new(STDIN)->can_read(0)) { |
|
83
|
|
|
|
|
|
|
return if STDIN->eof; |
|
84
|
|
|
|
|
|
|
my $url = STDIN->getline; |
|
85
|
|
|
|
|
|
|
chomp $url; |
|
86
|
|
|
|
|
|
|
$provider->add_request($c->prepare_request(Gungho::Request->new(GET => $url))); |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
}, |
|
89
|
|
|
|
|
|
|
handler => sub { |
|
90
|
|
|
|
|
|
|
my ($handler, $c, $req, $res) = @_; |
|
91
|
|
|
|
|
|
|
print $res->code, ' ', $req->uri, "\n"; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
); |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Sometimes you don't need the full power of an independent Gungho Provider |
|
99
|
|
|
|
|
|
|
and or Handler. In those cases, Gungho::Inline saves you from creating |
|
100
|
|
|
|
|
|
|
separate packages |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This module is a thin wrapper around Gungho that allows you to specify |
|
103
|
|
|
|
|
|
|
subroutine references instead of a full config. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
As of Gungho 0.09003, inlined handlers and providers are supported natively. |
|
106
|
|
|
|
|
|
|
The only reason to use this module is for you to use the old parameter list. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 BACKWARDS COMPATIBILITY WITH VERSIONS < 0.08 |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
From version 0.08 of Gungho::Inline, the parameter list passed to the |
|
111
|
|
|
|
|
|
|
handler and providers, as well as the run method has been changed. You |
|
112
|
|
|
|
|
|
|
can enable the old behavior if you do |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
env GUNGHO_INLINE_OLD_PARAMETER_LIST=1 gungho |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
or, somewhere in your code, create a subroutine constant: |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
BEGIN |
|
119
|
|
|
|
|
|
|
{ |
|
120
|
|
|
|
|
|
|
sub Gungho::Inline::OLD_PARAMETER_LIST { 1 }; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
use Gungho::Inline; |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 CONSTANTS |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 OLD_PARAMETER_LIST |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
If true, uses the old-style parameter list |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 METHODS |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 setup({ provider => $callback, handler => $callback, %args }) |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Sets up Gungho::Inline with this set of providers |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 AUTHOR |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Original code by Kazuho Oku. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |