NAME

Mite::Manual::Keywords - functions exported by Mite

MANUAL

To start a class:

use Your::Project::Mite;

If you need to provide additional options:

use Your::Project::Mite qw( some options );

To start a role:

use Your::Project::Mite -role;

Or with additional options:

use Your::Project::Mite qw( -role some options );

Options which look like words are requesting the import of a keyword of that name. For example, this imports a keyword called lazy:

use Your::Project::Mite qw( lazy );

Options which start with an exclamation mark are the negation of that. For example to unrequest lazy:

use Your::Project::Mite qw( !lazy );

Options starting with a hyphen are either a bundle of keywords, or are a pragma which affect your class as a whole.

By default, classes get the has, extends, with, before, after, and around keywords imported into them.

By default, roles get has, requires, with, before, after, and around keywords imported into them.

The -all flag imports everything possible.

has $name => %spec

Like has in Moose, this declares one or more attributes. See Mite::Manual::Attributes for further details.

extends @parents

Declares the parent classes for your class.

You cannot use extends from within roles.

Options hashrefs, including the -version option supported by Moose are not implemented.

Multiple inheritance is supported if you're inheriting from Mite classes within your project. Single inheritance is supported if you're inheriting from a "foreign" class, as long as it uses a blessed hashref. (Multiple inheritance may in some cases work.)

requires @methods

Works as in Moose.

You cannot use requires from within classes.

with @roles

Works as in Moose.

Roles must be Mite roles created in your own project, or Role::Tiny roles. Mite does not support using roles from other projects, or using role implementations other than Mite and Role::Tiny.

Options hashrefs, including the -version option are not implemented.

param and field keywords

The param and field keywords are available, like MooseX::Extended. These act as an alternative to has.

use Your::Project::Mite qw( param field !has );

param foo => ( isa => 'Str' );

Method Modifiers

Basic versions of the before, around, and after method modifiers are provided, but these may run in a different order from Moose if you use several modifiers on the same method.

Boolean constants

Although they're not imported by default, you can import true and false keywords. They can made attribute definitions a little prettier:

use Your::Project::Mite qw( true false );
# OR:
use Your::Project::Mite qw( -bool );

has foo => (
    is => 'rw',
    required => true,
);

Constants for "is"

You can export constants called ro, rw, rwp, bare, and lazy. Again, these can make attribute definitions prettier:

use Your::Project::Mite qw( ro rw -bool );
# OR:
use Your::Project::Mite qw( -is -bool );

has foo => ( is => rw, required => true );

carp, croak, and confess

These functions can be exported to your class:

use Your::Project::Mite qw( croak );

sub my_method {
    croak 'Not implemented yet';
}

The functions provided are superpowered versions of the ones from Carp. If called with multiple arguments, the first is treated as a format string for sprintf and the remainder are passed through Data::Dumper if they are references.

sub my_method {
    my $self = shift;
    croak '%s does not implement this method', ref( $self );
}

blessed

blessed from Scalar::Util can also be imported.

use Your::Project::Mite qw( blessed );

guard

A function similar to guard from Scope::Guard can be imported.

use Your::Project::Mite qw( guard );

# Says "Hello world"
do {
    my $guard = sub { print "world\n" };
    print "Hello ";
};

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.