-
Notifications
You must be signed in to change notification settings - Fork 0
API::Command
cooper879 edited this page Apr 24, 2011
·
6 revisions
Command.pm allows you to register user commands to juno. Each command is completely independent of any others and must handle the incoming data when a user uses it.
The register_command()
method registers a command to juno's user package. It can ONLY be called from within a module's init()
subroutine. The parameters are as follows:
- command
- description
- CODE reference
register_command('hello', 'Hello world!', \\&some_subroutine);
register_command()
can also take another optional hash reference argument for extended options. Valid options are listed below.
- params: the number of parameters that the command must have
- flag: the required oper flag to use the command
register_command('hello', 'Hello World!', \\&some_subroutine, { params => 2 });
# Valid: /HELLO Hello World!
# Invalid: /HELLO Hello
#!/usr/bin/perl
use warnings;
use strict;
use API::Module;
use API::Command;
register_module('HelloWorld', 0.1, 'Hello world!', \\&init, \\&void);
sub init {
register_command('hello', 'Hello world!', sub {
my ($user, $data) = @_;
$user->servernotice('Hello world!');
return 1
}) or return;
return 1
}
sub void {
print "Goodbye world!\n";
return 1
}