]> dxcluster.org Git - spider.git/commitdiff
add it!
authorminima <minima>
Fri, 14 Sep 2001 18:00:52 +0000 (18:00 +0000)
committerminima <minima>
Fri, 14 Sep 2001 18:00:52 +0000 (18:00 +0000)
perl/Script.pm [new file with mode: 0644]

diff --git a/perl/Script.pm b/perl/Script.pm
new file mode 100644 (file)
index 0000000..276aae5
--- /dev/null
@@ -0,0 +1,61 @@
+#
+# module to do startup script handling
+#
+# Copyright (c) 2001 Dirk Koopman G1TLH
+#
+# $Id$
+#
+
+package Script;
+
+use strict;
+
+use DXUtil;
+use DXDebug;
+use DXChannel;
+use DXCommandmode;
+use DXVars;
+use IO::File;
+
+use vars qw($VERSION $BRANCH);
+$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
+$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ ) || 0;
+$main::build += $VERSION;
+$main::branch += $BRANCH;
+
+my $base = "$main::root/scripts";
+
+sub new
+{
+       my $pkg = shift;
+       my $script = shift;
+       my $fn = "$base/$script";
+
+       my $fh = new IO::File $fn;
+       return undef unless $fh;
+       my $self = bless {call => $script}, $pkg;
+       my @lines;
+       while (<$fh>) {
+               chomp;
+               push @lines, $_;
+       }
+       $fh->close;
+       $self->{lines} = \@lines;
+       return $self;
+}
+
+sub run
+{
+       my $self = shift;
+       my $dxchan = shift;
+       foreach my $l (@{$self->{lines}}) {
+               unless ($l =~ /^\s*\#/ || $l =~ /^\s*$/) {
+                       my @out = DXCommandmode::run_cmd($dxchan, $l);
+                       if ($dxchan->can('send_ans')) {
+                               $dxchan->send_ans(@out);
+                       } else {
+                               dbg($_) for @out;
+                       }
+               }
+       }
+}