Index: /trunk/bin/bkmk
===================================================================
--- /trunk/bin/bkmk	(revision 103)
+++ /trunk/bin/bkmk	(revision 103)
@@ -0,0 +1,106 @@
+#!/usr/bin/perl -w
+use strict;
+
+use FindBin;
+use lib "$FindBin::RealBin/../lib";
+
+use YAML;
+use Getopt::Long;
+
+use Bookmarks;
+
+GetOptions(
+    'file|f=s' => \my $DBNAME,
+    'title=s' => \my $TITLE,
+);
+
+my $dbname = $DBNAME || $ENV{BKMK_DBNAME};
+die "Usage: $0 --file <dbname> <command>\n" unless $dbname;
+
+my $bookmarks = Bookmarks->new({
+    dbname => $dbname,
+});
+
+my $command = shift;
+
+my %action_for = (
+    init => sub {
+        my $src_file = shift;
+        $bookmarks->create_tables;
+        load_bookmarks($src_file) if $src_file;
+    },
+    
+    get => sub {
+        my $identifier = shift;
+        my $bookmark = find_bookmark($identifier);
+        print $bookmark ? Dump($bookmark->to_hashref) : "Not Found\n";
+    },
+    
+    add => sub {
+        my ($uri, @tags) = @_;
+        my $title = defined $TITLE ? $TITLE : fetch_title($uri);
+        my $bookmark = $bookmarks->add({ uri => $uri, title => $title, tags => \@tags });
+        print Dump($bookmark->to_hashref);
+    },
+
+    list => sub {
+        my @tags = @_;
+        my $resources = $bookmarks->search({
+            tags => \@tags
+        });
+        # TODO: list by tags, date, etc.
+        # TODO: coordinate this commandline script with the CGI app
+        print Dump([ map { $_->to_hashref } @{ $resources->results } ]);
+    },
+
+    tag => sub {
+        my ($identifier, @tags) = @_;
+        my $bookmark = find_bookmark($identifier);
+        if ($bookmark) {
+            $bookmark->tags(\@tags);
+            $bookmarks->update($bookmark);
+            print Dump($bookmark->to_hashref);
+        } else {
+            die "Not found\n";
+        }
+    },
+
+    #TODO: interactive editing of a bookmark
+
+    # bulk loading
+    load => sub {
+        my ($src_file) = @_;
+        load_bookmarks($src_file);
+    },
+
+    # bulk dumping
+    dump => sub {
+        my ($dump_file) = @_;
+        my $dump = [ map { $_->to_hashref } @{ $bookmarks->search->results } ];
+        $dump_file ? YAML::DumpFile($dump_file, $dump) : print Dump($dump);
+    },
+);
+
+$action_for{$command}->(@ARGV);
+
+sub find_bookmark {
+    my $identifier = shift;
+    my $query = $identifier =~ /^\d+$/ ? { id => $identifier } : { uri => $identifier };
+    return $bookmarks->get_bookmark($query);
+}
+
+sub fetch_title {
+    my $uri = shift;
+    require WWW::Mechanize;
+    my $mech = WWW::Mechanize->new;
+    $mech->get($uri);
+    return $mech->title || $uri;
+}
+
+sub load_bookmarks {
+    my $src_file = shift;
+    my $src_bookmarks = YAML::LoadFile($src_file);
+    for my $bookmark (@{ $src_bookmarks }) {
+        $bookmarks->add($bookmark);
+    }
+}
Index: /trunk/bin/bkmkd
===================================================================
--- /trunk/bin/bkmkd	(revision 103)
+++ /trunk/bin/bkmkd	(revision 103)
@@ -0,0 +1,60 @@
+#!/usr/bin/perl -w
+use strict;
+
+use FindBin;
+use lib "$FindBin::RealBin/../lib";
+
+use Getopt::Long;
+use YAML;
+use Plack::Runner;
+use File::Pid;
+use File::Spec::Functions qw{catfile};
+
+GetOptions(
+    'file=s' => \my $CONFIG_FILE,
+);
+
+$CONFIG_FILE ||= 'server.yml';
+-e $CONFIG_FILE or die "Config file $CONFIG_FILE not found\n";
+my $config = YAML::LoadFile($CONFIG_FILE);
+my $command = shift or die "Usage: $0 <start|stop>\n";
+
+my %run = (
+    start => sub {
+        my $config = shift;
+        require BookmarksApp;
+        my $app = BookmarksApp->new({ config => $config })->to_app;
+
+        my $server_root = $config->{server_root} || '.';
+        my $listen      = ':' . ($config->{port} || 5000);
+        my $access_log  = catfile($server_root, 'access');
+        my $error_log   = catfile($server_root, 'errors');
+        my $pid_file    = catfile($server_root, 'pid');
+
+        my $runner = Plack::Runner->new(server => 'Starman');
+        $runner->parse_options(
+            '--daemonize',
+            '--listen',     $listen,
+            '--pid',        $pid_file,
+            '--error-log',  $error_log,
+            '--access-log', $access_log,
+        );
+        $runner->run($app);
+    },
+
+    stop => sub {
+        my $config = shift;
+        my $server_root = $config->{server_root} || '.';
+
+        my $pid_file = File::Pid->new({
+                file => catfile($server_root, 'pid'),
+            });
+
+        if (my $pid = $pid_file->running) {
+            kill 'TERM', $pid;
+        }
+    },
+);
+
+exists $run{$command} or die "Unrecognized command $command\n";
+$run{$command}->($config);
Index: /trunk/bin/stop
===================================================================
--- /trunk/bin/stop	(revision 103)
+++ /trunk/bin/stop	(revision 103)
@@ -0,0 +1,28 @@
+#!/usr/bin/perl -w
+use strict;
+
+use FindBin;
+use lib "$FindBin::RealBin/../lib";
+
+use Getopt::Long;
+use YAML;
+use File::Pid;
+use File::Spec::Functions qw{catfile};
+
+GetOptions(
+    'file=s' => \my $CONFIG_FILE,
+);
+
+$CONFIG_FILE ||= 'server.yml';
+-e $CONFIG_FILE or die "Config file $CONFIG_FILE not found\n";
+my $config = YAML::LoadFile($CONFIG_FILE);
+
+my $server_root = $config->{server_root} || '.';
+
+my $pid_file = File::Pid->new({
+    file => catfile($server_root, 'pid'),
+});
+
+if (my $pid = $pid_file->running) {
+    kill 'TERM', $pid;
+}
Index: unk/bkmk
===================================================================
--- /trunk/bkmk	(revision 102)
+++ 	(revision )
@@ -1,106 +1,0 @@
-#!/usr/bin/perl -w
-use strict;
-
-use FindBin;
-use lib "$FindBin::RealBin/lib";
-
-use YAML;
-use Getopt::Long;
-
-use Bookmarks;
-
-GetOptions(
-    'file|f=s' => \my $DBNAME,
-    'title=s' => \my $TITLE,
-);
-
-my $dbname = $DBNAME || $ENV{BKMK_DBNAME};
-die "Usage: $0 --file <dbname> <command>\n" unless $dbname;
-
-my $bookmarks = Bookmarks->new({
-    dbname => $dbname,
-});
-
-my $command = shift;
-
-my %action_for = (
-    init => sub {
-        my $src_file = shift;
-        $bookmarks->create_tables;
-        load_bookmarks($src_file) if $src_file;
-    },
-    
-    get => sub {
-        my $identifier = shift;
-        my $bookmark = find_bookmark($identifier);
-        print $bookmark ? Dump($bookmark->to_hashref) : "Not Found\n";
-    },
-    
-    add => sub {
-        my ($uri, @tags) = @_;
-        my $title = defined $TITLE ? $TITLE : fetch_title($uri);
-        my $bookmark = $bookmarks->add({ uri => $uri, title => $title, tags => \@tags });
-        print Dump($bookmark->to_hashref);
-    },
-
-    list => sub {
-        my @tags = @_;
-        my $resources = $bookmarks->search({
-            tags => \@tags
-        });
-        # TODO: list by tags, date, etc.
-        # TODO: coordinate this commandline script with the CGI app
-        print Dump([ map { $_->to_hashref } @{ $resources->results } ]);
-    },
-
-    tag => sub {
-        my ($identifier, @tags) = @_;
-        my $bookmark = find_bookmark($identifier);
-        if ($bookmark) {
-            $bookmark->tags(\@tags);
-            $bookmarks->update($bookmark);
-            print Dump($bookmark->to_hashref);
-        } else {
-            die "Not found\n";
-        }
-    },
-
-    #TODO: interactive editing of a bookmark
-
-    # bulk loading
-    load => sub {
-        my ($src_file) = @_;
-        load_bookmarks($src_file);
-    },
-
-    # bulk dumping
-    dump => sub {
-        my ($dump_file) = @_;
-        my $dump = [ map { $_->to_hashref } @{ $bookmarks->search->results } ];
-        $dump_file ? YAML::DumpFile($dump_file, $dump) : print Dump($dump);
-    },
-);
-
-$action_for{$command}->(@ARGV);
-
-sub find_bookmark {
-    my $identifier = shift;
-    my $query = $identifier =~ /^\d+$/ ? { id => $identifier } : { uri => $identifier };
-    return $bookmarks->get_bookmark($query);
-}
-
-sub fetch_title {
-    my $uri = shift;
-    require WWW::Mechanize;
-    my $mech = WWW::Mechanize->new;
-    $mech->get($uri);
-    return $mech->title || $uri;
-}
-
-sub load_bookmarks {
-    my $src_file = shift;
-    my $src_bookmarks = YAML::LoadFile($src_file);
-    for my $bookmark (@{ $src_bookmarks }) {
-        $bookmarks->add($bookmark);
-    }
-}
Index: unk/start
===================================================================
--- /trunk/start	(revision 102)
+++ 	(revision )
@@ -1,36 +1,0 @@
-#!/usr/bin/perl -w
-use strict;
-
-use FindBin;
-use lib "$FindBin::RealBin/lib";
-
-use Getopt::Long;
-use YAML;
-use Plack::Runner;
-use BookmarksApp;
-use File::Spec::Functions qw{catfile};
-
-GetOptions(
-    'file=s' => \my $CONFIG_FILE,
-);
-
-$CONFIG_FILE ||= 'server.yml';
--e $CONFIG_FILE or die "Config file $CONFIG_FILE not found\n";
-my $config = YAML::LoadFile($CONFIG_FILE);
-my $app = BookmarksApp->new({ config => $config })->to_app;
-
-my $server_root = $config->{server_root} || '.';
-my $listen      = ':' . ($config->{port} || 5000);
-my $access_log  = catfile($server_root, 'access');
-my $error_log   = catfile($server_root, 'errors');
-my $pid_file    = catfile($server_root, 'pid');
-
-my $runner = Plack::Runner->new(server => 'Starman');
-$runner->parse_options(
-    '--daemonize',
-    '--listen',     $listen,
-    '--pid',        $pid_file,
-    '--error-log',  $error_log,
-    '--access-log', $access_log,
-);
-$runner->run($app);
Index: unk/stop
===================================================================
--- /trunk/stop	(revision 102)
+++ 	(revision )
@@ -1,28 +1,0 @@
-#!/usr/bin/perl -w
-use strict;
-
-use FindBin;
-use lib "$FindBin::RealBin/lib";
-
-use Getopt::Long;
-use YAML;
-use File::Pid;
-use File::Spec::Functions qw{catfile};
-
-GetOptions(
-    'file=s' => \my $CONFIG_FILE,
-);
-
-$CONFIG_FILE ||= 'server.yml';
--e $CONFIG_FILE or die "Config file $CONFIG_FILE not found\n";
-my $config = YAML::LoadFile($CONFIG_FILE);
-
-my $server_root = $config->{server_root} || '.';
-
-my $pid_file = File::Pid->new({
-    file => catfile($server_root, 'pid'),
-});
-
-if (my $pid = $pid_file->running) {
-    kill 'TERM', $pid;
-}
