aboutsummaryrefslogtreecommitdiffstats
path: root/lib/SpamCat.pm
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2015-10-20 10:51:11 -0400
committerBrian Cully <bjc@kublai.com>2015-10-20 12:08:36 -0400
commitf887806c5989fc3e5c86107d6ff945a6fc63b05c (patch)
tree433bd701b6b03e6b1ebd0d800e6469aef61cc3e7 /lib/SpamCat.pm
parentb22b545fbe0f9d58792fd6b9659dd5013459c66d (diff)
downloadspamcat-f887806c5989fc3e5c86107d6ff945a6fc63b05c.tar.gz
spamcat-f887806c5989fc3e5c86107d6ff945a6fc63b05c.zip
Various changes.
* Use `env' to find perl binary. * Change flag --dumpconfig to command. * Add `dump' command to output table in tab-delimited format. * Update documentation.
Diffstat (limited to 'lib/SpamCat.pm')
-rw-r--r--lib/SpamCat.pm29
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/SpamCat.pm b/lib/SpamCat.pm
index 5c6db51..d470520 100644
--- a/lib/SpamCat.pm
+++ b/lib/SpamCat.pm
@@ -75,6 +75,12 @@ sub parse_to {
} @tovals;
}
+sub get_table {
+ my ($self) = @_;
+
+ $self->in_transaction(sub { $self->get_table_t() });
+}
+
sub get_count {
my ($self, $sender) = @_;
@@ -97,6 +103,26 @@ sub decrement_count {
# The _t functions are meant to be run inside transacitons.
#
+sub get_table_t {
+ my ($self) = @_;
+
+ my @rows;
+ my $q = 'SELECT * FROM emails';
+ my $sth = $self->{dbh}->prepare($q);
+ $sth->execute();
+ while (my $row = $sth->fetchrow_hashref) {
+ push @rows, $row
+ }
+ if ($sth->err) {
+ $sth->finish;
+ carp $sth->errstr;
+ return;
+ }
+ $sth->finish;
+
+ \@rows;
+}
+
sub get_count_t {
my ($self, $sender) = @_;
@@ -154,8 +180,7 @@ sub in_transaction {
my $rc = eval { &$sub($self); };
if ($@) {
$self->{dbh}->rollback;
- warn "ERROR: Transaction failed: $@\n";
- exit 1;
+ carp "Transaction failed: $@\n";
} else {
$self->{dbh}->commit;
}