I bet $a is a relative uri or not a uri at all. Update: Or maybe the URI uses a scheme URI.pm doesn't recognize.
use URI ();
$uri = URI->new('index.pl');
print('Host of Relative URI ', $uri->as_string(), ':', $/);
eval { print($uri->host(), $/); };
print($@) if ($@);
print($/);
$uri = URI->new('www.perlmonks.com');
print('Host of something (', $uri->as_string(), ') that isn\'t a URI a
+t all:', $/);
eval { print($uri->host(), $/); };
print($@) if ($@);
print($/);
$uri = URI->new('ikegami://www.perlmonks.com/');
print('Host of a URI (', $uri->as_string(), ') whose scheme URI.pm doe
+sn\'t recognize:', $/);
eval { print($uri->host(), $/); };
print($@) if ($@);
print($/);
$uri = URI->new('http://www.perlmonks.com/');
print('Host of Absolute URI ', $uri->as_string(), ':', $/);
eval { print($uri->host(), $/); };
print($@) if ($@);
print($/);
$base_uri = URI->new('http://www.perlmonks.com/');
$rel_uri = URI->new('index.pl');
$abs_uri = $rel_uri->abs($base_uri);
print('Host of Relative URI ', $rel_uri->as_string(), ' converted to a
+ Absolute URI using Base URI ', $base_uri->as_string(), ':', $/);
eval { print($abs_uri->host(), $/); };
print($@) if ($@);
print($/);
__END__
output
======
Host of Relative URI index.pl:
Can't locate object method "host" via package "URI::_generic" (perhaps
+ you forgot to load "URI::_generic"?) at !.pl line 5.
Host of something (www.perlmonks.com) that isn't a URI at all:
Can't locate object method "host" via package "URI::_generic" (perhaps
+ you forgot to load "URI::_generic"?) at !.pl line 11.
Host of a URI (ikegami://www.perlmonks.com/) whose scheme URI.pm doesn
+'t recognize:
Can't locate object method "host" via package "URI::_foreign" (perhaps
+ you forgot to load "URI::_foreign"?) at !.pl line 17.
Host of Absolute URI http://www.perlmonks.com/:
www.perlmonks.com
Host of Relative URI index.pl converted to a Absolute URI using Base U
+RI http://www.perlmonks.com/:
www.perlmonks.com
|