X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FScript.pm;h=24593aee92fa22e85b436a2efca7c134b467cdc3;hb=3196486ff0a78459e1b88b3847d255a62fd17895;hp=434109ceaf688b0f4966874014ce95a83d77a34e;hpb=ec57aa982f870daf09a1fc7839d06e52980cfb55;p=spider.git diff --git a/perl/Script.pm b/perl/Script.pm index 434109ce..24593aee 100644 --- a/perl/Script.pm +++ b/perl/Script.pm @@ -25,10 +25,17 @@ $main::branch += $BRANCH; my $base = "$main::root/scripts"; +sub clean +{ + my $s = shift; + $s =~ s/[^-\w\.]//g; + return $s; +} + sub new { my $pkg = shift; - my $script = shift; + my $script = clean(lc shift); my $fn = "$base/$script"; my $fh = new IO::File $fn; @@ -41,7 +48,7 @@ sub new } $fh->close; $self->{lines} = \@lines; - return $self; + return bless $self, $pkg; } sub run @@ -50,13 +57,47 @@ sub run my $dxchan = shift; foreach my $l (@{$self->{lines}}) { unless ($l =~ /^\s*\#/ || $l =~ /^\s*$/) { + $dxchan->inscript(1); my @out = DXCommandmode::run_cmd($dxchan, $l); + $dxchan->inscript(0); if ($dxchan->can('send_ans')) { $dxchan->send_ans(@out); } else { dbg($_) for @out; } - last if @out && $l =~ /^pri?v?/; + last if @out && $l =~ /^pri?v?/i; } } } + +sub store +{ + my $call = clean(lc shift); + my @out; + my $ref = ref $_[0] ? shift : \@_; + my $count; + my $fn = "$base/$call"; + + rename $fn, "$fn.o" if -e $fn; + my $f = IO::File->new(">$fn") || return undef; + for (@$ref) { + $f->print("$_\n"); + $count++; + } + $f->close; + unlink $fn unless $count; + return $count; +} + +sub lines +{ + my $self = shift; + return @{$self->{lines}}; +} + +sub erase +{ + my $call = clean(lc shift); + my $fn = "$base/$call"; + unlink $fn; +}