📄 ch20_05.htm
字号:
new_abs($<em class="replaceable">str</em>, $<em class="replaceable">base_uri</em>)</pre><p>Creates a new absolute URI object.<tt class="literal">$</tt><em class="replaceable"><tt>str</tt></em> represents theabsolute URI, and<tt class="literal">$</tt><em class="replaceable"><tt>base_uri</tt></em> representsthe relative URI.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>opaque</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>opaque([$<em class="replaceable">new_opaque_value</em>])</pre><p>Sets and gets the scheme-specific part of<tt class="literal">$</tt><em class="replaceable"><tt>uri</tt></em>.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>path</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>path([$<em class="replaceable">path</em>])</pre><p>Sets and gets the escaped path component of<tt class="literal">$</tt><em class="replaceable"><tt>uri</tt></em>. Returns emptystring ("") if there is no path.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>path</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>path([$<em class="replaceable">new_path</em>])</pre><p>Gets and sets the same value as <tt class="literal">opaque</tt>, unless theURI supports the generic syntax for heirarchical namespaces.<tt class="literal">path</tt> returns the part of the URI between thehostname and the fragment.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>path_query</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>path_query([$<em class="replaceable">path_here</em>])</pre><p>Sets and gets the escapted path and query components.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>path_segments</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>path_segments([$<em class="replaceable">seg</em>])</pre><p>Sets and gets the path. In a scalar content,<tt class="literal">path_segments</tt> is equivalent to<tt class="literal">path</tt>. In a list contents,<tt class="literal">path_segments</tt> returns the unescaped path segmentsthat make up the path.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>port</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>port([$<em class="replaceable">new_port</em>])</pre><p>Sets and gets the port, which is an integer. If<tt class="literal">$</tt><em class="replaceable"><tt>new_port</tt></em> is notdefined, then the default port of the URI scheme will be returned.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>query</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>query([$<em class="replaceable">q</em>])</pre><p>Sets and gets the escaped query component of<tt class="literal">$</tt> <em class="emphasis">uri</em> .</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>query_form</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>query_form([$<em class="replaceable">key</em> => $<em class="replaceable">val</em>])</pre><p>Sets and gets query components that use the urlencoded format.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>query_keywords</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>query_keywords([$<em class="replaceable">keywords</em>])</pre><p>Sets and gets query components that use keywords separated by a<tt class="literal">+</tt>.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>rel</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>rel($<em class="replaceable">base_uri</em>)</pre><p>Returns a relative URI reference, if one exists. Otherwise,<tt class="literal">$</tt><em class="replaceable"><tt>uri</tt></em> is returned.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>scheme</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>scheme([$<em class="replaceable">some_scheme</em>])</pre><p>Sets and gets the scheme part of the URI. Such values include:<tt class="literal">data</tt>, <tt class="literal">file</tt>,<tt class="literal">ftp</tt>, <tt class="literal">gopher</tt>,<tt class="literal">http</tt>, <tt class="literal">https</tt>,<tt class="literal">ldap</tt>, <tt class="literal">mailto</tt>,<tt class="literal">news</tt>, <tt class="literal">nntp</tt>,<tt class="literal">pop</tt>, <tt class="literal">rlogin</tt>,<tt class="literal">rsync</tt>, <tt class="literal">snews</tt>,<tt class="literal">telnet</tt>, and <tt class="literal">ssh</tt>. In the case ofrelative URIs, <tt class="literal">scheme</tt> will return<tt class="literal">undef</tt>; otherwise, <tt class="literal">scheme</tt> willreturn the scheme in lowercase. With<tt class="literal">$</tt><em class="replaceable"><tt>some_scheme</tt></em>,<tt class="literal">scheme</tt> will set the scheme of the current URI.<tt class="literal">scheme</tt> will die if the scheme isn't supported, orif it contains non-US-ASCII characters.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>userinfo</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>userinfo([$<em class="replaceable">new_userinfo</em>])</pre><p>Sets and gets the escaped"userinfo" part of the authoritycomponent (of the URI). Often, the userinfo will appear as a usernameand password separated by a colon. Bear in mind that sending apassword in the clear is a bad idea.</p></div></div></div><a name="perlnut2-CHP-20-SECT-5.2" /><div class="sect2"><h3 class="sect2">20.5.2. URI::Escape</h3><p>This module escapes or unescapes"unsafe" characters within a URLstring. Unsafe characters in URLs are described by RFC 1738. Beforeyou form URI::URL objects and use that class'smethods, you should make sure your strings are properly escaped. Thismodule does not create its own objects; it exports the followingfunctions:</p><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>uri_escape</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>uri_escape <em class="replaceable">uri</em>, [<em class="replaceable">regexp</em>]</pre><p>Given a URI as the first parameter, returns the equivalent URI withcertain characters replaced with <tt class="literal">%</tt> followed by twohexadecimal digits. The first parameter can be a text string, such as<tt class="literal">"http:www.oreilly.com"</tt>, or an object of typeURI::URL. When invoked without a second parameter,<tt class="literal">uri_escape</tt> escapes characters specified by RFC1738. Otherwise, you can pass in a regular expression (in the contextof <tt class="literal">[ ]</tt>) of characters to escape as the secondparameter. For example:</p><blockquote><pre class="code">$escaped_uri = uri_escape($uri, 'aeiou')</pre></blockquote><p>This code escapes all lowercase vowels in <tt class="literal">$uri</tt> andreturns the escaped version.</p></div><a name="INDEX-2634" /><a name="INDEX-2635" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>uri_unescape</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>uri_unescape <em class="replaceable">uri</em></pre><p>Substitutes any instance of <tt class="literal">%</tt> followed by twohexadecimal digits back into its original form and returns the entireURI in unescaped form.<a name="INDEX-2634" /><a name="INDEX-2635" /> </p></div></div><a name="perlnut2-CHP-20-SECT-5.3" /><div class="sect2"><h3 class="sect2">20.5.3. URI::URL</h3><p><a name="INDEX-2636" /><a name="INDEX-2637" /><a name="INDEX-2638" />This module creates URL objects thatstore all the elements of a URL. These objects are used by the<tt class="literal">request</tt> method of LWP::UserAgent for serveraddresses, port numbers, filenames, protocol, and many other elementsthat can be loaded into a URL.</p><p><a name="INDEX-2639" />The <tt class="literal">new</tt> constructoris used to make a URI::URL object:</p><blockquote><pre class="code">$url = URI::URL->new($url_string [, $base_url])</pre></blockquote><p>This method creates a new URI::URL object with the URL given as thefirst parameter. An optional base URL can be specified as the secondparameter and is useful for generating an absolute URL from arelative URL.</p><p>The following methods are for the URI::URL class.</p><a name="INDEX-2640" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>abs</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">url</em>->abs([<em class="replaceable">base</em>, [<em class="replaceable">scheme</em>]])</pre><p><a name="INDEX-2640" />Returns the absolute URL, given a base.If invoked with no parameters, any previous definition of the base isused. The second parameter is a Boolean that modifies<tt class="literal">abs</tt>'s behavior. When the secondparameter is nonzero, <tt class="literal">abs</tt> will accept a relativeURL with a scheme but no host, such as<tt class="literal">http:index.html</tt>.</p></div><a name="INDEX-2641" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>as_string</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">url</em>->as_string( )</pre><p><a name="INDEX-2641" />Returns the URL as a scalar string. Alldefined components of the URL are included in the string.</p></div>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -