Category: Perl

The Moose Slippery – February PR Challenge

Moose Slippery

This February my Pull Request assignment on the CPAN Pull Request Challenge was Ovid’s Module, MooseX::Role::Strict. For me this was a big problem. First because it is about Moose (which I do not use) and then because it is about the Meta-Moose, the way Moose itself behaves.

The idea of the module is to allow Role users to import a role that defines a method that is already defined in the current package/object in a strict fashion. If the user declares that method will be overridden, it will work, if it doesn’t, then an exception will be raised.

It was great to notice Ovid maintains a TODO list. It is not very clear what each item means, but I tried to ask him and understand. And as far as I could find, the first item of the TODO list seemed easy to implement. In fact,  too easy. This Pull Request, as far as I can tell, could do the trick. But I lack knowledge on creating a test case.

So, in order to close this month’s assignment, I am asking for comments, suggestions and any kind of constructive help on testing and fixing this pull request.

PR-Challenge: January 1st PR

Cross Posted from my Perl Blogs blog.

So, yeah, to make me more active in the Perl community I decided to join the Pull Request Challenge. I have a quite big number of modules to maintain, but sometimes it is good to look to some other people code to learn something.

My attribution for January was Data::ObjectDriver. I am not sure, yet, what this module is about, but I learned some stuff already, dealing with Module::Install. That was enough for a simple Pull Request [see here]. Hopefully it will be useful for other people as well. Also, hope it gets accepted.

Although this is enough for the Challenge, I expect, in the next days, to prepare at least one more Pull Request. So, stay tuned.

EDIT: The second pull request [here] did not take that much time. Fixed a test that was failing given new error message on DBD::SQLite.

Dotcloud and Perl Versions

Today I waste all my afternoon trying to solve a problem with Perl versions and DotCloud. I say I wasted the afternoon because I could not solve the issue during the afternoon, only in the beginning of the night.

Enough complain, and let me explain what was going on. Yes, this post is a little as a complain to the DotCloud tech guys, but also as a guide to someone that stumble in a similar situation.

I had a service running with Dancer. It worked, it connected perfectly to the database. Next step was to set up a cron job to fetch some data from the Web. I added its dependencies in the Makefile.PL file for the website, and hoped that the deploy system would install them. But the cron job continued failing. I tried to force its installation, but the deploy system said it was up to date. Something wrong was going on. I forced a little more the installation, adding the URL to the module tarball. This way the deploy system could not guess its version, and therefore, would install the module anyway. It worked, but the deploy system continued complaining about other and other module.

It got stranger when the cron job complained about the lack of the DBI module. Hey, how can it be, if the website is running and using it? Well, DBI is based on C code, so probably I am missing to include a sub-folder of the local module installation. And then, it got clearer: the cron job complained that the version of DBI.so could not be loaded into Perl because of unresolved symbols. Aha! Then, there are two Perl versions.

And indeed, the web application was running Perl 5.14.x (I requested it on my DotCloud configuration file) and the Perl used by the cron job was Perl 5.10.x. Basically, DotCloud folks keep the system Perl, and install custom Perl versions under /opt/perl5, and creates some symlinks there, so that /opt/perl5/perls/current points to the Perl version requested.

So, the solution is to make the cron job use the correct Perl version. In my case I set the full path, but you could change the PATH environment variable in your .bashrc-like file.

This wasn’t that hard, but it was quite time consuming, because deploys take some time. Probably I could get faster if I remembered to test Perl versions right ahead, but I forgot to.

I suggest DotCloud guys to do one of two things: or document this in the same doc where it is explained how to request a specific Perl version, or fix the damn environment so that cron jobs and other code uses the same Perl version as the one requested by the system.

Nine tools I can’t live without (for Windows)

First, a relevant disclaimer: I use Windows mostly for two purposes, test my Perl modules under a Windows environment, and printing some stuff as my Mac sometimes can’t find some Windows printers in the network. This said, my Windows runs in a virtual machine, and I install these tools right after installing Windows.

Browser

The first thing you need to know is that Windows does not include a web browser. It includes a tool that is mainly used to download a Web browser. Its name is Internet Explorer, and you can use it to download Firefox, Google Chrome, Safari or Opera. In my main machine, I use Firefox. There are some features that I like that are not available on other browsers. But for my virtual machine I need a tool to check my mail, and to download some other tools. Not much more.

Antivirus

Now I am cheating. In my virtual machine I do not have an antivirus installed. It is too easy to reinstall a new virtual machine, and you all know that an antivirus running is wasting some resources that can be relevant for virtual machines. Nevertheless, I want to suggest two antivirus. In fact, I suggest these two because they are the two I install when I need one (note that I do not install both, I install one or other). I am not sure what is the best. Avira seems to be lighter, AVG seems to be more professional and heavy.

Both these antivirus software have their professional paid version. This means that if you like their performance, you can buy the paid version for better protection. They also include some functionality that are common on current antivirus software, like trojan detection and web site security.

 

Connectivity

I need to transfer files to and from my Mac and/or Linux servers to the Windows machine. For that I can make the file available to download, or I can use a tool to copy files. As FTP is not that secure, the best approach is to use SCP or Secure Copy. For that, I suggest WinSCP tool. It also support FTP, but its main strength is the ability to use the SSH protocol.

A similar necessity raises when I need to connect to a Linux server from Windows. Again, I do not need this when using a virtual machine, as I can use a terminal from the host machine to ssh anywhere I want. But if you have a dual boot machine, or you just work on windows, then you will need this. Putty is the better telnet/ssh client I ever seen for Windows. It not only supports ssh, but it also supports ssh keys, making your connection even more secure.

Version Control

My main repository of code is still a SubVersion one. I am now using GitHub a lot, too, but my main tools are still in the old SVN repository. To checkout and commit from Windows I use TortoiseSVN. Not only because it has a nice and cute logo, but because it integrates perfectly in Explorer. Also, I love a recent feature, where TortoiseSVN commit message window auto-completes your commit messages with the filenames or contents of the modified files. Very cool.

Text Editor

I do not use that much Windows to have a dedicated IDE. I usually use Notepad++ for my editing needs. It knows about file encoding, it knows about end-of-line differences among operating systems, it knows how to highlight main programming languages, it is light and easy to use. It is not full of features, but I do not need them. Or at least, I think I don’t. Also, I confess I never dig much all of its potentialities.

Programming Language

My main programming language is Perl. I occasionally need some C, and some of my Perl modules link to C and C++. So, to fill my need for these three programming languages I choose to install Strawberry Perl. I never ever used Perl with so ease in Windows before Strawberry Perl. It supports more than 90% of CPAN modules, and it includes a C and C++ compilers (gcc based) and a make command. What else one needs?

Compression Tool

Windows knows (it its recent incarnations) about what are zip files. But it ignores all about rar, gzip, bzip2 or tar files. Most Perl modules come in tgz format, so I need a tool to extract them. Most people tend to use WinRar or 7zip. I am not sure why, but I prefer IzArc. It is lightweight, supports most compression algorithms, and integrate pretty well with explorer.

PDF Visualizer

If up to now I defended the use of lightweight applications, now I’m going to the other side, and my choice to read PDF documents is Adobe Reader. There are other free and more lightweight applications, like FoxIt Reader, but I had so many trouble with PDFs and PDFs compatibility that I prefer to have the application from the PDF creators. I know that doesn’t mean much, but at least it can work as an excuse.

What I miss…

There are some tools that I miss. First, I miss a decent command prompt window. One that let me select text, copy and paste easily, that let me make full screen, that let me change easily the font, and not just some stupid predefined sizes. Together with this, a decent command prompt, or shell, with better completion, better prompt configuration, better history, etc. To install cygwin is not an option. For that, I would use linux.

Also, and as I stated above, now I am using GitHub a lot. Then, I miss a Git client. I tried TortoiseGit but it didn’t work well for me. Probably it was a beta release, and now it is better. I need to test. I used the Git binary, that includes a Git shell, and mostly works. But it do not integrate well with the operating system.

@GitHub Inconsistency

 

Github Inconsistency

Github Inconsistency

This is something I couldn’t still understand. Not sure if this is a bug or if I am missing some information. This project claims to have 22 open issues, but when I get into the issues page, it shows 24 issues (and the list really includes 24 items). I would say the number in the toolbar is wrong, but probably I am missing some special type of issue that does not get counted?

Being a Dancer

(re-post from blogs.perl.org)

For some time now, I am a Dancer contributor. It all started in the last Christmas (everything in the Perl community start or end at Christmas time), with Dancer Advent Calendar.

Getting a little behind… I tried to learn to use Catalyst some time ago, reading a Packt Publishing book and found at that time that the book was already outdated. Unfortunately that is standard in Technology, and the books that keep up to date for some time are the ones that focus the foundations of computer science, and not the technology itself. It didn’t work. Probably I was not tuned to the MVC model, or I didn’t have a concrete project where to test Catalyst.

Time passed, and I needed to put a website up. CGI was not an option. I do not think CGI is that bad, but if web frameworks exist, is because they lessen the work needed to make a website run. At that time I was pointing to Mojolicious, as I listened to a talk on a Portuguese Perl Workshop, and it seemed easier to learn than Catalyst. When I finally decided to learn a web framework I found that Dancer Advent Calendar, read the first two or three days (can’t remember exactly) and I liked it.

I started to build a web site with it, and it felt good. With little effort I got the basics working. Of course problems arise, and I needed to visit #dancer on irc.perl.org for help. The users present on that channel at the time tried to help me. I confess they didn’t find the solution, as it was some weird problem on redirects and the fact that I needed to use Open3. That was the time when I needed to develop POSIX::Open3.

But since them, I was hanging on #dancer. Listening to development discussion and newbies asking for help. I tried to help them as good as I could. Sometimes I needed to hack Dancer code to correct some bug or add a functionality requested by one of those newbies. And no, I wasn’t a Dancer developer then. Just trying to help.

Accordingly with the Changelog, my first patches were released in Dancer 1.3001. I do not want to search on GitHub the exact date for my first pull request, but this release was out in January/February 2011. That is, only one or two months after I started using Dancer.

The pull requests continue to pop in github. And I can be a hassle, poking the developers to merge my code 🙂 About eleven releases after (a quick count, didn’t take care of what were stable or developer releases), Dancer developers started to name stable releases with names of somebody that helped/contributed a lot to that release. The first release of this kind was named after Michael Schwern, and the next was released after my name (1.3030, April 13th). About four months after I started using Dancer.

As I did not stop to write code, fixing bugs and adding some new features, they made me a Dancer core developer in May 9th.

I continue to help (I think) in the development of Dancer. And it all started with a simple site I needed to put online.

As a final note, my thanks to Alexis Sukrieh, Damien Krotkine, David Precious, Franck Cuny and Sawyer X for putting up with me and for welcoming me to this community.

Book Review: Modern Perl

I bought the Modern Perl book by chromatic. The title is inspiring. There is a lot of people writing Perl code as they were writing years ago. Although Perl still support those syntax and lack of strictness, there is a new trend on Perl code, and actual and future Perl developers should start learning it.

The index of the book is inspiring as well. For one, it starts the chapter on object orientation with Moose and not with the old and crappy Perl OO system (in fact, I started learning Moose, and think there are too much Moose modules, too much documentation, too much of everything, that makes it impossible to find anything you would like). It could talk about Mouse or Moo, it does not matter, as only the basics are explained, and as far as I know, these three frameworks share the basic syntax and behavior.

Also, the book as a good aspect when you look to it in graphical terms. It is quite easy to notice it is typeset with LaTeX and that is nice. And it is typeset with LaTeX using a set of Perl tools to convert from the POD (Perl documentation format) to LaTeX. Unfortunately the bibliographic entry on the book writes LaTeX in ASCII form, but it should render the correct logo for it (there is a command for that, you know?).

The typesetting engine also changed the defaults from LaTeX. And, sorry for the language, they did shit. It is impossible to read a book where you cannot differentiate easily whats a chapter title, a section title or a subsection title. I almost feel tempted to measure the title lines and check how may millimeters there are of difference. More, the examples (and the full book, in fact) have the letters quite small, making it difficult to read.

Enough for the format, now for the contents. After reading the old Learning Book and Programming Book written by Larry, Schwartz and Christiansen, the new versions with Tom Phoenix, and most recent books with brian d foy, I should say chromatic is in the bottom regarding read easiness and sense of humor. Yes, older books had much more sense of humor than current ones.

The book is not for beginners. There are examples that are not complete. They have some text placed along with the example to explain it, but sometimes the most important piece to the beginning programmer is just missing. As an example, chromatic tries to explain that using $_ inside functions are bad, because you can’t use those functions safely on a for loop. He shows the for loop, shows the call for a function, but doesn’t show the function body. I think newbies will be kind of lost.

This said, I should congratulate chromatic and Onyx Neon for the courage and work publishing this book. Nevertheless, I think it needs some more work (both typographical and content related) and that a second edition is required as soon as possible.

Hiding the bird’s guts

Probably this is a stupid rant/question. If so, please clarify me. I can live without the insults. Really 🙂

OK, on to the relevant stuff. Twitter has a new OAuth authentication mechanism. To write an application able to post on twitter your application need to be registered and have a consumer key. That key is used to identify your application to twitter when requesting permissions to a user to post using her credentials.

Now, the problem is when your application is written in a scripting language, like Perl, Python, Ruby or anything similar. Will you insert this key verbatim in the source code? Then, when shipping your app, others can grab that token and use it as if it were your app. You can encrypt it, but you need to ship the decryption algorithm as well, so, making the key verbatim.

One of two things can be happening: or twitter guys are not good on this API thing, or I am being totally stupid.

Text::BibTeX 0.40 Released

Normally I do not post on every perl module I release. And that is good, or you will be feeling spammed.

Why this module is different?

Because I adopted Text::BibTeX a long time ago, and had a lot of complaints about its installation mechanism. This was mainly due to the fact that Text::BibTeX depended on a C library that needed to be installed prior to the perl module. The C library installation was easy on generic Unix platforms but was a pain to compile under Windows.

After lot of work I managed to include the library C code in the Perl module (now Text::BibTeX has no dependencies on the library), and managed to include code to compile the library in Windows, using the Strawberry Perl distribution (that includes a mingw C compiler).

The package is needing heavy tests, but it seems usable for most users. Probably I will post on the details about its build system in a later post.

Pascal is not dead

Probably you know that I was a teacher at the Computer Science Department at Universidade do Minho. There I was a C and Perl teacher, as well as other classes that are not relevant for this post. Now, I am working at Instituto Politécnico do Porto, in the Escola Superior de Estudos Industriais e de Gestão. I am not responsible for the class, so I teach what the responsible teacher says. I was quite surprised they still used Pascal.

But this was a stupid question. Now, after getting back to the Pascal world, I noticed Pascal is not dead, and it getting better, and quite far from C when regarding the abstraction layer. I will not discuss efficiency. It I would do that, I would not program Perl anymore.

Pascal is, like C, a compiled language. But it supports growing strings. Strings can be edited as if they were Perl strings. You can add substrings to the string, remove substrings by nothing or other smaller or bigger strings. But you can also use it as an array of characters and access to each character individually. I really miss this feature in Perl.

Pascal is now supporting units as classes. This means it can be programmed as if it were an Object Oriented language. I did not get to that point yet. But it is nice to know Pascal evolved.

Oh, there is a free compiler (free pascal compiler) and there is an IDE (lazarus) that enables GUI application development just like the old Delphi.