summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Fiegehenn <simbabque@cpan.org>2023-04-29 14:41:17 +0100
committerOlaf Alders <olaf@wundersolutions.com>2023-04-29 15:58:40 +0200
commit85253786118786f88c52ffcf3fbf34c3e721d953 (patch)
tree6859c8986a0f7a7fae23e5155715f113a45cb8e4
parent44ebc98e09bfdda797b52940d7ee941c97e406b5 (diff)
downloaduri-85253786118786f88c52ffcf3fbf34c3e721d953.tar.gz
rephrase POD and add test to prove it
-rw-r--r--Changes2
-rw-r--r--lib/URI.pm13
-rw-r--r--t/iri.t11
3 files changed, 19 insertions, 7 deletions
diff --git a/Changes b/Changes
index c1b17d5..6e02d50 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,8 @@ Revision history for URI
{{$NEXT}}
- Add a GH workflow to test LWP::Curl (GH#116) (Olaf Alders)
+ - Add documentation examples for the host() and ihost() methods (GH#28)
+ (Sebastian Willing)
5.17 2022-11-02 17:03:48Z
- Updated RFC references in the pod documentation for URI::file (GH#117)
diff --git a/lib/URI.pm b/lib/URI.pm
index 042ddc5..e83b79d 100644
--- a/lib/URI.pm
+++ b/lib/URI.pm
@@ -57,7 +57,7 @@ sub new
$uri = defined ($uri) ? "$uri" : ""; # stringify
# Get rid of potential wrapping
- $uri =~ s/^<(?:URL:)?(.*)>$/$1/; #
+ $uri =~ s/^<(?:URL:)?(.*)>$/$1/; #
$uri =~ s/^"(.*)"$/$1/;
$uri =~ s/^\s+//;
$uri =~ s/\s+$//;
@@ -230,7 +230,7 @@ sub _scheme
Carp::croak("Bad scheme '$new'") unless $new =~ /^$scheme_re$/o;
$old = $1 if $$self =~ s/^($scheme_re)://o;
my $newself = URI->new("$new:$$self");
- $$self = $$newself;
+ $$self = $$newself;
bless $self, ref($newself);
}
else {
@@ -876,7 +876,7 @@ every case where it has been used.
Sets and returns the unescaped hostname.
-If the $new_host string ends with a colon and a number, then this
+If the C<$new_host> string ends with a colon and a number, then this
number also sets the port.
For IPv6 addresses the brackets around the raw address is removed in the return
@@ -884,14 +884,17 @@ value from $uri->host. When setting the host attribute to an IPv6 address you
can use a raw address or one enclosed in brackets. The address needs to be
enclosed in brackets if you want to pass in a new port value as well.
-Sample: Returns I<www.xn--ri-sample-fra0f> for I<http://www.E<0xC3>E<0xBC>ri-sample/foo/bar.html>
+ my $uri = URI->new("http://www.\xC3\xBCri-sample/foo/bar.html");
+ print $u->host; # www.xn--ri-sample-fra0f
+
=item $uri->ihost
Returns the host in Unicode form. Any IDNA A-labels (encoded unicode chars with
I<xn--> prefix) are turned into U-labels (unicode chars).
-Sample: Returns I<www.E<0xC3>E<0xBC>ri-sample> for I<http://www.E<0xC3>E<0xBC>ri-sample/foo/bar.html>
+ my $uri = URI->new("http://www.\xC3\xBCri-sample/foo/bar.html");
+ print $u->ihost; # www.\xC3\xBCri-sample
=item $uri->port
diff --git a/t/iri.t b/t/iri.t
index 2eb64b2..cf983d6 100644
--- a/t/iri.t
+++ b/t/iri.t
@@ -6,9 +6,9 @@ use Test::More;
use Config qw( %Config );
if (defined $Config{useperlio}) {
- plan tests=>26;
+ plan tests=>30;
} else {
- plan skip_all=>'this perl doesn\'t support PerlIO layers';
+ plan skip_all=>"this perl doesn't support PerlIO layers";
}
use URI ();
@@ -25,6 +25,13 @@ is $u->host, "xn--bcher-kva.ch";
is $u->ihost, "bücher.ch";
is $u->as_iri, "http://bücher.ch";
+# example from the docs for host and ihost
+$u = URI->new("http://www.\xC3\xBCri-sample/foo/bar.html");
+is $u, "http://www.xn--ri-sample-fra0f/foo/bar.html";
+is $u->host, "www.xn--ri-sample-fra0f";
+is $u->ihost, "www.\xC3\xBCri-sample";
+is $u->as_iri, "http://www.\xC3\xBCri-sample/foo/bar.html";
+
$u = URI->new("http://example.com/Bücher");
is $u, "http://example.com/B%C3%BCcher";
is $u->as_iri, "http://example.com/Bücher";