line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#============================================================= -*-Perl-*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Template::Plugin::URL |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# DESCRIPTION |
6
|
|
|
|
|
|
|
# Template Toolkit Plugin for constructing URL's from a base stem |
7
|
|
|
|
|
|
|
# and adaptable parameters. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# AUTHOR |
10
|
|
|
|
|
|
|
# Andy Wardley |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# COPYRIGHT |
13
|
|
|
|
|
|
|
# Copyright (C) 2000-2007 Andy Wardley. All Rights Reserved. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# This module is free software; you can redistribute it and/or |
16
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
#============================================================================ |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
package Template::Plugin::URL; |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
|
680
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
75
|
|
23
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
71
|
|
24
|
2
|
|
|
2
|
|
10
|
use base 'Template::Plugin'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1198
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $VERSION = 2.74; |
27
|
|
|
|
|
|
|
our $JOINT = '&'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
31
|
|
|
|
|
|
|
# new($context, $baseurl, \%url_params) |
32
|
|
|
|
|
|
|
# |
33
|
|
|
|
|
|
|
# Constructor method which returns a sub-routine closure for constructing |
34
|
|
|
|
|
|
|
# complex URL's from a base part and hash of additional parameters. |
35
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub new { |
38
|
13
|
|
|
13
|
1
|
78
|
my ($class, $context, $base, $args) = @_; |
39
|
13
|
|
100
|
|
|
60
|
$args ||= { }; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return sub { |
42
|
28
|
100
|
|
28
|
|
469
|
my $newbase = shift unless ref $_[0] eq 'HASH'; |
43
|
28
|
|
100
|
|
|
109
|
my $newargs = shift || { }; |
44
|
28
|
|
|
|
|
110
|
my $combo = { %$args, %$newargs }; |
45
|
33
|
|
|
|
|
93
|
my $urlargs = join($JOINT, |
46
|
33
|
50
|
|
|
|
192
|
map { args($_, $combo->{ $_ }) } |
47
|
28
|
|
|
|
|
136
|
grep { defined $combo->{ $_ } && length $combo->{ $_ } } |
48
|
|
|
|
|
|
|
sort keys %$combo); |
49
|
|
|
|
|
|
|
|
50
|
28
|
|
100
|
|
|
154
|
my $query = $newbase || $base || ''; |
51
|
28
|
100
|
100
|
|
|
152
|
$query .= '?' if length $query && length $urlargs; |
52
|
28
|
100
|
|
|
|
67
|
$query .= $urlargs if length $urlargs; |
53
|
|
|
|
|
|
|
|
54
|
28
|
|
|
|
|
206
|
return $query |
55
|
|
|
|
|
|
|
} |
56
|
13
|
|
|
|
|
142
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub args { |
60
|
33
|
|
|
33
|
0
|
73
|
my ($key, $val) = @_; |
61
|
33
|
|
|
|
|
69
|
$key = escape($key); |
62
|
|
|
|
|
|
|
|
63
|
36
|
|
|
|
|
79
|
return map { |
64
|
33
|
100
|
|
|
|
97
|
"$key=" . escape($_); |
65
|
|
|
|
|
|
|
} ref $val eq 'ARRAY' ? @$val : $val; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
70
|
|
|
|
|
|
|
# escape($url) |
71
|
|
|
|
|
|
|
# |
72
|
|
|
|
|
|
|
# URL-encode data. Borrowed with minor modifications from CGI.pm. |
73
|
|
|
|
|
|
|
# Kudos to Lincold Stein. |
74
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub escape { |
77
|
69
|
|
|
69
|
0
|
90
|
my $toencode = shift; |
78
|
69
|
50
|
|
|
|
144
|
return undef unless defined($toencode); |
79
|
69
|
|
|
|
|
143
|
utf8::encode($toencode); |
80
|
69
|
|
|
|
|
122
|
$toencode=~s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg; |
|
7
|
|
|
|
|
40
|
|
81
|
69
|
|
|
|
|
295
|
return $toencode; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |