# -*- cperl -*- package POE::Component::IRC::Plugin::NoPaste::DB; use strict; use warnings; use DBI; use Hash::Util qw(lock_keys); sub new { my ($class, $config) = @_; my $this = bless {} => $class; $this->{config} = $config; $this->{dbh} = DBI->connect( "dbi:SQLite:dbname=$config->{db}{file}", "", "", { RaiseError => 1, AutoCommit => 1, }); lock_keys %$this; $this->setup_db; $this; } sub dbh { my $this = shift; $this->{dbh}; } sub setup_db { my $this = shift; eval { $this->{dbh}->do(q{ SELECT * FROM post LIMIT 0 }); }; if ($@) { $this->{dbh}->do(q{ CREATE TABLE post ( post_id INTEGER PRIMARY KEY, -- unique id of the post channel_id VARCHAR(512) NOT NULL, -- id of the channel in ascii posted_time INTEGER NOT NULL, -- timestamp in epoch nick VARCHAR(512) NOT NULL, -- nick of the person who posted this title BLOB NOT NULL, -- title of the post body BLOB NOT NULL -- body of the post ); }); } } 1;