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
|
Line | |
---|
1 | #!/usr/bin/perl -w |
---|
2 | use strict; |
---|
3 | |
---|
4 | use DBI; |
---|
5 | use YAML; |
---|
6 | use Bookmarks; |
---|
7 | |
---|
8 | my $dbname = 'new.db'; |
---|
9 | |
---|
10 | my $dbh = DBI->connect("dbi:SQLite:dbname=$dbname", "", "", { RaiseError => 1, PrintError => 0 }); |
---|
11 | |
---|
12 | my $bookmarks = Bookmarks->new({ |
---|
13 | dbh => $dbh, |
---|
14 | }); |
---|
15 | |
---|
16 | my $command = shift; |
---|
17 | |
---|
18 | my %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 | }, |
---|
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 | } |
---|
37 | ); |
---|
38 | |
---|
39 | $action_for{$command}->(@ARGV); |
---|
40 | |
---|
41 | =begin |
---|
42 | |
---|
43 | use YAML; |
---|
44 | |
---|
Note: See
TracBrowser
for help on using the repository browser.