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);
};
1

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 traits.pm module.

Processing schema.org markup with Perl

Someone on IRC asked me for an example of how to parse schema.org 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

use/users/toby_inkster/2012/08/index.html

About Toby Inkster

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