Recently in Perl 5 Category

Perlbuzz news roundup for 2010-08-27

| No Comments

These links are collected from the Perlbuzz Twitter feed. If you have suggestions for news bits, please mail me at andy@perlbuzz.com.

Run PHP tests in your Perl test suite

| 5 Comments

Sometimes you've got a big codebase that isn't just Perl. Maybe you've got PHP mixed in with it, and you want to test the PHP along with all the Perl code, too. Perl's prove program doesn't care if the testing results it parses are from Perl, PHP or even static files, so long as they're in the TAP format. However, actually getting prove to run those PHP programs takes a little doing. Fortunately, Test::Harness 3.xx has hooks for source handlers.

David Wheeler has written about running PostgreSQL tests under prove in his blog and I stole from his code shamelessly to create TAP::Parser::SourceHandler::PHP, released to the CPAN this morning.

So now, to run the Perl .t files and the PHP .phpt files all in one swell foop, here's what we do at work:

prove -r \
    -I/home/alester/proj/Lib \
    --source=Perl --ext=.t \
    --source=PHP \
    --ext=.phpt \
    --php-option=include_path=/home/alester/proj/Class \
    --php-option=extension=.phpt

That --source=PHP tells prove to load up TAP::Parser::SourceHandler::PHP. The --php-option tells prove to pass those options through to the SourceHandler. If we had PostgreSQL tests or MySQL tests, we could use the SourceHandlers for those that David Wheeler has written as well.

Now we can test everything all in one run, and we get all the benefits of Test::Harness 3.xx, like parallel tests and TAP archiving and so on.

Vim 7.3 supports Perl 6, adds Perl 5 improvements

| 1 Comment

Vim 7.3 has just been released today. From the announcement:

This is a minor release of Vim. It consists of Vim 7.2 plus all patches, updated runtime files and some more, see below. It has been two years since the 7.2 release, thus it's not that "minor". But not "major" either. Something in between, don't know how to call that.

The most notable additions since 7.2:

  • Persistent undo and undo for reload
  • Blowfish encryption, encryption of the swap file
  • Conceal text
  • Lua interface
  • Python 3 interface

However, to the Perl programmer, this is a significant upgrade from 7.2, because of updates of all the Perl-related support files. Vim has language specific plugins for syntax highlighting, indenting and other filetype-related behaviors. Every one of these Perl-related support files has been updated. For example, syntax/perl.vim has not been updated since 2006. Now, Perl 5.10 keywords like given, when and state are properly highlighted.

For the Perl 6 hackers out there working with Rakudo Star, Vim now includes support for Perl 6. Until now, if Perl 6 programmers wanted Vim to support Perl 6, they had to use a perl6.vim file that got passed around from person to person. Now, it comes installed automatically as part of Vim 7.3.

Perl 6 detection is primitive, so you may have to explicitly add it to your modeline in your file, such as

# vi: filetype=perl6:

All of these changes are from the vim-perl project hosted on Github. In that project, I've aggregated syntax, indent and filetype plugins for the Perl and Perl 6 support files that get fed back to the Vim project. It's also got support for other filetypes like Template Toolkit that are not part of the vim distribution. I'm not making many changes to the Vim code directly. Like many of my other contributions to open source, my role is one of wrangler and coordinator and less of programmer and technologist.

If you're interested in Vim support for Perl 5 and Perl 6, I encourage you to check out the vim-perl project and join the vim-perl mailing list. Now that Vim 7.3 is out, we have some room to stretch out and make Vim do incredible things for Perl in the next release.

What's on your to-do list?

| 3 Comments

What's on your to-do list for Perl projects these days? Here's mine.

  • Test::Harness
    • Testing PHP code with Perl's prove program. I wrote code to do this under Test::Harness 2.x, but 3.x has an entirely different way to do it.
  • vim-perl
    • Just gave Bram the latest files for inclusion in vim 7.3
    • I want to have a test suite and a packaging system and to distribute it on CPAN
    • Write an FAQ and intro to let people know about cool tricks like "set equalprg=perltidy"
  • Rakudo Perl 6
    • Learning more Perl 6
    • Want to make perl101.org have parallel examples for Perl 5 and Perl 6.
  • Parrot patches
    • Fixing dependency problems in the Makefile
    • Checking regularly for errors that GCC's super-strict and persnickity warning settings turn up.
  • Updating links and articles on http://bobby-tables.com
    • I want bobby to be the canonical source to turn to help newbies know how to avoid SQL injection
  • Perlbuzz
    • Review of Effective Perl Programming
    • Aggregate information about Plack
    • Create a sitemap for Google's benefit
  • WWW::Mechanize
    • Making a ->text() method that caches its results, so that I can then...
    • Make Test::WWW::Mechanize's ->text_contains() method use it and not recalculate the same page contents over and over

