Sean M. Burke

NAME

XML::RSS::TimingBotDBI - XML::RSS::TimingBot-subclass that saves state with DBI

SYNOPSIS

  use XML::RSS::TimingBotDBI;
  use DBI;
  
  my $dbh = DBI->connect( 'whatever...' )
   || die "Can't connect: $DBI::errstr\nAborting";
  
  my $table = "myrsstable";
  
  $browser = XML::RSS::TimingBotDBI->new;
  $browser->rssagent_dbh($dbh);
  $browser->rssagent_table($table);
  
  my $response = $browser->get(
    'http://interglacial.com/rss/cairo_times.rss'
  );

  ... And process $response just as if it came from
     a plain old LWP::UserAgent object, for example: ...
  
  if($response->code == '200') {
    ...process it...
  }

DESCRIPTION

This class is for requesting RSS feeds only as often as needed, and storing in a database the data about how often what feeds can be requested.

This is a subclass of XML::RSS::TimingBot's methods that stores its data in a DBI database object that you specify, instead of using XML::RSS::TimingBot's behavior of storing in a local flat-file database.

To use this class, use it, create a new object of this class, and use DBI and make a new database handle-object; then use rssagent_dbh to assign that handle to this TimingBotDBI object; and use rssagent_url_field, rssagent_lastmod_field, rssagent_nextupdate_field, and rssagent_fetag_field to set up the right table/field names; and then, finally, you can use the TimingBotDBI object just like a LWP::UserAgent (actually LWP::UserAgent::Determined) object, to request RSS feeds.

METHODS

This module inherits all of XML::RSS::TimingBot's methods, and adds the following ones. (These examples are of setting the value of these attributes; but if you call them without any arguments, then you get back the current value of that method. As in $tblname = $browser->rssagent_table;.)

$browser->rssagent_dbh( $dbh );

This sets what DBI handle is used for reading and writing data about feeds that this $browser object will/might process.

$browser->rssagent_table( 'rssjunk' );

This sets the name of the DBI table that the data will be stored in. The default values is "rsstibot".

NOTE: If this table doesn't exist when you call $browser->get($some_rss_thing), then it will be created with some relatively sane defaults.

$browser->rssagent_url_field( 'furl' );

This sets the name of the key field that will be used for storing the URL of each feed being processed. The default value is "feedurl".

$browser->rssagent_lastmod_field( 'lastm' );

This sets the name of the field that will be used for storing the date string gotten from "Last-Modified" header on each feed being processed. The default value is "lastmod".

$browser->rssagent_nextupdate_field( 'nextu' );

This sets the name of the field that will be used for storing the integer expressing the soonest time that this feed can be polled for new data. The default value is "nextup".

$browser->rssagent_etag_field( 'entwad' );

This sets the name of the field that will be used for storing the string gotten from the "ETag" header on each feed being processed. The default value is "etag".

IMPLEMENTATION

This class works by overriding XML:RSS::TimingBot's "datum_from_db" and "commit" methods.

DATABASE FUNK

If the SQL that this class uses isn't right for you, email me about it! It works for me, but I'd be interested to hear about cases of it failing.

SEE ALSO

XML::RSS::TimingBot, XML::RSS::Timing, LWP::UserAgent::Determined, LWP::UserAgent, LWP, DBI

COPYRIGHT AND DISCLAIMER

Copyright 2004, Sean M. Burke sburke@cpan.org, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.

AUTHOR

Sean M. Burke, sburke@cpan.org