Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #2 from kaoru/master

Added TODO file
  • Loading branch information...
commit 25c379f58a50008321024683c38e216d22cd71bd 2 parents dee0954 + ffa884c
Dave Cross authored August 13, 2013
21  TODO
... ...
@@ -0,0 +1,21 @@
  1
+From: http://www.scriptarchive.com/
  2
+
  3
+To Do:
  4
+
  5
+* FormMail (http://www.scriptarchive.com/formmail.html)
  6
+* Guestbook (http://www.scriptarchive.com/guestbook.html)
  7
+* WWWBoard (http://www.scriptarchive.com/wwwboard.html)
  8
+* Simple Search (http://www.scriptarchive.com/search.html)
  9
+* Counter (http://www.scriptarchive.com/counter.html)
  10
+* TextCounter (http://www.scriptarchive.com/textcounter.html)
  11
+* Free for all Links (http://www.scriptarchive.com/links.html)
  12
+* Random Link Generator (http://www.scriptarchive.com/rand_link.html)
  13
+* HTTP Cookie Library (http://www.scriptarchive.com/cookielib.html)
  14
+* SSI Random Image Displayer (http://www.scriptarchive.com/ssi_image.html)
  15
+
  16
+Done:
  17
+
  18
+* Countdown (http://www.scriptarchive.com/countdown.html)
  19
+* Random Image Displayer (http://www.scriptarchive.com/rand_image.html)
  20
+* Random Text (http://www.scriptarchive.com/rand_text.html)
  21
+* TextClock (http://www.scriptarchive.com/textclock.html)
64  text_counter/counter.psgi
... ...
@@ -0,0 +1,64 @@
  1
+#!/usr/bin/perl
  2
+
  3
+use strict;
  4
+use warnings;
  5
+use 5.010;
  6
+
  7
+use Dancer;
  8
+use DBI;
  9
+use File::Spec;
  10
+use FindBin;
  11
+use Data::Dumper;
  12
+
  13
+my $dbh = init_db_connection();
  14
+
  15
+get '/' => sub {
  16
+    my $count = increment_and_get_count($dbh);
  17
+    return $count;
  18
+};
  19
+
  20
+dance;
  21
+
  22
+#######################################
  23
+
  24
+sub init_db_connection {
  25
+    # connect to the SQLite database
  26
+    my $counter_db_file = File::Spec->catfile($FindBin::Bin, 'counter.db');
  27
+    my $dbh = DBI->connect(
  28
+        "dbi:SQLite:dbname=${counter_db_file}", # data source
  29
+        "",                                     # username
  30
+        "",                                     # password
  31
+        { RaiseError => 1 },                    # throw exceptions on failure
  32
+    ) or die "Failed to connect to SQLite DB: $DBI::errstr";
  33
+
  34
+    # maybe initialize
  35
+    maybe_initialize_db($dbh);
  36
+
  37
+    return $dbh;
  38
+}
  39
+
  40
+sub maybe_initialize_db {
  41
+    my $dbh = shift;
  42
+
  43
+    $dbh->do("CREATE TABLE IF NOT EXISTS Count(count INT DEFAULT 0);");
  44
+
  45
+    my $sth = $dbh->prepare("SELECT count FROM Count;");
  46
+    $sth->execute();
  47
+    if (!$sth->fetchrow()) {
  48
+        $dbh->do("INSERT INTO Count VALUES(0)");
  49
+    }
  50
+
  51
+    return;
  52
+}
  53
+
  54
+sub increment_and_get_count {
  55
+    my $dbh = shift;
  56
+
  57
+    $dbh->do("UPDATE Count SET count = count + 1;");
  58
+
  59
+    my $sth = $dbh->prepare("SELECT count FROM Count;");
  60
+    $sth->execute();
  61
+    my ($count) = $sth->fetchrow();
  62
+
  63
+    return $count;
  64
+}

0 notes on commit 25c379f

Please sign in to comment.
Something went wrong with that request. Please try again.