17 print STDERR
"$Odin::PROG: $m\n";
24 while (read STDIN
, my $buf, 8192) { $c .= $buf; }
25 return Odin
::tidy_pastebin_content decode locale
=> $c;
28 my $op = shift(@ARGV) // "help";
38 new [-l LANG] [-t TITLE]
40 update [-c] [-l LANG] [-t TITLE] TAG
42 } elsif ($op eq "list") {
43 @ARGV == 0 or Odin
::fail
"usage: list";
44 my $db = Odin
::open_db
;
45 for my $r (@
{$db->selectall_arrayref
46 ("SELECT " . Odin
::sql_timestamp
($db, "stamp") .
48 FROM odin_pastebin WHERE owner = ?
49 ORDER BY stamp", undef, $Odin::WHO
)}) {
50 my ($stamp, $tag, $lang, $title) = @
$r;
51 my $t = strftime
"%Y-%m-%d %H:%M:%S %z", localtime $stamp;
52 printf "%-25s %-12s %-16s %s\n",
53 $t, $tag, $lang, encode locale
=> $title;
55 } elsif ($op eq "new") {
57 getopts
"l:t:", \
%o and @ARGV == 0
58 or Odin
::fail
"usage: new [-l LANG] [-t TITLE]";
59 my %p = (title
=> decode
(locale
=> $o{t
}), lang
=> $o{l
} // "plain-text",
60 content
=> read_content
);
61 my $db = Odin
::open_db
;
63 while (read STDIN
, my $buf, 8192) { $c .= $buf; }
64 $p{content
} = read_content
;
65 @
{$db->selectall_arrayref
66 ("SELECT lang FROM odin_pastebin_lang WHERE lang = ?", undef, $p{lang
})}
67 or Odin
::fail
"unknown language `$p{lang}'";
68 my ($tag, $edit) = Odin
::new_pastebin
%p;
69 print "$Odin::PASTEBIN/$url $edit\n";
70 } elsif ($op eq "get") {
71 @ARGV == 1 or Odin
::fail
"usage: get TAG";
73 Odin
::get_pastebin Odin
::open_db
, $tag, my %p;
74 print encode locale
=> $p{content
};
75 } elsif ($op eq "claim") {
76 @ARGV == 2 or Odin
::fail
"usage: claim TAG EDITKEY";
77 my ($tag, $key) = @ARGV;
78 Odin
::claim_pastebin
$tag, $key;
79 } elsif ($op eq "rekey") {
80 @ARGV == 1 or Odin
::fail
"usage: rekey TAG";
82 my $key = Odin
::rekey_pastebin
$tag;
84 } elsif ($op eq "del") {
85 @ARGV or Odin
::fail
"usage: del TAG ...";
86 Odin
::delete_pastebin
map { $_, undef } @ARGV;
87 } elsif ($op eq "update") {
89 getopts
"cl:t:", \
%o and @ARGV == 1
90 or Odin
::fail
"usage: update [-c] [-l LANG] [-t TITLE] TAG";
92 my %p = (title
=> decode
(locale
=> $o{t
}), lang
=> $o{l
});
93 if ($o{c
}) { $p{content
} = read_content
; }
94 Odin
::update_pastebin
$tag, undef, %p or Odin
::fail
"nothing changed";
96 Odin
::fail
"unknown operation `$op'";