The Road to Hell is Paved With Good Intentions

Ok you might remember this post a week or so ago. Our might even remember the last line

one more quick fix and then they all pass, package and stick on CPAN.

Famous last words of the dammed as I took a look today and

Running a non-blocking command in Mojolicious

Mojolicious is an awesome framework designed from the ground up to be non-blocking. During web development it is sometimes desirable to run a command and do something with the results. However, with methods such as "system" and "open" the command will block concurrent requests.

A non-blocking process execution is possible with background processes; however, the process must be managed and if the UserAgent needs updating, then long-polling will need to be utilized.

Below is a complete Mojolicious::Lite program that does this. In words, the app generates a utility script on-the-fly that a) sleeps; b) writes to a state file; and c) sleeps at the the end. This means that our state file will be around while the program is running. This mimics several use-cases, for example creating a thumbnail.

The state file can be inspected using events provided by Mojo::IOLoop::ProcBackground. The alive event is a heartbeat for the process and the dead event happens when the process stops.

Stupid CPAN Tricks

Stupid CPAN Tricks :

I’ve uploaded my slides for 9 Perl modules you should have in your tool belt to the MadMongers file archive.

[From my blog.]

Add your gittip id to your MetaCPAN account

  • In the Account menu (top right) on MetaCPAN, select Profile.
  • Scroll down to the Profiles section and select Gittip from the "Add Profile" drop-down.
  • Fill in your gittip id and click on the word "check" to the right.
  • Scroll down and hit "Save Profile"

And don't forget to join the Perl community on gittip!

Shame Is in

sc-public-schools-epic-fail.jpg

I think I will join the shame circle started by KD. So here is my confession and it happened today.

Well today I was finishing creating a new system for a customer based on another similar one. So there I am happily copying some files, re-naming thing A here and thing B there, setting up some configs, refactoring, cleaning and generally enjoying trying to remove some aspects of a giant anti-pattern from our system.

Things worked fine for the export portion of the system so then I moved on to the import and on the first try it died and died hard.

Well after some head scratching I was at a loss so I called in a colleague to have a look. After the usual blame the new code and blame the old code game, then a round or two of everyone's favorite pastime 'Change Die to Carp::confess'. Nothing!

We even tried 'perl -d xxx.pl' and even that didn't help.

POE::Session object_states: handlers are sub names not CODEREFs

