DSL 源过滤器
这是另一个尝试。skiphoppy 说得有道理,但再看一遍,我注意到(到目前为止)你并没有问太多复杂的问题。您只想获取每个命令并告诉远程服务器执行此操作。必须理解命令的不是perl,而是服务器。
因此,我删除了一些关于源过滤器的警告,并决定向您展示如何编写一个简单的过滤器。同样,您所做的并不那么复杂,我在下面的“过滤”非常简单。
package RemoteAppScript;
use Filter::Simple; # The basis of many a sane source filter
use Smart::Comments; # treat yourself and install this if you don't have
# it... or just comment it out.
# Simple test sub
sub send_command {
my $cmd = shift;
print qq(Command "$cmd" sent.\n);
return;
}
# The list of commands
my @script_list;
# The interface to Filter::Simple's method of source filters.
FILTER {
# Save $_, because Filter::Simple doesn't like you reading more than once.
my $mod = $_;
# v-- Here a Smart::Comment.
### $mod
# Allow for whole-line perl style comments in the script
$mod =~ s/^\s*#.*$//m;
# 1. Break the package up into commands by split
# 2. Trim the strings, if needed
# 3. lose the entries that are just blank strings.
@script_list
= grep { length }
map { s/^\s+|\s+$//g; $_ }
split /;/, $mod
;
### @script_list
# Replace the whole script with a command to run the steps.
$_ = __PACKAGE__ . '::run_script();';
# PBP.
return;
};
# Here is the sub that performs each action.
sub run_script {
### @script_list
foreach my $command ( @script_list ) {
#send_command( $command );
socket_object->send_command( $command );
}
}
1;
你需要把它保存RemoteAppScript.pm
在你的 perl 可以找到它的地方。(perl -MData::Dumper -e 'print Dumper( \@INC ), "\n"'
如果您需要知道在哪里,请尝试。)
然后你可以创建一个“perl”文件,其中包含:
use RemoteAppScript;
App.View2.Page2.Activate();
App.View1.Page2.Click();
然而
没有真正的理由不能读取包含服务器命令的文件。那会打断FILTER
电话。你将会拥有
App.View2.Page2.Activate();
App.View1.Page2.Click();
在你的脚本文件中,你的 perl 文件看起来更像这样:
#!/bin/perl -w
my $script = do {
local $/;
<ARGV>;
};
$script =~ s/^\s*#.*$//m;
foreach my $command (
grep { length() } map { s/^\s+|\s+$//g; $_ } split /;/, $script
) {
socket_object->send_command( $command );
}
并这样称呼它:
perl run_remote_script.pl remote_app_script.ras