#!/Perl
#!/Perl
# 
use strict;
use Cwd;
use Win32::OLE qw(EVENTS);
###use Win32::OLE qw(in with);

# from : http://www.perl.com/pub/a/2005/04/21/win32ole.html
my $IEObject;

print "Hello, World...\n";

my $URL = "http://samie.sf.net/simpleform.html";

my $IE  = Win32::OLE->new("InternetExplorer.Application")
    || die "Could not start Internet Explorer.Application\n";

Win32::OLE->WithEvents($IE,\&Event,"DWebBrowserEvents2");

$IE->{visible} = 1;

$IE->Navigate($URL);

Win32::OLE->MessageLoop();

print "Out of message loop ... set edit box ...\n";

SetEditBox("name","samie");

exit 0;

######################################################################
### services
############

sub Event {
    my ($Obj,$Event,@Args) = @_;
    print "Here is the Event: $Event\n";
    if ($Event eq "DocumentComplete") {
        $IEObject = shift @Args;
        print "Here is my reference: $IEObject\n";
        print "URL: " .  $IEObject->Document->URL . "\n";
		print "Quitting message loop ...\n";
		Win32::OLE->QuitMessageLoop();
    }
}

sub SetEditBox {
    my ($name, $value) = @_;
    my $IEDocument     = $IEObject->{Document};
    my $forms          = $IEDocument->forms;

    for (my $i = 0; $i < $forms->length; $i++) {
        my $form       = $forms->item($i);
        if (defined($form->elements($name))) {
           $form->elements($name)->{value} = $value;
        }
        return;
    }
}

# autoie01.pl
