The API package in Perl

This is the BESAPI package that you can include with your own scripts:

# BESAPI.pm

package BESAPI;

use strict;
use Win32::OLE;

Win32::OLE->Option( Warn => sub { die Win32::OLE->LastError() . "\n"; } );

sub new
{
      my ( $perlType, $besAPIType, $server ) = @_;
   my $self = {};
      $self->{type} = $besAPIType;
      $self->{object} = Win32::OLE->new( "BESAPI." . $besAPIType );
      $self->{object}->SetServer( $server );
   return bless $self, $perlType;
}

our $AUTOLOAD;
sub AUTOLOAD
{
   my $self = shift;
      $AUTOLOAD =~ s/^.*:://;
      if ( $AUTOLOAD eq "DESTROY" )
            { return; }

      my $besAPIObject = $self->{object};
   my $result = $self->{object}->Invoke( $AUTOLOAD, @_ );
   if ( $besAPIObject->DiagnosticMessage() ) {
        die "BESAPI." . $self->{type} . "." . $AUTOLOAD . 
        " error: " . $self->{object}->DiagnosticMessage() . "\n";
   }

      return $result;
}

# included for use with versions prior to 8.2
sub CheckSigningKeys
{
      my ( $dsn, $username, $password, $privateKey ) = @_;
      my $signingKeys = BESAPI->new( "SigningKeys" );
      $signingKeys->SetDefaultDSN( $dsn );
      $signingKeys->SetPrivateKeyPath( $username, $privateKey );
      if ( !$signingKeys->AreSigningKeysValid( $username, $password ) )
            { die "SigningKeys not valid\n"; }
}

sub FixletMessage
{
      my ( $siteID, $FixletID, $username, $password, $server ) = @_;
      my $Fixlet = BESAPI->new( "FixletMessage", $server );
      $Fixlet->Load( $siteID, $FixletID, $username, $password );
      return $Fixlet;
}

1;