line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTPx::Dispatcher; |
2
|
6
|
|
|
6
|
|
398270
|
use strict; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
319
|
|
3
|
6
|
|
|
6
|
|
29
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
155
|
|
4
|
6
|
|
|
6
|
|
210
|
use 5.00800; |
|
6
|
|
|
|
|
33
|
|
|
6
|
|
|
|
|
328
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
6
|
6
|
|
|
6
|
|
3140
|
use HTTPx::Dispatcher::Rule; |
|
6
|
|
|
|
|
71
|
|
|
6
|
|
|
|
|
51
|
|
7
|
6
|
|
|
6
|
|
218
|
use Scalar::Util qw/blessed/; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
258
|
|
8
|
6
|
|
|
6
|
|
27
|
use Carp; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
342
|
|
9
|
6
|
|
|
6
|
|
32
|
use base qw/Exporter/; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
655
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw/connect match uri_for/; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $rules; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub connect { |
16
|
43
|
|
|
43
|
0
|
100950
|
my $pkg = caller(0); |
17
|
43
|
|
|
|
|
101
|
my @args = @_; |
18
|
|
|
|
|
|
|
|
19
|
43
|
|
|
|
|
64
|
push @{ $rules->{$pkg} }, HTTPx::Dispatcher::Rule->new(@args); |
|
43
|
|
|
|
|
244
|
|
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub match { |
23
|
46
|
|
|
46
|
0
|
111689
|
my ( $class, $req ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
46
|
|
|
|
|
65
|
for my $rule ( @{ $rules->{$class} } ) { |
|
46
|
|
|
|
|
116
|
|
26
|
54
|
100
|
|
|
|
217
|
if ( my $result = $rule->match($req) ) { |
27
|
46
|
|
|
|
|
115
|
return $result; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
0
|
|
|
|
|
0
|
return; # no match. |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub uri_for { |
34
|
10
|
|
|
10
|
0
|
8538
|
my ( $class, @args ) = @_; |
35
|
|
|
|
|
|
|
|
36
|
10
|
|
|
|
|
15
|
for my $rule ( @{ $rules->{$class} } ) { |
|
10
|
|
|
|
|
24
|
|
37
|
12
|
100
|
|
|
|
40
|
if ( my $result = $rule->uri_for(@args) ) { |
38
|
10
|
|
|
|
|
43
|
return $result; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
__END__ |