Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of Stevan (6065)

Thursday August 17, 2006
02:38 PM

Moose::Autobox - Ruby ain't got nothin on us

[ #30675 ]

I have just released the newest version of Moose::Autobox (0.03 to be exact), which adds a few nice improvements. First is that you no longer need to use autobox, just use Moose::Autobox will do. Next is the ability to mixin new roles at runtime, which makes neat things like this Ruby ActiveSupport style date trick very easy to accomplish.

Moose::Autobox->mixin_additional_role(SCALAR => 'Units::Time');

print 2->days->ago->as_string;
print 3->weeks->from_now->as_string;

See the Moose::Autobox examples directory for more details.

The next new toy (and my personal favorite) is the Y combinator is now available for CODE references. For those who are not familiar the Y combinator is a fixed-point combinator which can be used to turn an unnamed or anonymous subroutine into a recursive one. It does this through a series of complex tricks which are beyond the scope of this post, so it is probably best to just show a code example.

my $factorial = sub {
    my $f = shift;
    sub {
        my $n = shift;
        return 1 if $n < 2;
        return $n * $f->($n - 1);
    }
}->y;

$factorial->(10) # returns 3628800

This is now much shorter then the ruby version (and cleaner to IMHO).

Now all we need is a dashingly handsome spokesmodel and Perl can be the new Ruby ;)

- Stevan

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.