Perlbuzz news roundup for 2010-08-09

| No Comments

These links are collected from the Perlbuzz Twitter feed. If you have suggestions for news bits, please mail me at andy@perlbuzz.com.

Perlbuzz news roundup for 2010-07-27

| No Comments


These links are collected from the Perlbuzz Twitter feed. If you have suggestions for news bits, please mail me at andy@perlbuzz.com.

Why roles in Perl are awesome

| 2 Comments

by Chris Prather

A question came up recently on a mailing list. I was talking about how Roles are a awesome win for Perl5 considering how few languages implement the concept1. Someone asked what the win was with Roles. I happen to have been thinking about this recently and dashed off a reply.

When you use Inheritance, especially multiple inheritance, for behavioral re-use you run into several problems quickly.

First Inheritance is an explicit modeling of a relationship that carries semantic meaning. Let's say you're developing a game for Biology students to explain to them taxonomy. In this game a Dog class is a subclass of Animal. That is, the Dog class inherits specific behaviors and attributes from the Animal class. This probably isn't even a direct relationship your Dog class may inherit from a Mammal class which inherits from a Vertebrate class which inherits from Animalia which itself inherits from Life. These kinds of hierarchies are common in Taxonomy as well as in Object Oriented programming. However when you need to express something that may cross cut concerns in, you run into issues.

Say for example your marketing department has had trouble selling this product to schools and is attempting to market to parents directly. They have done studies and kids really like Pets2. So your boss comes to you because the company wants you to add the concept of Pet to your Taxonomy model.

Pets don't fit into a Taxonomy, it's obvious that not all Animalias are Pets3 and some Pets may not be animals at all4. In many languages can use Multiple Inheritance to describe this new "I'm an Animalia and a Pet" relationship but often you run into issues there as well. Is a Pet a Life? That would mean our object model would look like:

Life
    Animalia
        Vertebrae
            Canine    Pet
                Dog

Pet stands out like a sore thumb. Obviously we've got issues with this new modeling. We talk to our boss and figure out that the rules for Pet are simple. Pet's are always domesticated versions of the Animalia, but not every class in Animalia is a pet. So for example Dogs are always Pets, Wolves are not. We can solve this with multiple inheritance now, but it's really not a clean way to express the relationship and it requires us to document the special relationship the Pet class would have with the rest off the Inheritance tree. Once you get beyond a few "special cases" like this it becomes hard to see the model for the exceptions.

This is why some languages like to disallow multiple inheritance entirely. In Java for example, Pet could become an Interface.

public interface Pet {
    Date getYearDomesticated;
}

This however means that every class that we want to be a pet needs to have the exact same piece of boiler plate code added to it.

class Dog implements Pet {
    ...
    private Date yearDomesticated;
    public Date getYearDomesticated () { this.yearDomesticated }
    ...
}

If we instead have the concept of Roles then we can apply the concept of a Pet once at any level of the hierarchy we need. A example using a modern Perl5

package Pet {
    use Moose::Role
    has year_domesticated => (
        is => 'ro',
        isa => 'DateTime',
        required => 1
    );
}

package Dog {
    use Moose;
    extends qw(Canine);
    with qw(Pet);
}

The Pet Role here implements everything we need for a default implementation, and doesn't require more boiler plate to our Dog class, that the bare minimum needed. It also avoids the ugly inheritance issues we saw with multiple inheritance by moving the behavior composition onto different tool. In my opinion, Roles aren't a win for every use of inheritance, nor for every time you want to re-use behavior, but they are an excellent tool to have in the box and one that the Moose crowd knows to reach for quite often.


  1. Off the top of my head I only know about Perl5, Perl6, Scala, Javascript, and Smalltalk. There may be other implementations out there. ↩

  2. The Marketing guy's daughter plays on WebKinz nightly. ↩

  3. Pet Shark's would be dangerous to say the least, and where would you keep a pet Blue Whale? ↩

  4. Who doesn't love their Pet Rock? ↩

  5. We're using the the inline package syntax that will be released in 5.14 ↩

