in reply to Making a program for a gui future

If you are going to approach this properly then you I suggest that you need to consider the MVC or Model, View, Controller design. The functionality of your program can be split into these parts with a bit of thought and analysis.

The data your program operates on forms the model and provides methods to access, update and delete the information it contains. The controller is your main application. It provides all the glue logic for your app and also also looks after the interaction between the model and the views.

Finally, the view presents the user with their view of the program. However, your program can have as many of these as you like. Consider your program as having two views, command line and GUI. The underlying data and the basic logic is the same, the interaction with the user has changed.

In essence, you have decoupled your program model from your program display. The view then looks after the interaction between the user and the program, presents the info and makes calls (via the controller) to the model to get relevant data.

I suggest you look at the Observer pattern as a start point. Here (in very simplified terms) you can register objects to listen to events from another object. In context, you can register a view or views to listen to the model. When its state changes, it can notify the views. The view then grabs the info it requires and uses its own logic to display that to the user.

Hope that helps :)

Replies are listed 'Best First'.
Re: §Making a program for a gui future
by o(o_o)o (Scribe) on Mar 24, 2002 at 21:44 UTC

    Ah! I have been learning the Model, View, Controller design in my stupid Java lectures at Uni, but didn't know it was the same approach in Perl... are there premade Observer and Observable modules which can be <java speak>extended and implemented</java speak> in Perl, if there is, howcome i havn't heard much of them b4?

    simon.proctor++, you sound like a lecturer ;-) thanks for your help, it makes a lot of sence now!! Thanks.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    i would slit my wrists for you

      For posterity: I just uploaded Class::Observable which would likely be useful as infrastructure for this task.

      Chris
      M-x auto-bs-mode