August 2012 Archives

Sugar for MooseX::Traits

Tomorrow morning I'll be needing to get up in the wee small hours of the morning to travel to the Moving to Moose Hackathon 2012. In the mean time, here's some sugar for the awesome MooseX::Traits...

package traits;
use MooseX::Role::Parameterized;
parameter namespace => (
    isa     => 'Str',
    default => '',
role {
    with 'MooseX::Traits';
    has '_trait_namespace' => (is => 'ro', default => shift->namespace);

Instead of this:

package MyProject::MyClass;
use Moose;
with 'MooseX::Traits';
has '+_trait_namespace' => ( default => 'MyProject' );

You can now just write:

package MyProject::MyClass;
use Moose;
with traits => { namespace => 'MyProject' };

It would be better perhaps if MooseX::Traits and the 'with traits => {}' pattern could be integrated into Moose itself, avoiding the need for a top-level module.

Processing markup with Perl

Someone on IRC asked me for an example of how to parse markup using my HTML::HTML5::Microdata::Parser module. So here one is. It pulls the microdata from the page, and queries it using SPARQL.

#!/usr/bin/env perl


About Toby Inkster

user-pic I'm tobyink on CPAN, IRC and PerlMonks.