Chris Prather is an Owner at Tamarou LLC, a member of the Moose cabal, and responsible for Task::Kensho.

Perlbuzz news roundup for 2010-07-06

| 2 Comments

These links are collected from the Perlbuzz Twitter feed. If you have suggestions for news bits, please mail me at andy@perlbuzz.com.

Perlbuzz news roundup for 2010-06-18

| No Comments

These links are collected from the Perlbuzz Twitter feed. If you have suggestions for news bits, please mail me at andy@perlbuzz.com.

Perl 5.12 released; Perl 5 under new release process

| No Comments

By Jesse Vincent, thanks to Eric Brine and Shlomi Fish for the markup. Please note the section about the new time-based release process below.

'Please would you tell me,' said Alice, a little timidly, for she was not quite sure whether it was good manners for her to speak first, 'why your cat grins like that?'

'It's a Cheshire cat,' said the Duchess, 'and that's why. Pig!'

She said the last word with such sudden violence that Alice quite jumped; but she saw in another moment that it was addressed to the baby, and not to her, so she took courage, and went on again:--

'I didn't know that Cheshire cats always grinned; in fact, I didn't know that cats COULD grin.'

'They all can,' said the Duchess; 'and most of 'em do.'

-- Lewis Carroll, Alice's Adventures in Wonderland

On behalf of Perl's development team, It gives me great pleasure to announce the release of Perl 5.12.0.

Perl 5.12.0 represents approximately two years of development since version 5.10.0 and contains over 750,000 lines of changes across over 3,000 files from over 200 authors and committers.

SHA-1 signatures for this release:

f533687077e2da113b48a6c5e578f4a206fbf173  perl-5.12.0.tar.bz2
5341e60d099fdda71bc33b2a36e417fc0926518f  perl-5.12.0.tar.gz

You can download this release from your nearest CPAN mirror or from:

http://search.cpan.org/dist/perl-5.12.0/

This release cycle marks a change to a time-based release process. Beginning with version 5.11.0, we make a new development release of Perl available on the 20th of each month. Each spring, we will release a new stable version of Perl. One month later, we will make a minor update to deal with any issues discovered after the initial ".0" release. Future releases in the stable series will follow quarterly. In contrast to releases of Perl, maintenance releases will contain fixes for issues discovered after the .0 release, but will not include new features or behavior.

Notable changes in Perl 5.12 include:

  • Perl now conforms much more closely to the Unicode standard. Additionally, this release includes an upgrade to version 5.2 of the standard.

  • New experimental APIs allow developers to extend Perl with "pluggable" keywords and syntax.

  • Perl now has a better sense of time and will be able to keep accurate time well past the "Y2038" barrier.

  • New syntax allows developers to specify package version numbers directly in "package" statements

  • Perl now warns the user about the use of deprecated features by default.

Perl 5.12.0 features numerous new features, optimizations and bugfixes. You can find a complete list of these changes on the web at:

http://search.cpan.org/~jesse/perl-5.12.0/pod/perl5120delta.pod"> http://search.cpan.org/~jesse/perl-5.12.0/pod/perl5120delta.pod

As specified in the licenses for Perl (see the files named Artistic or Copying in the Perl distribution), THIS PACKAGE IS PROVIDED WITH ABSOLUTELY NO WARRANTY.

Based on extensive testing over the past 3 months, we believe that Perl 5.12.0 is ready for production deployments. However, you should never blindly trust any software vendor. It is imperative that you test new software before deploying it in production.

While we have worked tirelessly to ensure that Perl 5.12.0 will be a solid platform for your software, it's possible that issues will be found after release day. You can find a current list of known issues with Perl 5.12.0 at http://dev.perl.org/perl5/errata.html

Perl continues to flourish into its third decade thanks to a vibrant community of users and developers. The following people are known to have contributed the improvements that became Perl 5.12.0:

