Question

I understand this question has been asked in different forms before.

Here is the line in Google::V3.pm:

use lib '/var/www/cgi-bin/lib';
use Carp;
use Encode;
use JSON;
use HTTP::Request;
use LWP::UserAgent;
use URI;

...

my $uri = URI->new("http://$self->{host}/maps/api/geocode/json");
my %query_parameters = ($loc_param => $location);

...

my $components_params = $self->_get_components_query_params;
$query_parameters{components} = $components_params if defined $components_params;
$uri->query_form(%query_parameters);
my $url = $uri->as_string;

Here's the code from URI::_foreign.pm:

package URI::_foreign;

require URI::_generic;
@ISA=qw(URI::_generic);

1;

How can I resolve this?

Was it helpful?

Solution

The URI constructor creates an object instance specific to the scheme of the data passed to it. For http data, that is URI::http. However, if it's unable to determine a scheme, the final fall back is of class URI::_foreign.

Each of these subclasses have different abilities and features. As you've observed, the base class _foreign does not have an implementation of query_form.

So our question why is your data not being interpreted as http? I also think, like ikegami, that what you posted is not representative of the $uri you actually had.

Here is a script that shows how URI will interpret data specific to the scheme:

use strict;
use warnings;

use URI;

while (<DATA>) {
    chomp;

    my $u = URI->new($_);
    printf "%-13s - %s\n", ref($u), $u;
}

__DATA__
http://www.asdf.com
http://www.asdf.com/morestuff
http://////too_many_slashes_still_ok
ftp://ftp.asdf.com/
gopher://oldtimey.com/
unknown://www.asdf.com/

outputs:

URI::http     - http://www.asdf.com
URI::http     - http://www.asdf.com/morestuff
URI::http     - http://////too_many_slashes_still_ok
URI::ftp      - ftp://ftp.asdf.com/
URI::gopher   - gopher://oldtimey.com/
URI::_foreign - unknown://www.asdf.com/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top