Home » Posts tagged "Perl"

Propel ORM for PHP

For the last couple of weeks I’ve have been working with Propel ORM for PHP and have really enjoyed using it. Coming from Perl I’m spoiled because it has DBIx::Class which is my ORM by choice and makes fetching data from your SQL database including relational data a breeze. Propel does a really nice job with this as well and though the API differs greatly from that of DBIx::Class I found it easy enough to pick up.

Propel nicely integrates with Symfony 2 and I’m happy with my decision to go with Propel. The alternative would’ve been Doctrine but decided against using it, mainly because of having to learn DQL (Doctrine Query Language). DQL is similar to SQL, but I liked the named methods of Propel better (e.g. filterByCampaign($object) or filterByCampaignId($id)) and in the end with Doctrine you’re still busy writing a dialect of SQL. With Propel and DBIx::Class you can still use SQL when needed (and to be honest I still find it to be a bit awkward at times in DBIx::Class but I understand why it is the way it is). I could also have looked at Zend_Db_Table from Zend Framework which I’ve used in the past but found too limiting.

All in all Propel a nice ORM library for PHP. Be sure to check it out if you haven’t already.

 

Maximus has been taken down

As of today Maximus, the BlitzMax Module Manager, has been taken down. I’ve blogged about this some time ago and today I’ve decided it was finally time to go through with it. The website now redirects to the GitHub organization that hosts the code for the client and the website. These will still be available online of course.

So what does this mean for Maximus and BlitzMax?

  1. The Maximus client can no longer fetch the sources file from the Maximus website and thus it can no longer download modules from the website as well. You’re back to downloading and installing BlitzMax modules manually yourself. If you’ve got a Maximus webapp instance running somewhere you can however configure the client to use the sources file from there.
  2. Development on both the client and webapp had stopped some time ago, but I would still fix bugs if they popped up. With the cancellation of the hosted webapp this also means I won’t be doing any development on Maximus anymore.
  3. With the source code being available anyone is free to host their own Maximus instance. Since the webapp uses Vagrant and Puppet you should be able to get a local instance running quickly. There’s also an INSTALL file for manual installation on Ubuntu.

Developing Maximus and providing this service has been a fun ride of which I’ve learned a lot and resulted in a well crafted piece of software. I can however no longer provide the service and support it and so it’s time to move on. I want to thank everyone who has supported Maximus in any way possible. Thanks.

Create a PDF document out of an HTML page

Perl has several modules on CPAN for creating and manipulating PDF files. Just a single search on PDF results in over 500 modules that have something to do with PDF files.

The most useful (or rather essential for PDF processing) are PDF::API2 and CAM::PDF. The former lends itself best for creating PDF’s and the latter for manipulating existing PDF’s and extracting data (such as plain text) from it.

Though these modules make handling PDF’s easier, handling PDF’s still isn’t much fun. As I was in need of a way to generate PDF’s out of work orders (or job tickets) and not feeling much for creating the layout manually and properly formatting paragraphs (manually) with PDF::API2 I started to look further.

I ended up trying out PDF::FromHTML. With PDF::FromHTML you can create a simple HTML layout and let the module create a PDF out of it. You can do some basic configuration such as changing fonts and font-size (check out its documentation for more). It also provides a nifty command line tool called html2pdf.pl for converting an HTML page to a PDF.

The resulting PDF’s from PDF::FromHTML weren’t as pretty as I had wanted, but good enough for the problem I needed solving. But after I started using these work order PDF’s in practice I found I needed more formatting freedom when writing the problem description. So I decided to add Markdown support through Text::Markdown.

Using Markdown I had added a list of tasks to a work order with the items being in bold text and the descriptions underneath it in normal text. Sadly the PDF’s created by PDF::FromHTML didn’t cope very well with nested HTML-elements. A bold paragraph would somehow cause the next paragraph become bold as well. I think that’s a bug in PDF::FromHTML and I’m sure it can be fixed and shame on me for not looking into it.

So instead of seeing if I could fix the bug I did a quick search on the internet and stumbled upon xhtml2pdf, which is provided by python-pisa/xhtml2pdf. Pisa is a Python library for converting HTML pages to PDF’s. It’s far more sophisticated than PDF::FromHTML as it supports more (all?) HTML tags and even CSS2 (plus some CSS3 stuff) for styling.

Currently my webapp will be using xhtml2pdf if it’s available or either fall back to PDF::FromHTML.

Some other interesting Perl PDF modules worth looking into some day are PDF::Boxer and PDF::TextBlock. And while writing this post I also found out that PhantomJS, a headless WebKit, also has a way of saving a page to PDF. So even though handling PDF’s still isn’t a lot of fun, with all these modules and software available it has become a lot easier.

Want to use a web service to convert HTML to PDF? Then take a look at HTML2PDF Web Service.

RSS and Atom feed for BlitzMax.com

This evening a wrote a Perl script using Mojolicious to generate a RSS and Atom feed for the BlitzMax website. I did this because that website has been lacking it. I use Google Reader to stay up to date with countless websites. Any website that doesn’t provide a RSS or Atom feed I’ve got to visit manually and scan through it to see if anything new and interesting has been posted. Which in turn can takes some time.

Below is the script I’ve written that uses some modules of the Mojolicious toolkit. Mojo::DOM makes it very easy to get specific content from a page and the CSS selector support is great. On top of that I’ve hardly had to use the documentation to figure out how to do what I wanted. Very clear API! For the feed generation I’ve used XML::Feed. I’m also using CHI to cache page content so it doesn’t need to fetch this every time the script runs.

You can host the script yourself, or you can add one of the links below to your RSS/Atom reader. As long as traffic doesn’t get too high I’ll be providing public access to the feeds.

Progress on programming languages to learn in 2011

A while ago I posted about Programming languages to learn in 2011. Now that we’re almost halfway into 2011 I though I do a little reflection of what languages I’ve learned so far… None!

Although none isn’t exactly correct, I can’t say I have learned enough of any of the listed languages to program with. So far all I’ve really done is reading the amazing book Learn You a Haskell for Great Good. So far I’m halfway through the book and I actually did some of the examples and am able to figure out what most of the syntax means. But not more than that.

Not exactly what I had in mind but still it’s better than nothing. I’ll be able to catchup soon though as I’m still only working full-time for 6 more weeks. After that I’ll have 2 months off (I’ll still have to do work from home, but will have a lot more free time on my hands) so that should be plenty of time to learn some new stuff!

Since almost 6 months has passed now, why is it that I haven’t done more yet? Well, there’s still the issues I have with my hands, although the last couple of 5 weeks or so this is getting much more better. I’m still trying to get my Vitamin D level up and am also getting Vitamin B12 injections. On top of that I’m still visiting the Acupuncturist every month or so.

In these weeks that I’ve finally been able to get some stuff done I focused on getting the Maximus website up and running and make it feature complete. All required functionality is in there now and it actually already hosts quite a lot of modules. Out of my head over 250. There’s still more work to be done for the final 1.0.0 release but it’s mostly refactoring, writing test cases and the occasional bug fixing.

So no, I haven’t been able to study the listed programming languages, but I have been able to do some more Perl and get Maximus in a state where it’s usable. In the coming months I do plan to focus on Haskell and C# though, as well as refreshing my Math skills. So all in all I’m pleased with my progress so far.