develooper Front page | perl.libwww | Postings from November 2002

Re: URI Bug?

Thread Previous | Thread Next
Gisle Aas
November 23, 2002 09:55
Re: URI Bug?
Message ID:
Hans de Graaff <> writes:

> I think the problem is that host() is only supported for those schemes
> that have an authority component (see perldoc URI for more
> details). It would be nice if there would be a simple test to
> determine which schemes qualify for this. Currently I have this
> hardcoded in my application to do this:
>     $url->host(ip_address($url->host)) if $url->scheme =~ /^(https?|ftp|gopher|https|ldap|news|nntp|pop|rlogin|snews|telnet)$/;
> I'd be happy to learn of a better way to do this, and I'm sure my list
> is not complete anyway.

I suggest either:

    $url->host(ip_address($url->host)) if $url->can("host");


    if (my $host = $url->can("host")) {
        &$host($url, ip_address(&$host($url)));


    eval { $url->host(ip_address($url->host)) };
    die $@ if $@ && $@ !~ /^Can't locate object method "host"/;


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About