Inspired in the post made by Jason Brazile (http://jbrazile.blogspot.com.br/2008/03/siebel-com-programming-with-perl.html) I decided to get something more "Perlish" working example.
This is the first working testing that I got, basically the same example given by Jason with some interesting differences:
use strict;
use warnings;
use Siebel::COM::App::DataServer;
use feature 'say';
my $schema = {
'Contact' => [
'Birth Date',
'Created',
'Created By Name',
'Email Address',
'Fax Phone #',
'First Name',
'Id',
'Job Title',
'Last Name',
'Updated',
'Updated By Name',
'Work Phone #'
]
};
my $sa;
eval {
$sa = Siebel::COM::App::DataServer->new(
{
cfg => 'C:/Siebel/8.1/Client_1/BIN/ptb/scomm.cfg',
data_source => 'ServerDataSrcDEV',
user => 'foobar',
password => 'foobar'
}
);
my ( $bo, $bc, $key, $field, $moreResults );
$sa->login();
foreach $key ( keys(%$schema) ) {
$bo = $sa->get_bus_object($key);
$bc = $bo->get_bus_comp($key);
foreach $field ( @{ $schema->{$key} } ) {
$bc->activate_field($field);
}
$bc->clear_query();
$bc->query();
$moreResults = $bc->first_record();
while ($moreResults) {
printf("-----\n");
foreach $field ( @{ $schema->{$key} } ) {
printf( "%40s: %s\n", $field, $bc->get_field_value($field) );
}
$moreResults = $bc->next_record();
}
}
};
if ($@) {
warn $@;
die $sa->get_last_error() if ( defined($sa) );
}
You might be wondering "where is the heck of Win32::OLE?". Well, the beautiful of this script is the usage of the distribution Siebel::COM, freshly available at http://code.google.com/p/siebel-com/, which provides syntax sugar and automatic error checking by using basically only Moose.
Of course there is still a lot to implement, and the code available at the SVN doesn't have yet tests neither POD documentation. But it is a good start and I'm positive that this will be available at CPAN until the end of the month (although implementing mock objects in the tests will be a problem).