NAME
Win32::VBScript - Run Visual Basic programs
DESCRIPTION
This module allows you to invoke code fragments written in Visual Basic (or even JavaScript) from within a perl program. The Win32::OLE part has been copied from Inline::WSC.
SYNOPSIS
use strict;
use warnings;
use Win32::VBScript qw(:ini);
# the cscript/wscript/async methods come
# in two flavours: pl_... and ms_...
# **************************************
compile_prog_js ([ qq{WScript.StdOut.WriteLine("Test1");} ])->pl_cscript;
compile_prog_js ([ qq{WScript.StdOut.WriteLine("Test2");} ])->ms_cscript;
compile_prog_vbs([ qq{WScript.StdOut.WriteLine "Test3"} ])->pl_cscript;
compile_prog_vbs([ qq{WScript.StdOut.WriteLine "Test4"} ])->ms_cscript;
# And with wscript, of course, you can use MsgBox:
# ************************************************
compile_prog_vbs([ qq{MsgBox "Test5"} ])->pl_wscript;
compile_prog_vbs([ qq{MsgBox "Test6"} ])->ms_wscript;
# And you can have an asynchronous MsgBox as well:
# ************************************************
compile_prog_vbs([ qq{MsgBox "Test7"} ])->pl_async;
compile_prog_vbs([ qq{MsgBox "Test8"} ])->ms_async;
# You can even define functions in Visual Basic...
# ************************************************
my $t1 = compile_func_vbs([ <<'EOF' ]);
' Say hello:
Function Hello(ByVal Name)
Hello = ">> " & Name & " <<"
End Function
' Handy method here:
Function AsCurrency(ByVal Amount)
AsCurrency = FormatCurrency(Amount)
End Function
EOF
# ...or even JavaScript...
# ************************
my $t2 = compile_func_js([ <<'EOF' ]);
function greet(name) {
return "Greetings, " + name + "!";
} // end greet(name)
EOF
# ...and call the functions later in Perl:
# ****************************************
print 'Compiled functions are: (',
join(', ', map { "'$_'" }
sort { lc($a) cmp lc($b) } $t1->flist, $t2->flist),
')', "\n\n";
{
no strict 'refs';
*{'::hi'} = $t1->func('Hello');
*{'::cur'} = $t1->func('AsCurrency');
*{'::grt'} = $t2->func('greet');
}
print hi('John'), ' gets ', cur(100000), ' -> ', grt('Earthling'), "\n\n";
AUTHOR
Klaus Eichner <klaus03@gmail.com>
COPYRIGHT AND LICENSE
Copyright (C) 2016 by Klaus Eichner
All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the artistic license 2.0, see http://www.opensource.org/licenses/artistic-license-2.0.php