Apache-AxKit-Provider-XMLDOMProvider
view release on metacpan or search on metacpan
lib/Apache/AxKit/Provider/XMLDOMProvider.pm view on Meta::CPAN
my $response = $ua->get($url);
# store some stuff for later use
$self->{response} = $response;
$self->{xmlfile} = $url;
$self->{id} = $url;
$self->{mtime_element} = $mtime_element;
}
# sub: get_fh
# we don't want to handle files, so we just throw an exception here.
sub get_fh {
throw Apache::AxKit::Exception::IO( -text => "Can't get filehandle for XMLDOMProvider (not yet implemented)!" );
}
# sub: get_strref
# since we refused to work with file handles, we HAVE to define this.
# returns a string containing the remote XML-DOM
sub get_strref {
my $self = shift;
my $response = $self->{response};
my $string = $response->content();
# debug
#my $h = $response->server;
#throw Apache::AxKit::Exception::Error(-text => "Last Modified Header: \"$h\"");
# some XML validation
my $parser = XML::LibXML->new();
$parser->validation(0);
$parser->load_ext_dtd(0);
$parser->expand_xinclude(0);
$parser->expand_entities(0);
my $dom;
eval {
$dom = $parser->parse_string($string);
};
if ($@) {
throw Apache::AxKit::Exception::Error( -text => "Input must be well-formed XML: $@" );
}
# if everything went fine, return xml-string-reference
return \$string;
}
# sub: mtime
# we want to cache our stuff; the mtime is determined
# from the mdate (YYYY-MM-DD hh:mm) element "<mdate></mdate>" placed
# somewhere in the remote XML-DOM;
lib/Apache/AxKit/Provider/XMLDOMProvider.pm view on Meta::CPAN
# sub: key
# should return a unique identifier for the resource.
# we assume the id from the uri (including query params) is a good one.
sub key {
my $self = shift;
return $self->{id};
}
# sub: exists
# returns 1 if remote XML-DOM is accessible
# throws AxKit IO exception otherwise
sub exists {
my $self = shift;
my $response = $self->{response};
my $url = $self->{xmlfile};
if ( $response->is_success() ) {
return 1;
}
else {
throw Apache::AxKit::Exception::IO( -text => $response->status_line() . ": Cannot access upstream resource: \"$url\"" );
}
}
1;
__END__
# Below is stub documentation for your module. You'd better edit it!
=head1 NAME
Apache::AxKit::Provider::XMLDOMProvider - AxKit Provider for remote XML-DOMs available via HTTP
( run in 0.368 second using v1.01-cache-2.11-cpan-496ff517765 )