| Inline-WSC documentation | view source | Contained in the Inline-WSC distribution. |
Inline::WSC - Use JavaScript and VBScript from within Perl
use Inline::WSC VBScript => <<'MyVBScript';
' Say hello:
Function Hello( ByVal Name )
Hello = "Hello, " & Name
End Function
' Handy method here:
Function AsCurrency( ByVal Amount )
AsCurrency = FormatCurrency( Amount )
End Function
MyVBScript
print Hello("John") . " gets " . AsCurrency( 100000 ) . "\n";
# You may also use the 'compile' method directly:
Inline::WSC->compile( JScript => q~
function greet( name ) {
return "Hello, " + name + "!";
}// end greet( name )
~);
print greet( 'John' ) . "\n";
Inline::WSC was originally intended to add a scriptable runtime to a larger
project.
Code fragments may be written in VBScript, JavaScript, JScript or PerlScript. PerlScript is only an option if you have installed the PerlScript COM extension that ships with ActiveState's ActivePerl distribution for Windows.
Inline::WSC creates a Windows Script Component (WSC) using the code you pass
it, and creates Perl stubs to access the methods in the WSC from the calling class.
Functions and subroutines defined within the code fragments are available within the caller's namespace.
Say you have the following VBScript:
Function ReturnsObject()
Dim obj : Set obj = CreateObject("Scripting.Dictionary")
obj.Add "Age", 28
obj.Add "Location", "Denver"
Set ReturnsObject = obj
End Function
If you called that function like so:
my $obj = ReturnsObject();
You could access its elements like any other Win32::OLE object:
print $obj->Item("Age");
print $obj->Item("Location");
Make sure all your methods have unique names.
If you pass Inline::WSC fragments of code that define the same
function/sub name more than once, you will get an error that looks like:
Method 'foo' was already defined in file 'InlineWin32COM.WSC_...wsc'
Methods defined in your Perl code are not available to the inlined code.
Inlined methods cannot call other inlined methods.
You can only pass strings and numbers to the inlined functions.
Do not use the words "sub" or "function" in the comments within your COM code. The regular expression used to parse out the function names is too simple and will result in errors that look like this:
Couldn't create OLE 'InlineWin32COM.WSC_...wsc': 317 at Inline/Win32COM.pm line xx.
http://msdn.microsoft.com/library/en-us/script56/html/c52b52d3-e11d-49f1-96c8-69b3c9ce8ade.asp
John Drago jdrago_999@yahoo.com
Copyright 2006 John Drago. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Inline-WSC documentation | view source | Contained in the Inline-WSC distribution. |