http://qs321.pair.com?node_id=259349


in reply to Re: Short Refactoring Tip: let the object do it for you
in thread Short Refactoring Tip: let the object do it for you

I'd probably work that out as a dispatch table instead:

my %STATES = ( sent => sub { . . . }, pending => sub { . . . }, waiting => sub { . . . }, procrastinating => sub { . . . }, delayed => sub { . . . }, ); # Make 'pending' and 'waiting' the same thing $STATES{pending} = $STATES{waiting}; # Later $STATES{$status->state->name}->();

It's faster than a speeding regex. And I personally think dispatch tables are sexy.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

Note: All code is untested, unless otherwise stated