line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#----------------------------------------------------------------- |
2
|
|
|
|
|
|
|
# CGI::URI2param - convert parts of an URL to param values |
3
|
|
|
|
|
|
|
#----------------------------------------------------------------- |
4
|
|
|
|
|
|
|
# Copyright Thomas Klausner / ZSI 2001,2002,2006 |
5
|
|
|
|
|
|
|
# You may use and distribute this module according to the same terms |
6
|
|
|
|
|
|
|
# that Perl is distributed under. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# Thomas Klausner domm@cpan.org http://domm.plix.at |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
#----------------------------------------------------------------- |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package CGI::URI2param; |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
58075
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
79
|
|
15
|
2
|
|
|
2
|
|
12
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
199
|
|
16
|
2
|
|
|
2
|
|
11
|
use Exporter; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
77
|
|
17
|
2
|
|
|
2
|
|
11
|
use vars qw(@ISA @EXPORT_OK); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
634
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
@EXPORT_OK = qw(uri2param); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$CGI::URI2param::VERSION = '1.01'; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub uri2param { |
26
|
1
|
|
|
1
|
1
|
414
|
my ($req,$regexs,$options)=@_; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# options not implemented, possible options are: |
29
|
|
|
|
|
|
|
# -> don't safe in $q->param but return parsed stuff as hash/array |
30
|
|
|
|
|
|
|
# -> use URI instead of PATH_INFO |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# check if $req seems to be a valid request object |
33
|
1
|
50
|
|
|
|
7
|
croak "CGI::URI2param: not a valid request object" unless $req->can('param'); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# check environment and set stuff |
36
|
1
|
|
|
|
|
2
|
my $uri; |
37
|
1
|
50
|
|
|
|
6
|
if ($ENV{MOD_PERL}) { |
38
|
0
|
|
|
|
|
0
|
$uri=$req->uri; |
39
|
|
|
|
|
|
|
} else { |
40
|
1
|
|
|
|
|
5
|
$uri=$req->url . $req->path_info; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# apply regexes |
44
|
1
|
|
|
|
|
9
|
eval { |
45
|
1
|
|
|
|
|
6
|
while(my($key,$regex)=each(%$regexs)) { |
46
|
2
|
50
|
|
|
|
63
|
if ($uri=~m/$regex/) { |
47
|
2
|
|
|
|
|
8
|
$req->param($key,$+); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
|
52
|
1
|
50
|
|
|
|
14
|
croak $@ if ($@); |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
5
|
return 1; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |