in reply to GUI Setup with Tk, overly verbose, or maintainable?

I think that your style of code is good for maintainability.

I like the use constant approach that keszler mentioned. There is a module that can do the counting for you; it is called enum::fields. You also have the opportunity to remove some redundancy from your array initializations.

sub guiStart { my ($client,$login) = @_; my $mw = MainWindow->new(-borderwidth => 30, -title => "Duplicates: ".$client); use enum::fields qw{ LIST DEL ADD DUP CHG EXIT }; my %layout; $layout{label} = [ 'List Available Data', 'Remove Data', 'Add Data', 'Identify Duplicates', 'Change Client', 'Exit Application', ]; $layout{callback} = [ \&listData, \&removeData, [\&addData,,$client,$login,$mw], \&identifyDuplicates, \&changeClient, \&exitApp, ]; for my $btn (LIST..EXIT) { $layout{frame}->[$btn] = $mw->Frame(); $layout{button}->[$btn] = $layout{frame}->[$btn] ->Button(-text => $layout{label}->[$btn], -width => 20, -command => $layout{callback}->[$btn]) ->pack(); $layout{frame}->[$btn]->pack(); } MainLoop; return; }
It should work perfectly the first time! - toma

Replies are listed 'Best First'.
Re^2: GUI Setup with Tk, overly verbose, or maintainable?
by Grygonos (Chaplain) on Jul 04, 2004 at 14:14 UTC

    Thanks, toma that's a neat module. Is there very much overhead involved with it? Is it fairly lightweight?

      You can read the source or invent benchmarks to decide how lightweight it is. I haven't looked at it much. The CAVEATS section of the enum::fields POD explains the module limitations. The author suggests that Class::Delegate may be a better module, but I don't understand the suggestion.

      It should work perfectly the first time! - toma