NAME

Mojo::Base - Minimal Base Class For Mojo Projects

SYNOPSIS

    package Car;
    use base 'Mojo::Base';

    __PACKAGE__->attr('driver');
    __PACKAGE__->attr('doors' => 2);
    __PACKAGE__->attr([qw/passengers seats/] => sub { 2 });

    package main;

    my $bmw = Car->new;
    print $bmw->doors;
    print $bmw->doors(5)->doors;

    my $mercedes = Car->new(driver => 'Sebastian');
    print $mercedes->passengers(7)->passengers;

DESCRIPTION

Mojo::Base is a simple base class for Mojo projects.

METHODS

new

    my $instance = BaseSubClass->new;
    my $instance = BaseSubClass->new(name => 'value');
    my $instance = BaseSubClass->new({name => 'value'});

This base class provides a basic object constructor. You can pass it either a hash or a hash reference with attribute values.

attr

    __PACKAGE__->attr('name');
    __PACKAGE__->attr([qw/name1 name2 name3/]);
    __PACKAGE__->attr(name => 'foo');
    __PACKAGE__->attr(name => sub { ... });
    __PACKAGE__->attr([qw/name1 name2 name3/] => 'foo');
    __PACKAGE__->attr([qw/name1 name2 name3/] => sub { ... });

Create attributes. An arrayref can be used to create more than one attribute. Pass an optional second argument to set a default value, it should be a constant or a sub reference. The sub reference will be excuted at accessor read time if there's no set value.

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicious.org.