I have an old and very large Perl Tk GUI application that I'm refactoring to Tkx. I want to split the interface into several packages so I can build up the application UI in a modular manner. Also, I want to keep the View separate from the Model, using a Controller to provide an interface between the two.
It seems to me that the only way to design this is with two huge global variables, one holding the model ($MODEL), and the other holding references to the widgets ($UI) that are spread across many packages. Then, the Controller interfaces the two using a series of commands like the following:
$UI->{'entry_widget'}->configure(-variable=>\$MODEL->{'entry_value'});
$UI->{'button_widget'}->configure(-command=>sub {$MODEL->{'entry_value'} = "New Value"} );
My question is: Is there a better way to design the application which avoids having to use these two big globals ($UI and $MODEL)? Any suggestions would be very welcome.
I think package methods are a way to make something globally available, but not a global variable. So something like this, would work:
So outside the package, you would simply need to call this:
To get the controller associated to an object.
You could even put some export logic into the accessors, like:
So you could just simply do this: