NAME

UnderscoreJS - Perl port of Underscore.js

SYNOPSIS

use UnderscoreJS;

_([3, 2, 1])->sort;

DESCRIPTION

UnderscoreJS Perl is a clone of a popular JavaScript library http://github.com/documentcloud/underscore|Underscore.js. Why? Because Perl is awesome. And because we can!

                  /\ \
 __  __    ___    \_\ \     __   _ __   ____    ___    ___   _ __    __
/\ \/\ \ /' _ `\  /'_` \  /'__`\/\`'__\/',__\  /'___\ / __`\/\`'__\/'__`\
\ \ \_\ \/\ \/\ \/\ \ \ \/\  __/\ \ \//\__, `\/\ \__//\ \ \ \ \ \//\  __/
 \ \____/\ \_\ \_\ \___,_\ \____\\ \_\\/\____/\ \____\ \____/\ \_\\ \____\
  \/___/  \/_/\/_/\/__,_ /\/____/ \/_/ \/___/  \/____/\/___/  \/_/ \/____/
                                                   ___
             __                                   /\_ \
            /\_\    ___       _____      __   _ __\//\ \
            \/\ \ /' _ `\    /\ '__`\  /'__`\/\`'__\\ \ \
             \ \ \/\ \/\ \   \ \ \ \ \/\  __/\ \ \/  \_\ \_
              \ \_\ \_\ \_\   \ \ ,__/\ \____\\ \_\  /\____\
               \/_/\/_/\/_/    \ \ \/  \/____/ \/_/  \/____/
                                \ \_\
                                 \/_/

This document describes the differences. For the full introduction see original page of http://documentcloud.github.com/underscore/|Underscore.js.

The test suite is compatible with the original one, except for those functions that were not ported.

The main differences

All the methods have CamelCase aliases. Use whatever you like. I personally prefer underscores.

Objects are simply hashes, not Perl objects. Maybe objects will be added later.

Of course not everything was ported. Some things don't make any sense for Perl, other are impossible to implement without depending on event loops and async programming.

Implementation details

Most of the functions are just wrappers around built-in functions. Others use List::Util and List::MoreUtils modules.

Numeric/String detection is done the same way JSON::PP does it: by using B hacks.

Boolean values are implemented as overloaded methods, that return numbers or strings depending on the context.

_->true;
_->false;

Object-Oriented and Functional Styles

You can use Perl version in either an object-oriented or a functional style, depending on your preference. The following two lines of code are identical ways to double a list of numbers.

_->map([1, 2, 3], sub { my ($n) = @_; $n * 2; });
_([1, 2, 3])->map(sub { my ($n) = @_; $n * 2; });

DEVELOPMENT

Repository

http://github.com/vti/underscore-perl

CREDITS

Undescore.js authors and contributors

AUTHORS

Viacheslav Tykhanovskyi, vti@cpan.org Rich Douglas Evans, rich.douglas.evans@gmail.com

COPYRIGHT AND LICENSE

Copyright (C) 2011-2012, Viacheslav Tykhanovskyi Copyright (C) 2013 Rich Douglas Evans

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.