1URI::FromHash(3) User Contributed Perl Documentation URI::FromHash(3)
2
3
4
6 URI::FromHash - Build a URI from a set of named parameters
7
9 use URI::FromHash qw( uri );
10
11 my $uri = uri( path => '/some/path',
12 query => { foo => 1, bar => 2 },
13 );
14
16 This module provides a simple one-subroutine "named parameters" style
17 interface for creating URIs. Underneath the hood it uses "URI.pm",
18 though because of the simplified interface it may not support all
19 possible options for all types of URIs.
20
21 It was created for the common case where you simply want to have a
22 simple interface for creating syntactically correct URIs from known
23 components (like a path and query string). Doing this using the native
24 "URI.pm" interface is rather tedious, requiring a number of method
25 calls, which is particularly ugly when done inside a templating system
26 such as Mason or TT2.
27
29 This module provides two functions both of which are optionally
30 exportable:
31
32 uri( ... ) and uri_object( ... )
33 Both of these functions accept the same set of parameters, except for
34 one additional parameter allowed when calling "uri()".
35
36 The "uri()" function simply returns a string representing a
37 canonicalized URI based on the provided parameters. The "uri_object()"
38 function returns new a "URI.pm" object based on the given parameters.
39
40 These parameters are:
41
42 · scheme
43
44 The URI's scheme. This is optional, and if none is given you will
45 create a schemeless URI. This is useful if you want to create a URI
46 to a path on the same server (as is commonly done in "<a>" tags).
47
48 · host
49
50 · port
51
52 · path
53
54 The path can be either a string or an array reference.
55
56 If an array reference is passed each defined member of the array
57 will be joined by a single forward slash (/).
58
59 If you are building a host-less URI and want to include a leading
60 slash then make the first element of the array reference an empty
61 string ('').
62
63 You can add a trailing slash by making the last element of the
64 array reference an empty string.
65
66 · username
67
68 · password
69
70 · fragment
71
72 All of these are optional strings which can be used to specify that
73 part of the URI.
74
75 · query
76
77 This should be a hash reference of query parameters. The values for
78 each key may be a scalar or array reference. Use an array reference
79 to provide multiple values for one key.
80
81 · query_separator
82
83 This option is can only be provided when calling "uri()". By
84 default, it is a semi-colon (;).
85
87 Dave Rolsky, <autarch@urth.org>
88
90 Please report any bugs or feature requests to
91 "bug-uri-fromhash@rt.cpan.org", or through the web interface at
92 <http://rt.cpan.org>. I will be notified, and then you'll
93 automatically be notified of progress on your bug as I make changes.
94
96 Copyright 2006-2008 Dave Rolsky, All Rights Reserved.
97
98 This program is free software; you can redistribute it and/or modify it
99 under the same terms as Perl itself.
100
102 Hey! The above document had some coding errors, which are explained
103 below:
104
105 Around line 226:
106 =back without =over
107
108
109
110perl v5.12.0 2010-05-07 URI::FromHash(3)