This works as expected:

    sub _poll_start {
        my $self = $_[OBJECT];
    [...]
    POE::Session->create(
        'object_states' => [
            $self => {
                '_start' => '_poll_start',
                'Work'   => '_poll_work',
                '_stop'  => '_poll_stop',
            }
        ],
    );

This, on the other hand, calls the handlers but without filling the @_ array:

Next grant application process starting in March

Due to our internal reasons, the Grants Committee did not call for application in the 2013 Q4 round.

Now we are back in business; we will call for grant proposals in early March. The deadline will be two weeks after the CFP is open. The exact date will be announced at news.perlfoundation.org.

The Grants Committee members are working hard to improve the process. It'll be one of the improvements to increase the CFP frequency from quarterly to every two months.

More London events

<farnsworth>"Good news, everyone!</farnsworth>
I'm going to be back in London for the entire first two weeks of March.

First up, if anyone is planning on attending QCon London next month, here's a discount code that will get you £100 off registration (and see another £100 donated to Make A Wish UK): CONW100

I'll be speaking at the conference, giving a keynote on quantum cellular automata, as well as a tutorial on presentation skills, and a 40-minute preview of my new 1-day polyglot regular expressions class...which FlossUK will then be offering in full in the week after QCon.

We're also looking into the possibility of me giving another talk for London.pm one evening in the second week. I'll blog the details of that event, once we can confirm a date and venue.

Keep yer notes

I was cleaning up some papers out of a notes binder this AM and blundered across something I scribbled down during a YACEU, (not sure if it ws 08 or 09). On closer examination it was a number of notes taken during one of the lighting talk session.

Nothing that I would want 5 years later the only interesting bits where some of those magic/secret/sacred code one-lines that somebody always presentes during one the the lightning talks.

I rarely use them myself except for the good old spaceship operator or

<=>

Useful when you want to sort this @(-1,23,5,-6,0) you want this @(-6,-1,0,5,23 ) and get this @(-1 -6 0 23 5)*

Used normally like this

my @arry = (-1,23,5,-6,0);

my @sorted = sort({$a<=>$b}) @arry;

Which code to read?

Peter Seibel has written a great blog post on code reading - learning more about programming by reading good examples. The final model he describes has someone diving into a piece of code like a 19th century explorer and then reporting back to the group on what they found. This sounds like a valuable activity for a Perl Mongers group.

So my question to you is what CPAN module would you recommend as rewarding to an intrepid code explorer; and why? Of course I'm not suggesting Perl programmers should only read Perl code, but I do think CPAN is a good place to start.

detecting "too heavy" views in Template Toolkit

$client is doing a lot of heavy lifting (perhaps accidentally) in some Catalyst-driven Template Toolkit code. Apparently, it's far too easy to pass a DBIx::Class object into the stash, and then trigger things that end up hitting the database... from the view. That wouldn't be horrible, except the same exact queries are being used in multiple places in the templates, causing many redundant identical queries to the database per page hit. (Note aside: if this was Rose::DB... I'd trivially jump to Rose::DB::Object::Cached. Problem solved.)

I wanted a way to see what method calls were being invoked on the objects in the stash. Simple... just subclass Template::Stash! Now I get a list of the component invoking the method, the path from the root stash to the object, and the method call being made.

Three ways to introduce othogonal behavior: Aspects, Method modifiers, and Subroutine attributes

In my previous post I spoke about what Subroutine attributes are and how to use them. Here I compare them to other techniques for introducing orthogonal behaviors: Method modifiers and Aspects. These three techniques enable to modify what a subroutine does, but they do it in different ways and are thus suited for different needs.

Ok No is not Moose

A many readers of this blog know I have been spending a good deal of time lately playing about with Moose doing all sorts of silly little things with AD&D character creation and alike.

Well I was curious today and started to take apart a little bit of Moose and see what was under the hood so to speak. So far I have discover that all the nice Moose sugar are really just function calls and since some programming I was doing today requires me to use 'no Moose', he much preferred 'namespace::autoclean;' not being install on the box I was playing with yet.

So I started to look in the Moose dir of my perl for the 'sub no' the one that takes away all the sugar. Well I tired every combination of 'sub no' I could think of with 'ack', 'Grep' and even loading things on Padre to see the outline result.

Nothing couldn't find it anywhere???

Joose - advanced meta-class system for JavaScript

Joose - advanced meta-class system for JavaScript :

Joose is Moose in Javascript.

[From my blog.]

I bought a weekly round for my friends

Given our community is a little... let's say cautious I feel the need to open with a disclaimer. I am in no way affiliated with Gittip, in the past, present and the foreseeable future. In fact I looked at their bugtracker for the first time this morning and am appalled that a site in production for 2 years can have so many outstanding basic conceptual issues.

In any case this entry is about the underlying idea, so if you can manage to not get distracted by a shoddy implementation - read on (NSFW language as always :)

"You and your ilk are a tiny minority trying to impose your opinion upon the majority who actively and vocally disagree with you."

I will no longer be participating at Perlmonks.

Blast From the Past

Was cleaning up a few files on the server today and blundered across a few code files that look something like this on the inside

New blog. New role.

TPF (The Perl Foundation) announced the new Secretary of the Grants Committee. It's me.

Some of you may not know what TPF does. It may not be well known that TPF grants money for Perl development.

Here in this blog, I would like to add a bit of transparency on what the committee does, answer questions and have feedback from the community.

While it's my blog as the Secretary, the Grants Committee's official communication channel continues to be news.perlfoundation.org. You don't need to read my blog to apply for a grant but you are expected to read news.perlfoundation.org.

Subroutine attributes: where and how to use them

I watched this video about Subroutine attributes, and I wrote myself a summary of what I learned. I thought I could share it.

Using DBIx::Class::Schema::Loader to find design flaws

If you avoid DBIx::Class because of performance issues, you should probably check out version 0.08250 or better. In an interesting note from the Changes file:

Rewrite from scratch the result constructor codepath - many bugfixes and performance improvements (the current codebase is now capable of outperforming both DBIx::DataModel and Rose::DB::Object on some workloads).

Previously I used it because with DBIx::Class::Schema::Loader, I could pregenerate my classes from a database schema and it's fairly robust. When the database changes, I can regenerate my classes on the fly and and run the tests to verify that nothing's broken. However, I hit upon a case where it generated some bad code. As it turns out, DBIx::Class::Schema::Loader was correct and it revealed a bug in my database design.

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.