Mojo::Base - Minimal Base Class For Mojo Projects
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;
Mojo::Base is a simple base class for Mojo projects.
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.
Mojolicious, Mojolicious::Book, http://mojolicious.org.
To install Mojolicious, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious
CPAN shell
perl -MCPAN -e shell install Mojolicious
For more information on module installation, please visit the detailed CPAN module installation guide.