Permalink
Browse files

Merge pull request #2 from kaoru/master

Added TODO file
  • Loading branch information...
2 parents dee0954 + ffa884c commit 25c379f58a50008321024683c38e216d22cd71bd @davorg committed Aug 13, 2013
Showing with 85 additions and 0 deletions.
  1. +21 −0 TODO
  2. +64 −0 text_counter/counter.psgi
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;
+}

0 comments on commit 25c379f

Please sign in to comment.