Synopsis
# enables use warnings and strict for you
use Modo;
# Modo now uses autobox. Which means you can create strings and arrays like so
my $str = "Hello, World"->ob;
my $arr = ['hello', 'there']->ob;
# Basic Str example
my $str = Str->new("Hello, World!");
$str->say; # prints Hello, World!
# What you can do with it after
$str->concat("How")->concat("Are")->concat->("You?")->say;
# or
$str + "How" + "Are" + "You?";
say $str->first; # get the first character
say $str->substr(0, 1); # sure, or use substr
# Splitting a string with the division operator returns an Array class
my $str = Str->new("Hello:there:world");
($str / ':')->loop(sub {
say $_;
});
# Hello
# there
# world
## Ints
my $int = Int->new(5);
say $int->val; # prints 5
# chain methods to perform math
say $int->add(5)->divide(2)->subtract(3)->mult(7);
# or
$int + 5 / 2 - 3 * 7;
## enums
use Modo;
enum Bool => ( 'True:1', 'False:0' );
# set up a couple of test methods to test against our new Boolean type
sub ok { return 1; }
sub not_ok { return 0; }
if (ok() == Bool->True) { say "We're good!"; }
if (not_ok() == Bool->False) { say "This is false"; }
## Class building
{
package MyFoo;
use Modo as => 'Class';
has 'x' => ( is => 'rw', default => 5 );
private 'secret' => sub {
say "Private method can't be called from outside of this class";
};
}
my $foo = MyFoo->new;
say $foo->x; # prints 5
$foo->x(7); # updates x to 7
say $foo->x; # prints 7
## Arrays
my $day = 'Tuesday';
my $weekdays = Array->new(qw< Monday Tuesday Wednesday Thursday Friday >);
if ($weekdays->any($day)) {
say "OK, I'll see you on $day!";
}
# or
if ($weekdays ~~ $day) { .. }
$weekdays->loop(sub {
say $_;
});
# push new arrays
my @a = qw(Saturday);
$weekdays + \@a;
# do it all inline
($weekdays + \@a)->loop(sub { say $_; });
# insert to the beginning of an Array
$weekdays << ['Sunday'];
Description
Modo is an attempt at implementing a Modern feel to perl5. Obviously this is my interpretation and yours will probably vary. It's still in its infancy at the moment, but as you can see I've borrowed a bit from perl6 and turned it into perl5. There is no source filtering or Devel::Declare stuff going on to change the syntax - it's pure perl5 and will remain that way. Yes, I know the pod sucks. Documentation isn't my best of traits.. sorry.

Comments
use autobox SCALAR => 'Str';
use Modo;
say "Hey" + " there"; # complains that it's not numeric.. but Modo's overloaded operators allows you to do this
If I do this, it works
say "Hey"->new("Hey") + " there"; # but damn that looks ugly
If there was a way to create the object properly with autobox without the need for ->new I would happily use it
If you know of a better way I'm open to suggestions.
Note that Perl 6 still has separate operators for strings (~) and numerics (+).
If you look at the github code, it's not touching UNIVERSAL at all. If you have a problem with it, don't use it. Modo isn't for everyone, but it does have a following of people who are interested to see where it is going.
Please sign up to post a review.