Skip to content
cooper879 edited this page Apr 24, 2011 · 6 revisions

API::Command

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.

register_command()

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:

  1. command
  2. description
  3. 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

Example

#!/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
}
Clone this wiki locally