moosex::poe ftw!

in the serie "why using moose and moosex" - today i present moosex::poe.

say you want to create a poe session. traditional way is to create a module handling spawn method that would be called as:

the module itself would be something like this:

now that's moutful. and it has an easy-to-miss error - found it? right, it's should be event3, not evnet3. you can curse poe quite some time trying to understand why your nice handler never gets called for event3.

here's the version using moosex::poe:

of course, it's still possible to mis-spell event3. however, you only have to spell it once, whereas you wrote it 3 times before - which is 2 times too much!

and i'm not talking about the easy accessors that could be added by moose - but i'm concentrating on moosex::poe here.

granted, there's one downside: subs are now anonymous, which can make it a bit harder to debug. but that's a small price to pay, imo.

so, moosex definitely makes your code more readable - i'm definitely not looking back, and i advise you to have a look too.


  1. This comment has been removed by the author.

  2. Neat! I'll definitely give this a try the next time I'm using POE. To Ironman and beyond!

    OffTopic: I like the look of the github gist embeds. I think I'll start using that too, since code on blogspot otherwise looks so horrible. Thanks for the pointer.


  3. I believe you can still name your events 'on_event3' and make them regular subs and have them dispatch. It's been a little while since I looked, and I almost always use the event() interface.

    Also the event stuff is just a wrapper for Class::MOP::Package's add_method which calls Sub::Name's subname() on the methods. It's circutous logic but the method's are given names at some point, so they're not really anonymous.

  4. Hi!

    Congratulations! Your readers have submitted and voted for your blog at The Daily Reviewer. We compiled an exclusive list of the Top 100 Perl Blogs, and we are glad to let you know that your blog was included! You can see it at http://thedailyreviewer.com/top/perl

    You can claim your Top 100 Blogs Award here

    P.S. This is a one-time notice to let you know your blog was included in one of our Top 100 Blog categories. You might get notices if you are listed in two or more categories.

    P.P.S. If for some reason you want your blog removed from our list, just send an email to angelina@thedailyreviewer.com with the subject line "REMOVE" and the link to your blog in the body of the message.


    Angelina Mizaki
    Selection Committee President
    The Daily Reviewer