summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2012-10-11 21:12:41 +0200
committerJonas Smedegaard <dr@jones.dk>2012-10-11 21:12:41 +0200
commitc99b8f0ebc2b511d6279761adb773a8aa4d876ee (patch)
treeb0475dbb67415d836a2afdc02aabf6d53a1ab8da
parent846ec44317a52f347bfe0beb5a0d8af572631ffb (diff)
Convert to App::Cmd application.
-rwxr-xr-xbin/smsg4
-rw-r--r--lib/App/smsg.pm5
-rw-r--r--[-rwxr-xr-x]lib/App/smsg/Command/Talk.pm (renamed from smsbot)32
3 files changed, 33 insertions, 8 deletions
diff --git a/bin/smsg b/bin/smsg
new file mode 100755
index 0000000..6b3723d
--- /dev/null
+++ b/bin/smsg
@@ -0,0 +1,4 @@
+#!/usr/bin/env perl
+
+use App::smsg;
+App::smsg->run;
diff --git a/lib/App/smsg.pm b/lib/App/smsg.pm
new file mode 100644
index 0000000..38bfec1
--- /dev/null
+++ b/lib/App/smsg.pm
@@ -0,0 +1,5 @@
+package App::smsg;
+
+use App::Cmd::Setup -app;
+
+1;
diff --git a/smsbot b/lib/App/smsg/Command/Talk.pm
index f90ebc2..e31725b 100755..100644
--- a/smsbot
+++ b/lib/App/smsg/Command/Talk.pm
@@ -1,7 +1,10 @@
-#!/usr/bin/perl
+package App::smsg::Command::Talk;
+
use strict;
use utf8;
+use App::smsg -command;
+
use AnyEvent;
use AnyEvent::XMPP::Client;
use AnyEvent::XMPP::Ext::Disco;
@@ -12,10 +15,12 @@ use AnyEvent::XMPP::Util qw/node_jid res_jid/;
use NetSDS::Kannel;
#use Coro;
-use Getopt::Long::Descriptive;
+sub abstract { 'respond (stupidly simple) when addressed in a Jabber MUC' }
+
+sub usage_desc { '%c talk %o <jid> <password> <talkfile> [<room>]' }
-my ($opt, $usage) = describe_options(
- '%c %o <jid> <password> <talkfile> [<room>]',
+sub opt_spec {
+ return (
['kannelserver=s', "the Kannel server to connect to",
{default => 'localhost'}],
['kannelport=i', "the Kannel port to connect to",
@@ -28,12 +33,19 @@ my ($opt, $usage) = describe_options(
[],
# [ 'verbose|v', "print extra stuff"],
[ 'debug', "print debug stuff"],
- [ 'help', "print usage message and exit"],
-);
+ );
+}
-print($usage->text), exit if ($opt->help or @ARGV < 3);
+sub validate_args {
+ my ($self, $opt, $args) = @_;
-my ($jid, $pw, $inputfile, $room) = @ARGV;
+ $self->usage_error("too few arguments") unless @$args >= 3;
+}
+
+sub execute {
+ my ($self, $opt, $args) = @_;
+
+my ($jid, $pw, $inputfile, $room) = @$args;
# TODO: support overriding full URL
# TODO: use URI module to construct URL
@@ -130,6 +142,10 @@ $cl->start;
$j->wait;
+}
+
+1;
+
__END__
=head1 COPYRIGHT