NAME

Inline::WSC - Use JavaScript and VBScript from within Perl

SYNOPSIS

  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";

DISCUSSION

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.

HOW IT WORKS

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.

RETURNING OBJECTS

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");

CAVEATS

Uniqueness of Function Names

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'

Perl Method Visibility

Methods defined in your Perl code are not available to the inlined code.

Inline-to-Inline Method Visibility

Inlined methods cannot call other inlined methods.

Parameter Lists

You can only pass strings and numbers to the inlined functions.

Reserved keywords

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.

SEE ALSO

  • Microsoft's Windows Script Component section on MSDN:

    http://msdn.microsoft.com/library/en-us/script56/html/c52b52d3-e11d-49f1-96c8-69b3c9ce8ade.asp

AUTHOR

John Drago jdrago_999@yahoo.com

COPYRIGHT AND LICENSE

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.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 240:

'=item' outside of any '=over'

Around line 244:

You forgot a '=back' before '=head1'