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

Hi dear Monks,

Can someone tell me how best to separate the GUI layer (TK) from the logic layer in perl?

Simply via modules? or are there better concepts?

Maybe someone has a link?

Thank you in advance.

Your brother

Replies are listed 'Best First'.
Re: Architecture GUI and Logic
by choroba (Cardinal) on Feb 28, 2018 at 11:58 UTC
    Check my PerlMonk ChatterBox GUI. All things GUI happen in the GUI.pm, all network goes through Communication.pm, and the logic is in Control.pm. Or, at least, that's how I designed the libraries.
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: Architecture GUI and Logic
by Discipulus (Canon) on Feb 28, 2018 at 11:50 UTC
    Hello MurciaNew,

    are just plain subs not enough?

    My most complicated Tk project has only 60 lines (plus some more that are repetitions..) of Tk logic on ca. 1200 lines.

    If you can use a sub to create repetitive parts of your gui all must flows simply.

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: Architecture GUI and Logic
by stevieb (Canon) on Feb 28, 2018 at 14:31 UTC

    What's your objective? To be able to install/use only a command line version, but also have the ability to "plug in" a UI if desired?

    Or is it a full blown GUI app and you just want the code separated for ease of readability and to make it easier to work on?

      I think it's the old MVC pattern, where the Tk "View" is replacing the HTML templates.

      Though I never understood how a template can include code logic if it's strictly restricted to the "C" part.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Wikisyntax for the Monastery

Re: Architecture GUI and Logic
by LanX (Saint) on Feb 28, 2018 at 20:12 UTC
    I googled "MVC Tk" and had some hits, mostly considering Python/Tkinter though.

    But as far as I can see you have to abstract the Tk logic into a class, should works pretty much the same way in Perl.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Wikisyntax for the Monastery