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.

In reply to OO circularity by wfsp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.