source: bookmarks/trunk/bkmk @ 14

Last change on this file since 14 was 14, checked in by peter, 12 years ago
  • added a basic "list" action to the bkmk script
  • Property svn:executable set to *
File size: 1012 bytes
RevLine 
[2]1#!/usr/bin/perl -w
2use strict;
3
4use DBI;
5use YAML;
6use Bookmarks;
7
8my $dbname = 'new.db';
9
10my $dbh = DBI->connect("dbi:SQLite:dbname=$dbname", "", "", { RaiseError => 1, PrintError => 0 });
11
12my $bookmarks = Bookmarks->new({
13    dbh => $dbh,
14});
15
16my $command = shift;
17
18my %action_for = (
19    get => sub {
20        my $identifier = shift;
21        my $query = $identifier =~ /^\d+$/ ? { id => $identifier } : { uri => $identifier };
22        my $bookmark = $bookmarks->get_bookmark($query);
23
24        print $bookmark ? Dump($bookmark) : "Not Found\n";
25    },
26    add => sub {
27        my ($uri, $title, @tags) = @_;
28        my $bookmark = $bookmarks->add({ uri => $uri, title => $title, tags => \@tags });
29        print Dump($bookmark);
30    },
[14]31    list => sub {
32        my @resources = $bookmarks->get_resources();
33        # TODO: list by tags, date, etc.
34        # TODO: coordinate this commandline script with the CGI app
35        print Dump(\@resources);
36    }
[2]37);
38
39$action_for{$command}->(@ARGV);
40
41=begin
42
43use YAML;
44
Note: See TracBrowser for help on using the repository browser.