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