Sunday, May 17, 2009

Adding a wxPerl GUI to the twitter script: part 4 - Putting it all together

Note: this article is part of a series.

Today I've finished version 1.0.0 of Nothing fancy, I just added the Net:Twitter part from the console version of to the existing User Interface. I can now post to or from a graphical interface Perl program. That's how cool I am.

New since version 0.0.2
I removed the event handling on EVT_TEXT_MAXLEN because I realized that I didn't need to display a message when I reached 140 characters. The fact that you cannot type anything after the limit is enough. Keeping the message would have been annoying in fact...

A "gentle" analysis from Perl::Critic made me change the way I was calling the open function.
open(LOGINFILE, $password_file)
open(my $logfile_handle, '<', $password_file)

- The LOGINFILE file handle is dangerous because as such, LOGINFILE is declared as a global. It could already be used as another file's handle.
- The '<' second argument indicates that the file is open in read-only mode. It is easier to see that than in the previous writing and it avoids bugs for file names starting with '<' or '>' (see the full explanation).

I also replaced the double quotes (") by single quotes (') everywhere variable interpolation was not needed.
Speaking about quotes, I removed those surrounding the identifiers of the hash elements.
Speaking about hashes, I really enjoy how flexible they can be used for structuring your data. Take for example the %login hash in $this->{login}. It lets me organize data as such:

%login = {
user_name => { twitter => " user name",
identica => "Identica user name"
password => { twitter => " password",
identica => "Identica password"
And I can add to the hash construct as I need it. Of course, if not documented, I can see that hashes contructed in this manner could get pretty tough to maintain.

What's next?
There are improvements to be made to the twit_GUI script, especially concerning the password handling. Today I have a hard-coded path inside the script which is very ugly. I am not proud of myself but the Perl Iron Man's deadline is arriving soon and I want to stay in the contest ;)
I will apply the finishing touch in a next post.

I am not sure if I should keep the POD comments. I was thinking about throwing it all inside an "About" menu item. Maybe I can display the POD info directly in a MessageBox, in a reentrant fashion.

I will not plaster the walls of this blog with yet another listing but as always you can find all script versions on the DamienLearnsPerl's companion site.


  1. You may like modulinos concept [1] and learn very easy Module::Install or another packaging system to make this all distributiable via CPAN [2].


  2. Thanks for the links Ruslan. Now I know what a modulino is :)