A Flash-related browser crash ate my bug report to MooseX::Declare

ggghhhhaaaa. I hate flash. I really like http://proquest.safaribooksonline.com/, or rather, I used to love it, but now they’ve switched to Flash and it is hateful hateful hateful. But I still can’t stop using it because the information is so awesome and handy and because UCI has an account and it is right there waiting for me whenever I have a question. But then *bang* one page too many and firefox just blinks off my desktop.

So really this has nothing to do with hating flash, or how safari books is like a luscious siren lolling about in a tidepool, splashing the water, waving you over to come play with her, and singing that delightful song, never hinting that the coral with destroy your boat and her pet sharks are going to rip you to shreds.

FlashBlock is like strapping oneself to the mast, but I keep undoing the knot and jumping in.

But again, off topic, off topic. I have been trying to use perl; in the modern sense. I was using MooseX::Declare, and got into a tricky spot with trying to set up a single base role that was “extended” (if that is the word) by two other roles and then joined together again in a real class. It wasn’t working the way I wanted, although I got a version passing tests using classes, not roles. Then today I found MooseX::Role::Parameterized, but because I’m new to this, I couldn’t see how to mix that with MooseX::Declare.

Then search was actually useful. I found Parameterized%20Roles%20with%20MooseX::Declare. Very helpful note that Parameterized roles are *already* in MooseX::Declare.

So armed with this, I tried it out. And failed. A lot. Until I finally actually read the line number in the test failure and figured out where my problem was.

Anyway, here is a test for roles being able to use multiple roles, extending the test cases and test lib in the MooseX::Declare codebase. I was going to submit this as a bug report, and was looking up something in Perl Best Practices on Safari, when flash crashed my browser. Fucking flash.

First, I hacked MooseX::Declare’s test library t/lib/ParameterizedRole.pm as follows

use MooseX::Declare;

role Counter (Str :$name, Int :$charges = 1) {
    has $name => (is => 'rw', isa => 'Int', default => $charges);

    method "increment_${name}" {
        $self->$name($self->$name + 1);

    method "reset_${name}" {

class MyGame::Weapon {
    with Counter => { name => 'enchantment', charges => 5 };

class MyGame::Wand {
    with Counter => { name => 'zapped', charges => 3 };

class MyGame::Scroll {
    with Counter => { name => 'spelled' };

role MySingleCounter {
     with Counter => { name => 'lash', charges => 5 };

role MyDoubleCounter {
    with Counter => { name => 'enchantment', charges => 5 };
    with Counter => { name => 'pistol', charges => 10 };

class MyGame::Arsenal {
    with MySingleCounter=>{};
    with 'MyDoubleCounter';


My bug was in how I was using the non-parameterized roles. Instead of the above, I was trying to do

class MyGame::Arsenal {
    with MySingleCounter;
    with MyDoubleCounter;

That is, just putting the bare word for the role after the with keyword. That doesn’t work. MooseX::Declare is so full of sugar it will rot your brain and let you write stupid perl errors like that.

Then my test cases added into t/role_parameterized.t

use strict;
use warnings;
use Test::More;

use FindBin;
use lib "$FindBin::Bin/lib";

use ParameterizedRole;

can_ok('MyGame::Weapon', 'increment_enchantment');
can_ok('MyGame::Weapon', 'reset_enchantment');
is(MyGame::Weapon->new->enchantment, 5, 'Provided default for enchantment');

can_ok('MyGame::Wand', 'increment_zapped');
can_ok('MyGame::Wand', 'reset_zapped');
is(MyGame::Wand->new->zapped, 3, 'Provided default for zapped');

can_ok('MyGame::Scroll', 'increment_spelled');
can_ok('MyGame::Scroll', 'reset_spelled');
is(MyGame::Scroll->new->spelled, 1, 'Provided default for spelled');

can_ok('MyGame::Arsenal', 'increment_lash');
can_ok('MyGame::Arsenal', 'increment_enchantment');
can_ok('MyGame::Arsenal', 'increment_pistol');
can_ok('MyGame::Arsenal', 'reset_enchantment');
is(MyGame::Arsenal->new->increment_pistol, 11, 'Incremented the default for pistol');


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.