Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Added TODO file #2

Merged
merged 2 commits into from Aug 13, 2013
Jump to file or symbol
Failed to load files and symbols.
+85 −0
Split
View
21 TODO
@@ -0,0 +1,21 @@
+From: http://www.scriptarchive.com/
+
+To Do:
+
+* FormMail (http://www.scriptarchive.com/formmail.html)
+* Guestbook (http://www.scriptarchive.com/guestbook.html)
+* WWWBoard (http://www.scriptarchive.com/wwwboard.html)
+* Simple Search (http://www.scriptarchive.com/search.html)
+* Counter (http://www.scriptarchive.com/counter.html)
+* TextCounter (http://www.scriptarchive.com/textcounter.html)
+* Free for all Links (http://www.scriptarchive.com/links.html)
+* Random Link Generator (http://www.scriptarchive.com/rand_link.html)
+* HTTP Cookie Library (http://www.scriptarchive.com/cookielib.html)
+* SSI Random Image Displayer (http://www.scriptarchive.com/ssi_image.html)
+
+Done:
+
+* Countdown (http://www.scriptarchive.com/countdown.html)
+* Random Image Displayer (http://www.scriptarchive.com/rand_image.html)
+* Random Text (http://www.scriptarchive.com/rand_text.html)
+* TextClock (http://www.scriptarchive.com/textclock.html)
View
@@ -0,0 +1,64 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use 5.010;
+
+use Dancer;
+use DBI;
+use File::Spec;
+use FindBin;
+use Data::Dumper;
+
+my $dbh = init_db_connection();
+
+get '/' => sub {
+ my $count = increment_and_get_count($dbh);
+ return $count;
+};
+
+dance;
+
+#######################################
+
+sub init_db_connection {
+ # connect to the SQLite database
+ my $counter_db_file = File::Spec->catfile($FindBin::Bin, 'counter.db');
+ my $dbh = DBI->connect(
+ "dbi:SQLite:dbname=${counter_db_file}", # data source
+ "", # username
+ "", # password
+ { RaiseError => 1 }, # throw exceptions on failure
+ ) or die "Failed to connect to SQLite DB: $DBI::errstr";
+
+ # maybe initialize
+ maybe_initialize_db($dbh);
+
+ return $dbh;
+}
+
+sub maybe_initialize_db {
+ my $dbh = shift;
+
+ $dbh->do("CREATE TABLE IF NOT EXISTS Count(count INT DEFAULT 0);");
+
+ my $sth = $dbh->prepare("SELECT count FROM Count;");
+ $sth->execute();
+ if (!$sth->fetchrow()) {
+ $dbh->do("INSERT INTO Count VALUES(0)");
+ }
+
+ return;
+}
+
+sub increment_and_get_count {
+ my $dbh = shift;
+
+ $dbh->do("UPDATE Count SET count = count + 1;");
+
+ my $sth = $dbh->prepare("SELECT count FROM Count;");
+ $sth->execute();
+ my ($count) = $sth->fetchrow();
+
+ return $count;
+}