spider/cmd/blank.pl

35 lines
588 B
Perl
Raw Normal View History

#
# Print n blank lines
#
# Copyright (c) 1998 Dirk Koopman G1TLH
#
#
#
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
2013-09-06 13:22:38 +00:00
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);
2001-09-14 23:03:57 +00:00
}