How do I pick up existing objects in event handling code?

G

Graham Wood

I've written an FTP client using the GUI Loft and Net::FTP. I've
managed to get the program to work by scoping the $ftp object with "our"
but I don't think this is how you are supposed to do it.

Here's an artist's impression of what I'm doing now:

our $ftp= Net::FTP->new("hostname")|| die "Can't create FTP object";

sub ::btnChdir_Click{
our $ftp;
# get $path from value in a text box
$ftp->cwd("$path");
}

sub ::btnOK_Click{
our $ftp;
$ftp->put("$file");
}

sub ::btnDisconnect_Click{
our $ftp;
$ftp->quit();
}

I know that I could pass the $ftp object as an argument to subroutines
if I were calling them from my script but in this event driven model,
how do I elegantly pick up the value of the existing ftp object without
letting it all hang out in this unseemly fashion?

I notice that the gui $win object is picked up with code like this:

defined(my $win = $Win32::GUI::Loft::window(winCopyFiles})
or return (1);

Can I do something similar with Net::FTP objects like
defined(my $ftp = $Net::FTP);

Any hints gratefully accepted.

Thanks

Graham
 
J

Johan Lindstrom

Graham Wood said:
I notice that the gui $win object is picked up with code like this:

defined(my $win = $Win32::GUI::Loft::window(winCopyFiles})
or return (1);

Can I do something similar with Net::FTP objects like
defined(my $ftp = $Net::FTP);

Yes, you can attach an object to the Win32::GUI::Loft::Design object
you created when loading the design from the .gld file. The property
is called objApp:

Some user-defined object, normally used to connect a
application object responsible for this window.

So if you assign your FTP object (or any object) to the Design like
this (untested code):

my $objDesign = Win32::GUI::Loft::Design->newLoad($fileWindow); #or
die
$objDesign->objApp($ftp);

then you can get it out of the object in the event handlers like this:

my ($win, $design, $ftp) = tglApp('yourWindowName) or die;

Something like that.


I happened to stumble across this post by accident. There is a support
mailing list at the TGL site which I at least read a bit more often:
http://www.bahnhof.se/~johanl/perl/Loft/


/J
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top