http://qs321.pair.com?node_id=524951

wfsp has asked for the wisdom of the Perl Monks concerning the following question:

Please excuse my terminology.

I've been working on a cut down mock up of an app.

At it's core is a Tk front end which calls and receives input from other methods/subs.

It's this circularity that has been giving me grief. In particular, I'm passing the Tk object to subs that need it which feels wrong somehow.

How would other monks approach this?

#!/usr/bin/perl # auto.pl use strict; use warnings; use Auto::GUI; use Auto::MakeArticle; my $auto = Auto::GUI->new; $auto->fire_up_front_end or die;
package Auto::GUI; use strict; use warnings; sub new { my $class = shift; my $self = {}; bless $self, $class; return $self; } sub fire_up_front_end{ my $self = shift; # display the gui # later... a button will call MakeArticle my $mk = Auto::MakeArticle->new; $mk->make($self); # pass the GUI object (?) } sub msg { # show progress/error messages my $self = shift; my $msg = shift; print "$msg\n"; } 1;
package Auto::MakeArticle; use strict; use warnings; sub new { my $class = shift; my $self = {}; bless $self, $class; return $self; } sub make{ my $self = shift; my $gui = shift; # GUI object # do stuff to make page my $msg = "message from MakePage"; $gui->msg($msg); } 1;
The output is as expected:
---------- Capture Output ---------- > "C:\Perl\bin\perl.exe" auto.pl message from MakePage > Terminated with exit code 0.