NAME
Mooish::Base - importer for Mooish classes
SYNOPSIS
# for classes
use Mooish::Base;
# for roles
use Mooish::Base -role;
# create your class / role as usual
DESCRIPTION
This module is a shortcut that does roughly the same as calling these imports:
use Moo;
use Mooish::AttributeBuilder;
use Types::Common -types;
use namespace::autoclean;
# additional optional modules, if they are installed
If a -role flag is specified, then the module imports Moo::Role instead.
Environmental variables MOOISH_BASE_FLAVOUR and MOOISH_BASE_ROLE_FLAVOUR can be used to modify class and role systems used. If not present, Moo and Moo::Role will be used respectively. Make sure to introduce these variables before first loading the module.
The purpose of this module is to make it easier to create classes based on Moose family of modules. The choice of imported modules is meant to provide a solid base for module development, but still be perfectly compatible at least with Moose, Mouse and Moo.
Extra modules or features loaded
Depending on MOOISH_BASE_FLAVOUR some extra modules will be imported (if installed). Only modules which do not change the behavior will ever be added to this list - mostly modules which improve performance for free.
MOOISH_BASE_EXTRA_MODULES environmental variable can be declared to control which extra modules should be used. It must contain a semicolon-separated a list of modules to be loaded, for example MooX::TypeTiny;MooX::XSConstructor. It must be set prior to first loading the module to take effect. Normally, it should not be needed, but may be a helpful workaround if one of these modules contain a bug which causes the resulting class to misbehave.
Moo
-
This module speeds up Type::Tiny checks in Moo code.
minimum required version: 0.002002
-
This module attempts to use Class::XSConstructor to speed up the constructor.
minimum required version: 0.003002
Moose
-
This module attempts to use Class::XSConstructor to speed up the constructor.
minimum required version: 0.001002
-
This module attempts to use Class::XSAccessor to speed up the accessors.
minimum required version: 0.010
-
Since the module attempts to deliver a unified API for each flavour of Moose, Moose itself must be made immutable automatically after the class is built. This is done with the help of this module. Mooish::Base will warn if this module is not installed and Moose flavour is used.
minimum required version: 0.003
Debugging
Mooish::Base can be debugged by setting $Mooish::Base::DEBUG prior to loading a class. This package variable should be set to a hash reference. If it is, it will fill it up with keys for each loaded class or role. An example debug code will look like that:
BEGIN {
require Mooish::Base;
$Mooish::Base::DEBUG = {};
}
package MyClass;
use Mooish::Base;
use Data::Dumper;
print Dumper($Mooish::Base::DEBUG);
Example output:
$VAR1 = {
'MyClass' => {
'class_type' => 'Moo',
'role_type' => 'Moo::Role',
'role' => !!0,
'standard' => !!0
'extra_modules' => {
'MooX::TypeTiny' => !!1,
'MooX::XSConstructor' => !!0,
'Hook::AfterRuntime' => !!0,
'MooseX::XSConstructor' => !!0,
'MooseX::XSAccessor' => !!0
},
}
};
If more classes are loaded then more keys will appear in the debug hash, allowing to easily check what was loaded and where.
For module authors
If you wish to use Mooish::Base in your module, please use it with -standard flag. This flag will prevent custom behavior from propagating into the module. The idea is to have a solid base OO for module development while making sure that it won't break when users add custom settings.
Currently, it will ensure that:
Mooish::AttributeBuilder will be imported with
-standardflag (no user-defined shortcuts). (in effect since version 1.000)Moo and Moo::Role will be used regardless of the environment variables. (in effect since version 1.001)
SEE ALSO
AUTHOR
Bartosz Jarzyna <bbrtj.pro@gmail.com>
COPYRIGHT AND LICENSE
Copyright (C) 2025 by Bartosz Jarzyna
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.