potyl's Journal http://use.perl.org/~potyl/journal/ potyl's use Perl Journal en-us use Perl; is Copyright 1998-2006, Chris Nandor. Stories, comments, journals, and other submissions posted on use Perl; are Copyright their respective owners. 2012-01-25T02:40:45+00:00 pudge pudge@perl.org Technology hourly 1 1970-01-01T00:00+00:00 potyl's Journal http://use.perl.org/images/topics/useperl.gif http://use.perl.org/~potyl/journal/ Pexeso game now on CPAN - Game::Pexeso http://use.perl.org/~potyl/journal/39796?from=rss <p>I've finally packaged the Pexeso game as a CPAN application: <a href="http://search.cpan.org/perldoc?pexeso">Game::Pexeso</a>. Now there are no excuses for not playing it! </p><p>The source code is available on github: <a href="http://github.com/potyl/pexeso">pexeso git repo</a>.</p><p>Remember that if you want your face to be in the game that you have to create a CPAN account!</p> potyl 2009-10-24T07:54:02+00:00 journal Declarations and Scope followup on Chromatic's post http://use.perl.org/~potyl/journal/39767?from=rss <p>Chromatic as a good post on <a href="http://www.modernperlbooks.com/mt/2009/10/from-novice-to-adept-declarations-and-scope.html">Declarations and Scope</a>. I'm glad to see that I'm not the only one that follows this best practice. Which by the way I was surprised to not see in Damian Conway's <a href="http://astore.amazon.com/bratperlmong-20/detail/0596001738">Perl Best Practices</a>. </p><p>What I find the most strange is that I get constantly asked why I'm wrapping all my scripts into functions and that I don't have just plain executable code from the beginning. One of my posts in StackOverflow raised a lot of critics just by following this simple best practice: <a href="http://stackoverflow.com/questions/1183876/what-are-the-best-practices-for-implementing-a-cli-tool-in-perl/1183970#1183970">Scope bashing</a>. </p><p>I think that all conscious perl programmers always employ <code>use strict;</code> and <code>use warnigns</code>. So I find that localizing all our code in scoped blocks (let it be a <code>do {};</code>, a function or even a simple code block <code>{}</code>) is just too practical to be overlooked. I don't think that doing this adds too much noise nor distractions to the original source code. Yet the benefits gain are huge!</p><p>Not only does this technique protects your variables from becoming global but it also helps when the code needs to be refactored. There's nothing more annoying that having a monolithic script without functions that can't be refactored easily because the code assumes each single variable to be a global!</p> potyl 2009-10-18T08:44:50+00:00 journal Enable/Disable touch pad http://use.perl.org/~potyl/journal/39711?from=rss <p>I use a <a href="http://www.amitbhawani.com/Images/macbook-Amit.jpg">MacBook</a> as my main computer. I work on that laptop and do all my random hacking on it as well. </p><p>What might seem odd is that I run Linux on that hardware. Installing Linux there and getting it to work properly requires a lot of work and sacrifice: the web cam doesn't work and the OS sees a single CPU. Otherwise all is working fine and if the proper software (<a href="http://github.com/xiangfu/mfc-daemon">fan control</a>) is installed the laptop won't overheat. I can even play an <a href="http://github.com/potyl/pexeso">OpenGL game in Perl</a>! </p><p>One thing that I have noticed since I work on this MacBook is how clumsy I can be while typing. I would always hit the huge track pad and destroy my own work! OS X has a feature to disable the touch pad when a mouse is plugged and I would like to have the same feature in Linux. I think that the next version of Gnome will have this feature, but I want something like that now. </p><p>Luckily in Linux we have all the tools to implement this. What's missing is something to put all the pieces together, something like a glue language. So I wrote a small Perl script that can toggle the touch pad for me: <a href="http://github.com/potyl/bin/blob/master/toggle-touchpad">toggle-touchpad</a>. I binded the script to a keyboard combination through my window's manager keybindings and I can now enable/disable the touch pad at will! </p><p>This script will only work if the synaptic touch pad is configured to use shared memory. This means that the following option has to be set in the synaptic's driver section of your X11 configuration file: </p><blockquote><div><p> <tt>Section "InputDevice"<br>&nbsp; &nbsp; &nbsp; &nbsp; Identifier&nbsp; &nbsp; &nbsp; "Synaptics Touchpad"<br>&nbsp; &nbsp; &nbsp; &nbsp; Driver&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "synaptics"<br>&nbsp; &nbsp; &nbsp; &nbsp; Option&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "SendCoreEvents"&nbsp; &nbsp; &nbsp; &nbsp; "true"<br>&nbsp; &nbsp; &nbsp; &nbsp; Option&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Device"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "/dev/psaux"<br>&nbsp; &nbsp; &nbsp; &nbsp; Option&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Protocol"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "auto-dev"<br>&nbsp; &nbsp; &nbsp; &nbsp; Option&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "HorizScrollDelta"&nbsp; &nbsp; &nbsp; "0"<br> <br>&nbsp; &nbsp; &nbsp; &nbsp; # Use shared memory<br>&nbsp; &nbsp; &nbsp; &nbsp; SHMConfig&nbsp; &nbsp; &nbsp; &nbsp;"On"<br>EndSection</tt></p></div> </blockquote><p>Once the driver is configured to use shared memory the touch pad settings can be modified at runtime without needing to restart the X server. The program <i>synclient</i> can be used for playing around with the touch pad's settings. Once that done disabling the touch pad is as simple as doing: </p><blockquote><div><p> <tt>synclient touchpadoff=1</tt></p></div> </blockquote><p>Voila!</p> potyl 2009-10-05T06:50:13+00:00 journal Log::Log4perl now supports %R http://use.perl.org/~potyl/journal/39688?from=rss <p> <a href="http://search.cpan.org/perldoc?Log::Log4perl">Log::Log4perl</a> 1.25 has been released and it has two interesting enhancements: </p><ul> <li>Color configuration and attribute support added to ScreenColoredLevels</li><li>Patternlayout now supports %R, which returns the time elapsed from the last logging event</li></ul><p>The first enhancement looks really nice but I didn't had the opportunity to try it yet. I really like to use the color appender yet I always found the default color choice a bit odd. I used to work around this by creating a custom profile for my terminal with colors that matched the Log4perl log levels and fixed them to my liking. It's a bit hackish but on the other hand not everyone has the same color tastes. </p><p>I can comment a bit more on the second addition to Log4perl: the format %R in Patternlayout. This format is very similar to %r which prints the time elapsed since the start of the program except that %R prints the time elapsed since the last event successful logged event. This is exactly the same functionality as <a href="http://search.cpan.org/perldoc?Log::Log4perl::Layout::PatternLayout::Elapsed">Log::Log4perl::Layout::PatternLayout::Elapsed</a> but now available out of the box with Log::Log4per!</p><p>I got used to employ %r in my console appender while developing scripts. This was nice as I could see the execution time of the program and find the program's hot spots as I developed. I have to agree that this doesn't replace a good profiler but you will be surprised of the results.</p><p>The problem with %r is that finding the time elapsed between two consecutive log events requires compute the time difference between each consecutive log event. This can be easily done with another Perl script that will parse the output and show the time elapsed between each log event. </p><p>While parsing the output of a program with another program works, specially in Linux/Unix where pipes are so easy to do, it still wasn't the right thing to do. That's why I wrote Log::Log4perl::Layout::PatternLayout::Elapsed a long time ago. This allowed me to use that same functionality but from all programs using Log4perl without requiring to pipe the output through another program.</p><p>I'm glad to see that the modification is now in Log4perl and that I will be able to use without this feature right straight from Log4perl! </p> potyl 2009-09-28T18:46:14+00:00 journal Finding uncovered XS functions in Perl bindings http://use.perl.org/~potyl/journal/39679?from=rss <p>As I've said in my previous posts. I have two CPAN modules that provide bindings for C libraries. </p><p>One thing that I have I realized while I was writing these bindings is that sometimes C functions pass under my eyes unnoticed and that I forget to provide bindings for them. This can happen for various reasons: </p><ul> <li>The C library failed/forgot to document some functions.</li><li>New functions are added without being announced during the development.</li></ul><p>I asked a few months a go on the <a href="http://mail.gnome.org/archives/gtk-perl-list/2009-July/msg00011.html">gtk-perl-list</a> on how to proceed in order to find the functions that are missing code coverage in the the XS module. I took the suggestions posted in the mailing list and made this script: <a href="http://github.com/potyl/bin/blob/master/xs-coverage">xs-coverage</a> </p><p>I've used this script with a couple of bindings and I was quite satisfied. On my bindings it did find C functions that where missing in the XS files. But this script did even more: it showed me C functions that shouldn't have been public in the first place and undocumented functions in the library! This script is really helping me to improve the code coverage of the bindings that I maintain. </p><p>Even though xs-coverage is written in Perl i doubt that it is portable as the program relies on the command <i>nm</i> for inspecting the<nobr> <wbr></nobr>.so files.Furthermore, so far my script this has been only tested in Linux and could probably only work there. I'm not even sure that the program will work with standard C libraries as I only tested it with Glib based libraries. Another drawback is that the program will not detect XS aliases. Although, <a href="http://search.cpan.org/~vpit/">Vincent Pit</a> suggested that I might be able to get around that bug by inspecting the functions from the XS module by loading it in the Perl script and walking the package's symbol table. </p><p>If you have some suggestions or feed back on the script please let me know or fork it and send patches.</p> potyl 2009-09-26T21:09:47+00:00 journal Writing Perl bindings for GObject based libraries http://use.perl.org/~potyl/journal/39674?from=rss <p>I have in CPAN two modules that provide Perl bindings over two existing C libraries: <a href="http://search.cpan.org/perldoc?Gtk2::Unique">Gtk2::Unique</a> and <a href="http://search.cpan.org/perldoc?Champlain">Champlain</a>. These two modules both wrap C libraries that use Glib's <a href="http://library.gnome.org/devel/gobject/stable/">GObject</a> framework. I don't want to go too much in the details of explaining how GObject works, so I will just keep it brief. What's important to know is that the library provides and object-oriented framework for C that's easy to map to other languages through bindings (Perl, Python, Java, C++, etc). It provides classes, interfaces, a generic type system, memory management for objects, signals and even inheritance. You might not know too much about GObjects but you might be using them indirectly as it is the basis for Gtk2 and the Gnome desktop. </p><p>GObject and Glib have already Perl bindings: <a href="http://search.cpan.org/perldoc?Glib">Glib</a>. The Perl module on it self doesn't look so impressive as other Perl modules in CPAN offer the same functionality, nevertheless the module is capital. What makes it so unique is that it provides all the basis for the GObject framework. All the hard work of providing a mapping between GObjects's data structures, runtime, memory management and type system to Perl is covered by Glib!</p><p>Thanks to Glib's bindings, writing Perl bindings for a GObject based library is very easy. Most of the time all that's involved is to provide a map file that describes the C data structures (<i>Objects</i>, <i>Interfaces</i>, ect), to map their C names with Perl package names, to provide the prototypes of the C functions to bind in the XS files and to write the unit tests of course. That's it! Perl's Glib module will take care of the rest as it provides the utilities for compiling and linking the C code for us. It really is that simple.</p><p>The GObject framework is still evolving and gets new features. One that's very promising is introspection. This means that in a near future writing Perl bindings for a GObject based library will be almost if not automatic. And this future might not be so far as some work has been already made in order to give us even easier wrappers: <a href="http://live.gnome.org/GTK2-Perl/Introspection">Introspection for GTK2-Perl</a>. </p> potyl 2009-09-24T18:27:37+00:00 journal Champlain is now using Clutter 1.0 http://use.perl.org/~potyl/journal/39650?from=rss <p>I finally had the chance to resume my work on the Perl bindings for libchamplain which had a major release 0.4. The major change in this new version is the port to <a href="http://search.cpan.org/perldoc?Clutter">Clutter</a> 1.0.</p><p>Clutter, for the ones that don't know what it is, is an open source toolkit for creating fast, visually rich, portable and animated graphical user interfaces (GUI); more information here: <a href="http://www.clutter-project.org/">clutter's home page</a>. The library is fast and portable because it uses OpenGL and allows the creation of powerful GUIs very easily. </p><p>The toolkit is used as the basis of the <a href="http://moblin.org/documentation/moblin-netbook-intro">moblin</a> platform, the next major version of Gnome (3.0) will require clutter and even phones start to have clutter installed (<a href="http://maemo.nokia.com/">Nokia N900</a>). There's no doubt that Clutter is here to stay. </p><p>Lately <a href="http://search.cpan.org/perldoc?SDL">SDL</a> has been having a lot of attention since it got revived. This is a good thing as having more toolkits is always welcomed. But I have a feeling that this new enthusiasm has eclipsed Clutter's 1.0 release at least in the Perl blogosphere. This is a pity as Clutter is starting to make its mark in the open source world and has plenty of extra neat addons: </p><ul> <li> <a href="http://gstreamer.freedesktop.org/">Gstreamer</a> (Multimedia toolkit)</li><li>Gtk (for embeding in existing GUIs)</li><li>Champlain (geographical maps)</li></ul><p>I decided to try to show case Clutter and I implemented the pexeso game. This version is a Perl variant of the familiar game written in Perl and for the Perl community. The game is available for download here: <a href="http://github.com/potyl/pexeso">pexeso in clutter</a>. I hope that you will appreciate it! </p> potyl 2009-09-19T21:34:09+00:00 journal Summer of 09 http://use.perl.org/~potyl/journal/39593?from=rss <p>The summer is almost over and I didn't realized it! This year was full of adventures and surprises.</p><p>It all started when I accepted a job at <a href="http://www.booking.com/">booking.com</a> and joined the team in June. New company, new town and new country! All while my wife stayed in Bratislava, pregnant with our first baby!</p><p>Then there where the many flights to Bratislava during the weekends. Luckily Sky Europe had a cheap Amsterdam/Vienna connection. I've said <i>had</i> because the company is no more as it died one week ago. Everyone saw this coming: flights started to be delayed, then flights where operated by other companies, afterward flights where redirected to Bratislava (that was actually nice for me) and then flights got canceled. </p><p>I didn't mind too much having my flights delayed of a couple of hours. Now that I have git, being disconnected is no longer a problem. This gives me a good way of passing my time: Open Source. Thanks to git I was still able to hack and to commit code from the airport while I was monitoring the next delay (yes flight schedules where that bad that delays where delayed). Once I arrived home all that I needed was to push my changes and voila!.</p><p>Not only did I get to fly to Bratislava I also managed to go to YAPC::EU 09. That's something that I wasn't expecting as I just joined Booking.com! Once more the flights where delayed and a lot, luckily I wasn't alone this time as daxim and pepl where in the same flight. This YAPC was great and I had the chance to see some old friends that you only get to meet from YAPC to YAPC. </p><p>Finally, I'm made it back to Bratislava last week. Just in time for assisting to the birth of our first baby! Laurita was born last Thursday and I'm now going to visit her and her mother to the hospital as often as possible. While the family is being monitored and recovering at the hospital daddy is working from home and still hacking during the weekend. I know that very soon my random hacking during the weekends and evenings will be postponed for a while, but it's going to be worth it! I'm looking forward to have my whole family back under one single roof. </p> potyl 2009-09-07T07:02:09+00:00 journal Perl movie player http://use.perl.org/~potyl/journal/39204?from=rss <p>A few months ago I was playing with <a href="http://gstreamer.freedesktop.org/">Gstreamer</a> and I wrote a small movie player in Perl 5 thanks to the <a href="http://search.cpan.org/perldoc?GStreamer">Gstreamer</a> bindings. </p><p>For those that aren't familiar with Gstreamer it consists of an open source multimedia framework. Gstreamer allows an application to play, stream and covert any kind of multi-media content. It is mainly used in the Gnome desktop for playing sounds and viewing movies. </p><p>If you are a bit curious play with the following movie player: </p><blockquote><div><p> <tt>#!/usr/bin/perl<br> <br>=head1 NAME<br> <br>gst-video-player.pl - Video player made in Perl<br> <br>=head1 SYNOPSIS<br> <br>gst-video-player.pl video<br> <br>Where I&lt;video&gt; is the URI to a video (file, http, etc).<br> <br>=head1 DESCRIPTION<br> <br>This program shows how to create a video player using Gtk2 and Gstreamer. This<br>player can handle all video formats supported by Gstreamer.<br> <br>=cut<br> <br>use strict;<br>use warnings;<br> <br>use Glib qw(TRUE FALSE filename_to_uri);<br>use GStreamer '-init';<br>use GStreamer::Interfaces;<br>use Gtk2 '-init';<br>use File::Spec;<br>use Cwd;<br> <br>exit main();<br> <br>sub main {<br>&nbsp; &nbsp; die "Usage: file\n" unless @ARGV;<br>&nbsp; &nbsp; my ($uri) = @ARGV;<br> <br>&nbsp; &nbsp; if ($uri =~ m,^[^:]+://,) {<br>&nbsp; &nbsp; &nbsp; &nbsp; # Nothing to do as the input is already an URI<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; elsif (! File::Spec-&gt;file_name_is_absolute($uri)) {<br>&nbsp; &nbsp; &nbsp; &nbsp; my $file = File::Spec-&gt;catfile(getcwd(), $uri);<br>&nbsp; &nbsp; &nbsp; &nbsp; $uri = filename_to_uri($file, undef);<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; else {<br>&nbsp; &nbsp; &nbsp; &nbsp; $uri = filename_to_uri($uri, undef);<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; print "Playing: $uri\n";<br> <br>&nbsp; &nbsp; # Create the main pipeline and GUI elements<br>&nbsp; &nbsp; my ($pipeline, $player, $sink) = create_pipeline();<br>&nbsp; &nbsp; my ($window, $canvas, $buttons) = create_widgets();<br> <br>&nbsp; &nbsp; $player-&gt;set(uri =&gt; $uri);<br> <br>&nbsp; &nbsp; # Buttons used to control the playback<br>&nbsp; &nbsp; add_button($buttons, 'gtk-media-play', sub {<br>&nbsp; &nbsp; &nbsp; &nbsp; $sink-&gt;set_xwindow_id($canvas-&gt;window-&gt;get_xid);<br>&nbsp; &nbsp; &nbsp; &nbsp; $pipeline-&gt;set_state('playing');<br>&nbsp; &nbsp; });<br> <br>&nbsp; &nbsp; add_button($buttons, 'gtk-media-stop', sub {<br>&nbsp; &nbsp; &nbsp; &nbsp; $pipeline-&gt;set_state('ready');<br>&nbsp; &nbsp; });<br> <br>&nbsp; &nbsp; # Run the program<br>&nbsp; &nbsp; Gtk2-&gt;main();<br> <br>&nbsp; &nbsp; # Cleanup<br>&nbsp; &nbsp; $pipeline-&gt;set_state('null');<br>&nbsp; &nbsp; return 0;<br>}<br> <br>sub create_pipeline {<br>&nbsp; &nbsp; my $pipeline = GStreamer::Pipeline-&gt;new('pipeline');<br> <br>&nbsp; &nbsp; # The pipeline elements<br>&nbsp; &nbsp; my ($player, $sink) = GStreamer::ElementFactory-&gt;make(<br>&nbsp; &nbsp; &nbsp; &nbsp; playbin&nbsp; &nbsp; &nbsp;=&gt; 'player',<br>&nbsp; &nbsp; &nbsp; &nbsp; xvimagesink =&gt; 'sink',<br>&nbsp; &nbsp; );<br> <br>&nbsp; &nbsp; $pipeline-&gt;add($player);<br>&nbsp; &nbsp; $player-&gt;link($sink);<br> <br>&nbsp; &nbsp; $player-&gt;set('video-sink', $sink);<br>&nbsp; &nbsp; $sink-&gt;set('force-aspect-ratio', TRUE);<br> <br>&nbsp; &nbsp; return ($pipeline, $player, $sink);<br>}<br> <br>sub create_widgets {<br>&nbsp; &nbsp; # Create the widgets<br>&nbsp; &nbsp; my $window = Gtk2::Window-&gt;new();<br>&nbsp; &nbsp; $window-&gt;set_title("Gst video test");<br> <br>&nbsp; &nbsp; # This is where the video will be displayed<br>&nbsp; &nbsp; my $canvas = Gtk2::DrawingArea-&gt;new();<br>&nbsp; &nbsp; $canvas-&gt;set_size_request(300, 150);<br> <br>&nbsp; &nbsp; my $vbox = Gtk2::VBox-&gt;new(FALSE, 0);<br>&nbsp; &nbsp; $vbox-&gt;pack_start($canvas, TRUE, TRUE, 0);<br> <br>&nbsp; &nbsp; # Prepare a box that will hold the playback controls<br>&nbsp; &nbsp; my $buttons = Gtk2::HButtonBox-&gt;new();<br>&nbsp; &nbsp; $vbox-&gt;pack_start($buttons, FALSE, TRUE, 0);<br> <br>&nbsp; &nbsp; $window-&gt;add($vbox);<br> <br>&nbsp; &nbsp; $window-&gt;signal_connect(destroy =&gt; sub {Gtk2-&gt;main_quit()});<br>&nbsp; &nbsp; $window-&gt;show_all();<br> <br>&nbsp; &nbsp; return ($window, $canvas, $buttons);<br>}<br> <br>sub add_button {<br>&nbsp; &nbsp; my ($box, $stock, $callback) = @_;<br>&nbsp; &nbsp; my $button = Gtk2::Button-&gt;new_from_stock($stock);<br>&nbsp; &nbsp; $button-&gt;signal_connect(clicked =&gt; $callback);<br>&nbsp; &nbsp; $box-&gt;add($button);<br>&nbsp; &nbsp; $button-&gt;show_all();<br>}</tt></p></div> </blockquote> potyl 2009-07-01T20:38:36+00:00 journal Asynchronous HTTP with Gtk http://use.perl.org/~potyl/journal/39183?from=rss <p>I wrote a small demo for <a href="http://search.cpan.org/perldoc?Champlain">Champlain</a> that shows how to query Flickr and to display thumbnails of geotagged pictures that are publicly available. I already had a demo script that downloads an image from an URL. So writing this new demo wasn't too difficult, yet buliding the basis for it (the HTTP download part) was tedious. </p><p>The basis of the HTTP protocol are quite simple. So simple in fact that a simple GET command can be easily issued by hand through telnet. But today we no longer communicate with HTTP 0.9 and the protocol has been greatly enhanced with proxy support, SSL, keep-alive, pipelining, web services (XML-RPC and SOAP) and so on. Writing an HTTP client from scratch is pure madness, specially when <a href="http://search.cpan.org/perldoc?LWP">LWP</a> does everything so easily.</p><p>So what's the problem if we already have a great HTTP client library in CPAN? The problem is that in a GUI all I/O has to be made asynchronously. For a GUI this is crucial, if I/O is <b>NOT</b> performed asynchronously then the GUI will simply freeze while it's waiting for the I/O to resume and stops responding to user input. As far as I know there's no easy way for performing asynchronous HTTP (or HTTPS) requests that integrate well with <a href="http://search.cpan.org/perldoc?Glib">Glib</a>'s main loop, at least in Perl 5.</p><p> <a href="http://projects.gnome.org/libchamplain/">Libchamplain</a> performs its HTTP requests through <a href="http://live.gnome.org/LibSoup">libsoup</a> which is fully integrated with Glib's main loop. Sadly, libsoup doesn't have bindings for Perl 5 yet. </p><p>I though of using <a href="http://search.cpan.org/perldoc?POE">POE</a> for this but it requires a whole rewrite of the application. With POE, the logic has to be written using the POE framework and the GUI is added latter as a different component. This makes the application no longer look like a Gtk2 application but more like a POE component that happens to have a GUI. </p><p>At the end I implemented a minimalist version of Libsoup in Perl 5 thanks to <a href="http://search.cpan.org/perldoc?Net::HTTP::NB">Net::HTTP::NB</a>. My implementation is far from ideal but it works well enough for the purpose of the demo.</p><p>Remember when I said that writing an HTTP client fro scratch was pure madness, well I speak from experience and keep in mind that most of my work is still using Net::HTTP::NB for everything that involves the protocol. First of all my asynchronous client is not even fully asynchronous! In my version, the HTTP request is written with blocking I/O and only the response is read asynchronously. I tried to implement some basic version of keep-alive, it works but it is probably not that optimal. My library doesn't even have proxy support and it doesn't even keep track of the different TCP connections that the clients do. </p><p>I'm really thinking of writing the bindings my self. Although libsoup's API is quite extensive as it provides an HTTP client/server library for GNOME and this makes the task more time consuming. If anyone else would be interested in having libsoup's binding let me know. If I see that there's a demand beside my own personal need for a demo I will start the project sooner than expected. </p> potyl 2009-06-28T09:29:15+00:00 journal Champlain/libchamplain marathon is over http://use.perl.org/~potyl/journal/39124?from=rss <p>The <a href="http://projects.gnome.org/libchamplain/">libchamplain</a> dev team was really busy this weekend trying to fix some last minute bugs and to complete all bindings (Python, Perl and C#). Today the new version of libchamplain (0.3.3) was released and the race against the clock is now over. </p><p> I've realized that I forgot a few minor changes and fully completed the bindings only today, after the official release. This is not too much of a problem as the Perl bindings are mainly published through CPAN. For most users the version bundled with libchamplain should be good enough to use. For the purist that want 100% of API coverage they will have to wait until their favorite CPAN mirror has received the new version of <a href="http://search.cpan.org/perldoc?Champlain">Champlain</a> (0.4). </p> potyl 2009-06-15T22:12:52+00:00 journal Glib closures http://use.perl.org/~potyl/journal/38997?from=rss <p> <a href="http://projects.gnome.org/libchamplain/">Libchamplain</a> had a major release a few weeks ago and it introduced a MapSourceFactory which allows map sources to be registered, instantiated and easily swapped. This is a great addition as all map sources are now created in the same way. Displaying a combo box with all maps available is truly simple now. </p><p>The factory also allows user code to provide their own map source and to register it with libchamplain. Which means that once the factory will be properly binded in Perl it would be possible to implement a MapSource in pure Perl! </p><p>I was anxious to get this new feature but it came at a price: the bindings have to support the passing of a Perl sub (CODEREF) and to execute it when a map source is implemented in Perl. While, Glib and Gtk2 are overloaded with CODEREFS (after all the signal systems is implemented through callbacks), I had no idea how to implement this. To make things worse the callback for creating a new MapSource had no arguments which made the task impossible. </p><p>I finally had the time to refactor libchamplain and to modify the C callback signature in order to accept an extra parameter. Exactly as all Glib and Gtk2 callbacks do. This made it possible for me to reuse Glib's mechanism for binding callbacks. Thus, now it possible to create a MapSource in Perl! </p><p> This was the last bit that was missing in the Perl bindings. Now Champlain.pm has a total coverage of all functions and variables defined in libchamplain. The code needs still to be cleaned up a little bit and some pieces need to be refactored. But at least and at last I have a working version. </p> potyl 2009-05-18T20:31:40+00:00 journal Plenty of new releases Gtk2:: goodies http://use.perl.org/~potyl/journal/38928?from=rss <p>This last month has been a busy period and I managed somehow to work on 3 Gtk2 based CPAN bundles: Champlain, Gtk2::Ex::Entry::Pango and a new module Gtk2::Unique.</p><p>In the past weeks someone was looking for the Perl bindings to <a href="http://live.gnome.org/LibUnique">libunique</a> (a library for writing single instance applications). The bindings didn't exist so I decided to write them as they can be quite useful and might end-up being used one day in Xacobeo.</p><p>This project took a little longer than I expected even though the C API is quite small (3 header files). I got delayed considerably because I'm still learning how to write proper GObject bindings. The important thing is that the module has been released and is now in CPAN <a href="http://search.cpan.org/perldoc?Gtk2::Unique">Gtk2::Unique</a> </p><p>In the meanwhile I also managed to release a new version of <a href="http://search.cpan.org/perldoc?Gtk2::Ex::Entry::Pango">Gtk2::Ex::Entry::Pango</a> which is backward compatible with all versions of Gtk2 that support Pango and most important behaves correctly when the text entry gains focus. Now when default Pango markup is used to display text when the widget is empty it will clear the default text when the focus is gained and restore it when focus is lost (if there's no text). This is similar to what Firefox's search bar is doing and apparently Windows Vista (I don't have it so I can't tell).</p><p> Lastly but not the least, <a href="http://blog.pierlux.com/2009/05/04/libchamplain-03-released/en/">libchamplain</a> had a major release (0.3). The number of improvements and additions is too long to be enumerated in this post. One thing is assured the library is getting better and better. This new version has a lot of API changes, this is for the best so bare with us. The bad thing is that the API changes where so numerous that the bindings are lagging behind. Don't worry it's just a question of time and the bindings will be ready soon. </p> potyl 2009-05-06T05:20:54+00:00 journal Xacobeo has a new contributor and supports HTML files http://use.perl.org/~potyl/journal/38797?from=rss <p> <a href="http://search.cpan.org/~daxim/">Daxim</a> requested to join Xacobeo and submitted some nice patches that greatly improve the build system. </p><p>Now that we are more than two with commit access to SVN I really wished that Google Code would provide support for Git. I know that other services such as github and gitorious exisit but none of them provides the extra goodies that Google Code has (a built-in bug tracker, a download section, wikified site, etc). </p><p>This release adds the ability to open HTML files with Xacobeo. Don't expect the HTML page to be rendered in Xacobeo; although this could be done with <a href="http://search.cpan.org/perldoc?Gtk2::WebKit">Gtk2::WebKit</a> or <a href="http://search.cpan.org/perldoc?Gtk2::MozEmbed">Gtk2::MozEmbed</a> it's just that I don't see where in the window I could add this extra widget. What this feature does is to display the proper HTML DOM. For the moment the HTML parser has to be requested through the command line and only applies to the first document. </p> potyl 2009-04-12T05:52:29+00:00 journal New release of Champlain http://use.perl.org/~potyl/journal/38686?from=rss <p>Yesterday I've released a new version of <a href="http://search.cpan.org/perldoc?Champlain">Champlain</a>. This release addresses two issues: better support for Gt2 and unit tests.</p><p>In the previous release I wasn't able to provide proper support for Gtk2. I'm quite new at packaging a Perl module for a glib (or gnome) library and I made a big mistake. <a href="http://www.emmanuelebassi.net/">Ebassi</a> came to my help and managed to fix my mess. Now the Gtk2 wrapper works as expected and without hacks. </p><p>This time the package has unit tests and covers most of the public API (some parts that will be disappearing soon where omitted). It took me longer than what I would expect for writing the tests because of many small bugs. Thus, the majority of the time was spent writing test cases isolating the bugs, fixing <a href="http://projects.gnome.org/libchamplain/">libchamplain</a> and logging bug reports. At the end this pays as libchamplain is becoming more robust and other bindings will also benefit of the bug fixes. </p><p>Not only did this project gave me the opportunity of learning on how to create a package from scratch for an glib library it also introduced me to git. I've still haven't managed to master this new tool. I truly see advantage of having a distributed version control system, but the learning curve is quite high. Furthermore, the error messages are not too helpful. Although, I got told that in the past they where worst!</p> potyl 2009-03-23T06:37:50+00:00 journal Perl bindings for libchamplain http://use.perl.org/~potyl/journal/38648?from=rss <p>In the past days I was writing the bindings for <a href="http://projects.gnome.org/libchamplain/">libchamplain</a> and the first release is now available on CPAN <a href="http://search.cpan.org/perldoc?Champlain">Champlain</a>.</p><p>So what's Champlain? It's a Clutter based canvas that supports numerous free map sources such as <a href="http://www.openstreetmap.org/">OpenStreetMap</a>, <a href="http://www.openaerialmap.org/">OpenArialMap</a> and <a href="http://www.maps-for-free.com/">Maps for free</a>. The canvas can also be embedded in any <a href="http://search.cpan.org/perldoc?Gtk2">Gtk2</a> application.</p><p>This is a first release so some bugs might be lurking around, although in all honesty there's barely any code in this bindings. At the moment the module is not well documented nor tested. I plan to address this in the following releases. I'm also waiting for libchamplain to freeze a bit more it's API.</p> potyl 2009-03-16T06:31:54+00:00 journal Release weekend http://use.perl.org/~potyl/journal/38485?from=rss <p> <a href="http://use.perl.org/~jozef">Jozef</a> brought me the big news today: <a href="http://www.debian.org/News/2009/20090214">Debian GNU/Linux 5.0 released</a> (<i>Lenny</i>). Congratulations to the Debian team. I'm looking forward for the next release. Don't forget to improve the <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=497038">speed of apt-file</a><nobr> <wbr></nobr>;) </p><p> Inspired by the majestic release of Debian, I was compelled to make a release of Xacobeo. This new release addresses a nasty bug: the application crashes when opening non XML files. It never occurred to me to open something else than an XML file (except for HTML). But an user did try it and reported the results (Segmentation Fault), it is now fixed.</p><p>This new release makes Xacobeo reentrant, that's right you can now read Xacobeo's source code with Xacobeo. Actually, this is misleading as nothing will be displayed as Xacobeo's source code is not a valid document. But at least Xacobeo will no longer crash. </p><p>Speaking about opening non XML files. This week at work a colleague wanted to edit an existing HTML file and to save the results so he came to ask me about XPath, which he doesn't know. I showed him how XPath worked and he was quite impressed by the technology. Of course I tried to display the HTML document with Xacobeo but the document wasn't valid and a big chunk was missing. I replaced a single <code>parse_file()</code> by <code>parse_html_file()</code> and Xacobeo could handle HTML! I have to give XML::LibXML and libxml2 all credit for this. Of course, Xacobeo doesn't support yet HTML but in a near future I'm planning to implement this. </p> potyl 2009-02-15T20:00:42+00:00 journal Xacobeo traducido dans votre jazik http://use.perl.org/~potyl/journal/38425?from=rss <p>I have a uploaded a developer's release of <a href="http://search.cpan.org/perldoc?Xacobeo">Xacobeo</a> (version 0.06_02) to CPAN. From now on the application is using i18n which means that it can be translated quite easily to different languages. I have included two translations to Spanish and French. I'm guessing that these translations will probably need to be revised as I don't know the exact XML terminology any other language then English</p><p>I was surprised by the number of Perl modules available in CPAN that provide i18n. Specially the ones that interface with GNU gettext. At the end it can get quite confusing when comes the moment of making a choice.</p><p>Another pitfall that I've seen is that there doesn't seem to be a proper way (a Perl way) for generating the<nobr> <wbr></nobr><i>.mo</i> files from the<nobr> <wbr></nobr><i>.po</i> files. I had to revert to invoke <i>msgfmt</i> from <i>Module::Build</i> which isn't too portable. </p> potyl 2009-02-07T16:16:04+00:00 journal Productive holiday season for Xacobeo http://use.perl.org/~potyl/journal/38215?from=rss <p> This holiday season was some how particular as I had no choice but to take a two week vacation. It was a mandatory top management decision for all company employees. This was a great opportunity for me to continue the development of Xacobeo, all of course, founded at my own expenses<nobr> <wbr></nobr>;) </p><p> So what's Xacobeo? It's a simple XPath visualizer (see CPAN <a href="http://search.cpan.org/dist/Xacobeo/">Xacobeo</a>). It started as a Perl script that allowed me to execute an arbitrary XPath query and to see the results in plain Gtk2 GUI. Of course the script was quite simple and had a lot of shortcomings, nevertheless it was quite useful for parsing XML or writing XSLT. </p><p> I once showed it to <a href="http://use.perl.org/~jozef/">Jozef</a> who introduced it to <a href="http://use.perl.org/~pepl/">Pepl</a>. They both convinced me to release the script to the public. At first I was reluctant because the script was far from being ready to be used widely. On the other hand I figured out that if two to users found it useful maybe it deserved a chance. </p><p> Since it's first public apparition in CPAN, Xacobeo had 4 major releases and a few development releases with each version adding new features or fixing some existing bugs. I have now merged the XS development branch and made it available through CPAN as a development release (version 0.05_XX). In my opinion this version makes the software more usable as the two slowest parts of the application are now written in XS and have been heavily profiled. This allows the Xacobeo to handle quite large documents in a reasonable time, thus making it ready for prime time. So if you want to give it a try, now is the right time! </p><p> In retrospective, releasing Xacobeo was a good thing as it has taught me a lot: </p><ul> <li>Configuring Perl's build scripts (Makefile.PL, Build.PL) for applications instead of modules</li><li>XS</li><li>The internals of Gtk2, XML::LibXML, gtk2 and libxml2</li><li> <a href="http://library.gnome.org/devel/pango/stable/PangoMarkupFormat.html">Pango markup</a> (see <a href="http://search.cpan.org/perldoc?Gtk2::Ex::Entry::Pango">Gtk2::Ex::Entry::Pango</a>)</li><li>How helpful the perl-XML and perl-Gtk2 mailing list are</li><li>Contributing a patches and bug reports to Gtk2, XML::LibXML and libxml2</li></ul><p> Of course the project is still young and more development will be needed. I hope that I will be able to publish new versions of the tool and to learn new things. </p><p> I wish you all a Happy New Year!</p> potyl 2009-01-04T09:36:42+00:00 journal From YAML to XML through a DTD http://use.perl.org/~potyl/journal/37618?from=rss <p>The <a href="http://bratislava.pm.org/">Bratislava PM</a> web site has now an RSS feed. This feed is currently generated from a custom made <a href="http://search.cpan.org/perldoc?YAML">YAML</a> file that's transformed to RSS thanks to <a href="http://search.cpan.org/perldoc?XML::RSS">XML::RSS</a>. This approach is simple and quite flexible but has some quirks.</p><p>First, it's almost impossible to verify that the format of the YAML file is following the default template without writing our own validation. For instance, if a feed entry is missing the title, the link or the date there's no built-in mechanism to inform us of this errors.</p><p>Secondly, the main content of each feed element is allowed to have HTML. In fact, all feed items that we have include HTML. Mixing HTML inside of a YAML file doesn't make the input file too nice since it has now two markup languages. Of course, one can argue that YAML Ain't Markup Language (tm), nevertheless it is weird to embed HTML in YAML.</p><p>Finally, converting YAML to XML seems strange. YAML is mainly used to provide data structures, configuration files or data serialization. Using it for content manipulation might be pushing it too far.</p><p>For this particular context XML seems more appropriated. Some of its advantages are that it's possible to validate through a DTD, an XML Schema or RELAX NG. HTML and XML can coexist without problems, specially if XHTML is used. And transforming an XML file into another an RSS feed can be <i>easily</i> done through XSLT.</p><p>Using XML as the input file provided some interesting advantages. First, thanks to a DTD not only can we validate each feed entry in the input file, but we can also validate the HTML that's embedded in the feed's description.</p><p>By using some clever XML and DTD hacks it's possible to create a custom made feed that can be validated without too much effort. Let's we assume that an RSS feed contains an events and that each event has: </p><ul> <li>title</li><li>link</li><li>description (can contain HTML)</li><li>subject</li><li>creator</li><li>date</li><li>id</li></ul><p>The following DTD describes and validates a feed input file:</p><blockquote><div><p> <tt>&lt;!ELEMENT ba:events&nbsp; &nbsp; &nbsp; (ba:event*)&gt;<br>&lt;!ATTLIST ba:events<br>&nbsp; &nbsp; xmlns:ba&nbsp; CDATA&nbsp; &nbsp;#FIXED "http://bratislava.pm.org/dtd/events-1.0.dtd"<br>&gt;<br> <br>&lt;!ELEMENT ba:event&nbsp; &nbsp; &nbsp; &nbsp;(ba:title, ba:link, ba:description, ba:subject, ba:creator, ba:date, ba:id)&gt;<br> <br>&lt;!ELEMENT ba:title&nbsp; &nbsp; &nbsp; &nbsp;(#PCDATA)&gt;<br>&lt;!ELEMENT ba:link&nbsp; &nbsp; &nbsp; &nbsp; (#PCDATA)&gt;<br>&lt;!ELEMENT ba:description (#PCDATA)&gt;<br>&lt;!ELEMENT ba:subject&nbsp; &nbsp; &nbsp;(#PCDATA)&gt;<br>&lt;!ELEMENT ba:creator&nbsp; &nbsp; &nbsp;(#PCDATA)&gt;<br>&lt;!ELEMENT ba:date&nbsp; &nbsp; &nbsp; &nbsp; (#PCDATA)&gt;<br>&lt;!ELEMENT ba:id&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (#PCDATA)&gt;</tt></p></div> </blockquote><p>Although this DTD can be used for simple feed elements it has a problem: it doesn't allow any HTML inside the element <i>ba:description</i>! Does defeating the purpose of replacing YAML by XML. But all is not lost as this can be easily fixed by importing the XHTML DTD within our DTD and by redefining the element <i>ba:description</i> in order to accept any HTML tag that a <i>div</i> accepts:</p><blockquote><div><p> <tt>&lt;!-- Import that XHTML DTD --&gt;<br>&lt;!ENTITY % xhtml PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;<br>%xhtml;<br> <br>&lt;!ELEMENT ba:events&nbsp; &nbsp; &nbsp; (ba:event*)&gt;<br>&lt;!ATTLIST ba:events<br>&nbsp; &nbsp; xmlns:ba&nbsp; CDATA&nbsp; &nbsp;#FIXED "http://bratislava.pm.org/dtd/events-1.0.dtd"<br>&gt;<br> <br>&lt;!ELEMENT ba:event&nbsp; &nbsp; &nbsp; &nbsp;(ba:title, ba:link, ba:description, ba:subject, ba:creator, ba:date, ba:id)&gt;<br> <br>&lt;!ELEMENT ba:title&nbsp; &nbsp; &nbsp; &nbsp;(#PCDATA)&gt;<br>&lt;!ELEMENT ba:link&nbsp; &nbsp; &nbsp; &nbsp; (#PCDATA)&gt;<br>&lt;!ELEMENT ba:subject&nbsp; &nbsp; &nbsp;(#PCDATA)&gt;<br>&lt;!ELEMENT ba:creator&nbsp; &nbsp; &nbsp;(#PCDATA)&gt;<br>&lt;!ELEMENT ba:date&nbsp; &nbsp; &nbsp; &nbsp; (#PCDATA)&gt;<br>&lt;!ELEMENT ba:id&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (#PCDATA)&gt;<br> <br>&lt;!-- The definiton of 'ba:description' is the same as a 'div' --&gt;<br>&lt;!ELEMENT ba:description %Flow;&gt;<br>&lt;!ATTLIST ba:description<br>&nbsp; &nbsp; xmlns&nbsp; &nbsp; &nbsp;CDATA&nbsp; &nbsp;#FIXED&nbsp; "http://www.w3.org/1999/xhtml"<br>&gt;</tt></p></div> </blockquote><p>Thanks to this new DTD the element <i>ba:description</i> can include any HTML element that's allowed within a <i>div</i> element. The DTD will make the validation and will ensure that valid HTML is inside the element. For instance, adding the element <i>body</i> to the element <i>ba:description</i> will be rejected by the DTD even though it's a valid HTML element it's not allowed to be within a <i>div</i>. </p><p>The element <i>ba:description</i> is declared in our DTD the same way that the element <i>div</i> is in the XHTML DTD. Furthermore, the element is allowed to set the default namespace to XHTML. Thus, making all child elements of <i>ba:description</i> to belong to the XHTML elements, this is very handy when processing the XML file latter on.</p><p>It's is not difficult to see that the new version of the feed will be generated from an XML file as using XML is quite advantageous here.</p> potyl 2008-10-07T21:39:10+00:00 journal