Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-26 06:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found