Aaron Crane, Abe Timmerman, Abhijit Menon-Sen, Abigail, Adam Russell, Adriano Ferreira, Ævar Arnfjörð Bjarmason, Alan Grover, Alexandr Ciornii, Alex Davies, Alex Vandiver, Andreas Koenig, Andrei Yelistratov, Andrew Rodland, Andy Armstrong, Andy Dougherty, Jose Auguste-Etienne, Benjamin Smith, Ben Morrow, bharanee rathna, Bo Borgerson, Bo Lindbergh, Brad Gilbert, Bram, Brendan O'Dea, brian d foy, Charles Bailey, Chip Salzenberg, Chris 'BinGOs' Williams, Christoph Lamprecht, Chris Williams, chromatic, Claes Jakobsson, Craig A. Berry, Dan Dascalescu, Daniel Frederick Crisman, Daniel M. Quinlan, Dan Jacobson, Dan Kogai, Dave Rolsky, David Cantrell, David Dick, David Golden, David Mitchell, David M. Syzdek, David Nicol, David Wheeler, Dennis Kaarsemaker, Dintelmann, Peter, Dominic Dunlop, Dr.Ruud, Duke Leto, Enrico Sorcinelli, Eric Brine, Father Chrysostomos, Florian Ragwitz, Frank Wiegand, Gabor Szabo, Gene Sullivan, Geoffrey T. Dairiki, George Greer, Gerard Goossen, Gisle Aas, Goro Fuji, Graham Barr, Green, Paul, Hans Dieter Pearcey, Harmen, H. Merijn Brand, Hugo van der Sanden, Ian Goodacre, Igor Sutton, Ingo Weinhold, James Bence, James Mastros, Jan Dubois, Jari Aalto, Jarkko Hietaniemi, Jay Hannah, Jerry Hedden, Jesse Vincent, Jim Cromie, Jody Belka, John Malmberg, John Peacock, John P. Linderman, John Wright, Josh ben Jore, Jos I. Boumans, Karl Williamson, Kenichi Ishigaki, Ken Williams, Kevin Brintnall, Kevin Ryde, Kurt Starsinic, Leon Brocard, Lubomir Rintel, Luke Ross, Marcel Grünauer, Marcus Holland-Moritz, Mark Jason Dominus, Marko Asplund, Martin Hasch, Mashrab Kuvatov, Matt Kraai, Matt S Trout, Max Maischein, Michael Breen, Michael Cartmell, Michael G Schwern, Michael Witten, Mike Giroux, Milosz Tanski, Moritz Lenz, Nicholas Clark, Nick Cleaton, Niko Tyni, Offer Kaye, Osvaldo Villalon, Paul Fenwick, Paul Gaborit, Paul Green, Paul Johnson, Paul Marquess, Philip Hazel, Philippe Bruhat, Rafael Garcia-Suarez, Rainer Tammer, Rajesh Mandalemula, Reini Urban, Renée Bäcker, Ricardo Signes, Richard Foley, Rich Rauenzahn, Rick Delaney, Risto Kankkunen, Robert May, Roberto C. Sanchez, Robin Barker, Tomoyuki Sadahiro, Salvador Ortiz Garcia, Sam Vilain, Scott Lanning, Sébastien Aperghis-Tramoni, Sérgio Durigan Júnior, Shlomi Fish, Simon Schubert, Sisyphus, Slaven Rezic, Smylers, Steffen Müller, Steffen Ullrich, Stepan Kasal, Steve Hay, Steven Schubiger, Steve Peters, Tels, The Doctor, Tim Bunce, Tim Jenness, Todd Rinaldo, Tom Christiansen, Tom Hukins, Tom Wyant, Tony Cook, Torsten Schoenfeld, Tye McQueen, Vadim Konovalov, Vincent Pit, Hio Yamashina, Yasuhiro Matsumoto, Yitzchak Scott-Thoennes, Yuval Kogman, Yves Orton, Zefram and Zsban Ambrus.

This list is woefully incomplete as it's automatically generated from version control history. In particular, it doesn't include the names of the (very much appreciated) contributors who reported issues in previous versions of Perl that helped make Perl 5.12.0 better. For a more complete list of all of Perl's historical contributors, please see the AUTHORS file in the Perl 5.12.0 distribution.

Best,

Jesse Vincent

« Parrot | Main Index | Archives | Perl 6 »