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

Re: URI Bug?

Thread Previous | Thread Next
From:
Gisle Aas
Date:
November 23, 2002 09:55
Subject:
Re: URI Bug?
Message ID:
lradk0416f.fsf@caliper.activestate.com
Hans de Graaff <hans@degraaff.org> 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");

or:

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

or:

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


Regards,
Gisle

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About