Apache-AxKit-Provider-XMLDOMProvider
view release on metacpan or search on metacpan
lib/Apache/AxKit/Provider/XMLDOMProvider.pm view on Meta::CPAN
# test if $mdate is provided in xml-dom
if ( defined $mdate ) {
# create time-piece object
# mdate format example: 2007-06-26 02:42
my $time_obj = Time::Piece->strptime( $mdate, "%Y-%m-%d %H:%M" );
$mtime = $time_obj->epoch();
# debug
#print STDERR Dumper( "mtime in secs: ", $mtime );
}
else {
# else invalidate cache
$mtime = time();
# debug
#print STDERR Dumper("now: ", $mtime );
}
# cache mtime, since mtime is called twice per request
$self->{mtime}->{$self->{id}} = $mtime;
# debug
#print STDERR Dumper( "return value: ", $mtime );
return $mtime;
}
# sub: process
# we always answer requests :-)
sub process {
my $self = shift;
return 1;
}
# 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
=head1 SYNOPSIS
AxContentProvider Apache::AxKit::Provider::XMLDOMProvider
PerlSetVar RemoteXML "http://www.example.com/xmlfile.xml"
PerlSetVar RemoteXMLmTimeElement "mdate"
=head1 DESCRIPTION
Apache::AxKit::Provider::XMLDOMProvider allows for local transformation of
remote XML-Files available via HTTP. The remote XML-file for local processing
can be specified in the Apache::AxKit configuration. Additionally, an element
holding adequate modification time information can be provided via the
Apache::AxKit configuration. This Apache::AxKit-Provider is very useful for
local processing of dynamically generated XML-DOMs available via a Web-server,
especially if one needs to pass specific query parameters to it.
The URI of the remote XML-file is specified with the RemoteXML variable.
RemoteXMLmTimeElement should hold the name of the XML-Element which contains
date information when the remote XML-file was last modified (format "YYYY-MM-DD
hh:mm"; e.g. "2007-07-15 16:20"). Is the element specifying the modification
time not present, the remote XML-file will not be cached and hence fetched for
each request. This module uses LWP::UserAgent to get remote XML-files.
=head2 EXPORT
All by default.
=head1 SEE ALSO
Apache::AxKit (http://www.axkit.org)
=head1 AUTHOR
Severin Gehwolf, E<lt>Severin.Gehwolf@uibk.ac.atE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2007 by Severin Gehwolf
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.8 or,
at your option, any later version of Perl 5 you may have available.
=cut
( run in 1.245 second using v1.01-cache-2.11-cpan-13bb782fe5a )