Add custom command support with new CustomCommands module
This commit is contained in:
parent
7807ee5ee3
commit
5d879616e8
2 changed files with 28 additions and 0 deletions
22
lib/CustomCommands.pm
Normal file
22
lib/CustomCommands.pm
Normal file
|
@ -0,0 +1,22 @@
|
|||
package CustomCommands;
|
||||
|
||||
our %COMMANDS = (
|
||||
# Example command:
|
||||
# 'hello' => sub { print "Hello, World!\n"; return 1; }
|
||||
'quit' => sub { exit; return 1; }
|
||||
);
|
||||
|
||||
sub handle {
|
||||
my ($command) = @_;
|
||||
|
||||
# Check if this is a custom command
|
||||
foreach my $cmd (keys %COMMANDS) {
|
||||
if ($command =~ /^$cmd\b/) {
|
||||
return $COMMANDS{$cmd}->($command);
|
||||
}
|
||||
}
|
||||
|
||||
return 0; # Not a custom command
|
||||
}
|
||||
|
||||
1;
|
Loading…
Add table
Add a link
Reference in a new issue