X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;ds=inline;f=perl%2FScript.pm;fp=perl%2FScript.pm;h=8fdd806496c34df3c684abad02b98b46326fb6d7;hb=fe4f4e3751da3786d25df2fe2fba104523de095d;hp=3128dcde6486021bdce8ef15379f70f505108873;hpb=168689554677c7f1480d6f1161ee371e12548e6b;p=spider.git diff --git a/perl/Script.pm b/perl/Script.pm index 3128dcde..8fdd8064 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 @@ -60,3 +67,35 @@ sub run } } } + +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; +}