# Copyright (c) 2000 Clark Cooper
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
## Note that this external entity handler reads the entire entity into
## memory, so it will choke on huge ones. It would be really nice if
## LWP::UserAgent optionally returned us an IO::Handle.
sub lwp_ext_ent_handler
{
my ($xp, $base, $sys) = @_; # We don't use public id
# Base may have been set by parsefile, which is agnostic about
# whether its a file or URI.
my $base_uri = new URI
($base);
unless (defined $base_uri->scheme) {
$base_uri = URI
->new_abs($base_uri, URI
::file
->cwd);
$uri = URI
->new_abs($sys, $base_uri);
unless (defined $uri->scheme) {
$uri = URI
->new_abs($uri, URI
::file
->cwd);
my $ua = $xp->{_lwpagent
};
$ua = $xp->{_lwpagent
} = new LWP
::UserAgent
();
my $req = new HTTP
::Request
('GET', $uri);
my $res = $ua->request($req);
$xp->{ErrorMessage
} .= "\n" . $res->status_line . " $uri";
$xp->{_BaseStack
} ||= [];
push(@
{$xp->{_BaseStack
}}, $base);
} # End lwp_ext_ent_handler
sub lwp_ext_ent_cleanup
{
$xp->base(pop(@
{$xp->{_BaseStack
}}));
} # End lwp_ext_ent_cleanup