NAME
Mite::Manual::Features - other features provided by Mite
MANUAL
Class Methods
Your class can or will provide the following methods:
new( %attributes )
or new( \%attributes )
Constructor for your class. It takes some arguments and returns an object.
Mite generates this for you.
Mite automatically provides a similar feature to MooseX::StrictConstructor, so your constructor will die if you pass it unknown attributes.
BUILDARGS
Works as in Moose and allows your constructor to be called with something other than a hash of attributes. Mite does not generate this for you.
FOREIGNBUILDARGS
Works as in Moo and MooseX::NonMoose. Mite does not generate this for you.
BUILD
/ BUILDALL
.
Works as in Moose. Mite generates BUILDALL
for you.
From Mite 0.007004 onwards, your BUILD
method gets called before the strict constructor check, which allows you to remove keys from $args
if you don't want them to trigger an exception.
DEMOLISH
/ DESTROY
Works as in Moose. Mite generates DESTROY
for you.
On Perl older than 5.14, the $in_global_destruction
argument will be undefined unless Devel::GlobalDestruction is installed, so add that to your project's dependencies if you are relying on it and need to support older versions of Perl.
DOES
/ does
DOES
allows you to check if your class/object performs a particular role. See UNIVERSAL.
does
is just an alias.
If you want to fake support for a role:
$Your::Project::SomeClass::DOES{'Your::Project::SomeRole'} = 1;
strict
Mite will turn strict on for you.
warnings
Mite will turn warnings on for you.
Clean Classes
Mite will automatically import namespace::autoclean into your classes if it is installed on the end user's system. If it's not available, your classes will quietly be left with imported keywords cluttering up their namespace.
To force namespace::autoclean, then just use it manually:
use Your::Project::Mite;
use namespace::autoclean;
To force it to not be used:
use Your::Project::Mite qw( -unclean );
Autolax
Autolax mode can be enabled in your .mite/config file:
autolax: 1
If you do that and recompile your project, then many of the sanity checks Mite builds into your constructors, accessors, and method signatures will be disabled by default. In lax mode, these checks will be disabled:
MooseX::StrictConstructor-style checks for unknown named parameters passed to your constructor.
Checks for unknown named parameters passed to method signatures.
Type checks in your constructor, except as part of coercion.
Type checks in accessors and writers, except as part of coercion.
Type checks in method signatures, except as part of coercion.
Argument count checks in readers, writers, accessors, lvalue accessors, clearers, and predicates.
Argument count checks in method signatures.
However, while the checks become disabled, they can be re-enabled by the end user by setting the PERL_STRICT
environment variable, or any other environment variable supported by Devel::StrictMode.
The idea is that if your project uses autolax, you can set PERL_STRICT
in your testing environment to get more rigorous checks, fix any errors you find, and then run your code without PERL_STRICT
in your production environment.
Run-Time Role Application
If you add the -runtime
option when creating a Mite role:
package Your::Project::SomeRole;
use Your::Project::Mite -role, -runtime;
Then your role will include a couple of functions:
# Applies the role to an existing object
#
Your::Project::SomeRole::APPLY_TO( $object );
# Applies the role to an existing class
#
Your::Project::SomeRole::APPLY_TO( 'Some::Class' );
# Applies the role to an existing class, but does not modify the
# existing class.
#
my $new_class = Your::Project::SomeRole::CREATE_CLASS( 'Some::Class' );
As this functionality is relatively heavy, it is not included in roles by default, which is why the -runtime
option is needed as a way to opt in.
When applying a role to an existing class, the class's constructor will not be modified, so any attributes defined in the role will only be available to get and set via accessor methods.
BUGS
Please report any bugs to https://github.com/tobyink/p5-mite/issues.
AUTHOR
Michael G Schwern <mschwern@cpan.org>.
Toby Inkster <tobyink@cpan.org>.
COPYRIGHT AND LICENCE
This software is copyright (c) 2011-2014 by Michael G Schwern.
This software is copyright (c) 2022 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
DISCLAIMER OF WARRANTIES
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.