added support for subroutines in commands
authorDirk Koopman <djk@tobit.co.uk>
Fri, 6 Sep 2013 13:22:38 +0000 (14:22 +0100)
committerDirk Koopman <djk@tobit.co.uk>
Fri, 6 Sep 2013 13:22:38 +0000 (14:22 +0100)
commitc675748ded5843f7bbd3819bb550f66b2534193a
treefb8d52f8e9f7332e56d4f914c7203ce697e50f2f
parentf67292b60a4b1567c0c370818fa2a7f0bc308fbc
added support for subroutines in commands

Traditionally, a command is a piece of perl that is a simple
in line lump of code e.g (blank.pl):

my ($self, $line) = @_;
my $lines = 1;
my $data = ' ';
my @f = split /\s+/, $line;
if (@f && $f[0] !~ /^\d+$/) {
$data = shift @f;
$data = $data x int(($self->width-1) / length($data));
$data .= substr $data, 0, int(($self->width-1) % length($data))
}
if (@f && $f[0] =~ /^\d+$/) {
$lines = shift @f;
$lines = 9 if $lines > 9;
$lines = 1 if $lines < 1;
}
my @out;
push @out, $data for (1..$lines);
return (1, @out);

It is now possible to have a 'handler' and any other code you like in
a command file, for instance (again blank.pl):

sub this {}

sub that {}

sub another {}

sub handle
{
my ($self, $line) = @_;
my $lines = 1;
my $data = ' ';
my @f = split /\s+/, $line;
if (@f && $f[0] !~ /^\d+$/) {
$data = shift @f;
$data = $data x int(($self->width-1) / length($data));
$data .= substr $data, 0, int(($self->width-1) % length($data))
}
if (@f && $f[0] =~ /^\d+$/) {
$lines = shift @f;
$lines = 9 if $lines > 9;
$lines = 1 if $lines < 1;
}
my @out;
push @out, $data for (1..$lines);
return (1, @out);
}

The 'sub handle' being the cue that distiguishes one form from the other.

The first form has the 'sub handle { <code> }' wrapped around it so, internally
they are treated the same. Each command is placed in its own DXCommandmode sub
package with a standard set of packages "use"d in front of it.

For now (at least) any functions you declare are just that. "$self" is a DXCommandmode
not a blessed reference to this command's full package name, you cannot use things like

$self->this() or $self->that()

they must be called as local functions.

This may change in the future.

Conflicts:

perl/DXChannel.pm
perl/Version.pm
cmd/blank.pl
perl/DXChannel.pm
perl/DXCommandmode.pm
perl/DXUtil.pm
perl/Sun.pm
perl/Version.pm