DSL Source Filter
Here's another attempt. skiphoppy has a point, but on second look, I noticed that (so far) you weren't asking much that was that complex. You just want to take each command and tell the remote server to do it. It's not perl that has to understand the commands, it's the server.
So, I remove some of my warnings about source filters, and decided to show you
how a simple one can be written. Again, what you're doing is not that complex, and my "filtering" below is quite easy.
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;
You would need to save this in RemoteAppScript.pm
somewhere where your perl can find it. ( try perl -MData::Dumper -e 'print Dumper( \@INC ), "\n"'
if you need to know where.)
Then you can create a "perl" file that has this:
use RemoteAppScript;
App.View2.Page2.Activate();
App.View1.Page2.Click();
However
There no real reason that you can't read a file that holds server commands. That would throw out the FILTER
call. You would have
App.View2.Page2.Activate();
App.View1.Page2.Click();
in your script file, and your perl file would look more like this:
#!/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 );
}
And call it like so:
perl run_remote_script.pl remote_app_script.ras