Moose: Perl module that extends the Perl 5 object system to make programming easier, more consistent, and less tedious

http://search.cpan.org/~ether/Moose-2.1402/lib/Moose.pm

This module has me interested in writing some Perl code for the first time in years. I’m going to check this out.

Example from perldocs:

package Person;

use Moose;

has 'first_name' => (
    is  => 'rw',
    isa => 'Str',
);

has 'last_name' => (
    is  => 'rw',
    isa => 'Str',
);

no Moose;
__PACKAGE__->meta->make_immutable;

This is a complete and usable class definition!

package User;

use DateTime;
use Moose;

extends 'Person';

has 'password' => (
    is  => 'rw',
    isa => 'Str',
);

has 'last_login' => (
    is      => 'rw',
    isa     => 'DateTime',
    handles => { 'date_of_last_login' => 'date' },
);

sub login {
    my $self = shift;
    my $pw   = shift;

    return 0 if $pw ne $self->password;

    $self->last_login( DateTime->now() );

    return 1;
}

no Moose;
__PACKAGE__->meta->make_immutable;

When ready to instantiate your class in an application, use it in the “traditional” Perl manner:

use User;

my $user = User->new(
  first_name => 'Example',
  last_name  => 'User',
  password   => 'letmein',
);

$user->login('letmein');

say $user->date_of_last_login;