Mite::Manual::Missing - major Moose features not supported by Mite
Mite doesn't support native attribute traits (i.e. delegating to non-objects). However, you can accomplish this by using Sub::HandlesVia 0.026 or above. You need to make sure the Mite shim is loaded before Sub::HandlesVia, and this will add an extra dependency to your project.
package Your::Project::Class; use Your::Project::Mite; use Sub::HandlesVia; has numbers => ( is => 'lazy', builder => sub { [] }, isa => 'ArrayRef[Int]', handles_via => 'Array', handles => { add_number => 'push', pop_number => 'pop', }, ); 1;
Your constructor, destructor, and accessors are build on the developer's machine when mite compile is run, rather than at run-time on the end user's machine like Moose, Mouse, and Moo do. Role application is mostly performed during mite compile too, with the exception of applying method modifiers, and checking that requires is satisfied, which happens at run-time.
mite compile
requires
This means any run-time logic used to construct your classes and roles is unlikely to work. As an example:
package Your::Project::SomeClass; use Your::Project::Mite; if ( $ENV{YOUR_PROJECT_DEBUG} ) { with 'Your::Project::Trait::Verbose'; } ...; 1;
Best case scenario, this will work, but it's the value of YOUR_PROJECT_DEBUG on the developer's machine when they run mite compile which is honoured, and becomes hard-coded into the generated class. Worst case scenario, things break in interesting and unusual ways.
YOUR_PROJECT_DEBUG
Logic which is guaranteed to run the same on both the developer's machine and the end user's machine should be fine. For example, this should be fine:
for my $attr ( qw( foo bar baz ) ) { has $attr => ( reader => "get_$attr", writer => "set_$attr", ); }
However Mite provides a lot of shortcuts which Moose doesn't, so you're less likely to need that sort of logic anyway. You could just write:
has [ qw( foo bar baz ) ] => ( reader => 'get_%s', writer => 'set_%s', );
Or even:
has [ qw( foo bar baz ) ] => ( reader => true, writer => true, );
And it will work the same!
If you do need to be able to construct your classes and roles at run time, switch to Moose or Moo.
Please report any bugs to https://github.com/tobyink/p5-mite/issues.
Michael G Schwern <mschwern@cpan.org>.
Toby Inkster <tobyink@cpan.org>.
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.
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.
To install Mite, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mite
CPAN shell
perl -MCPAN -e shell install Mite
For more information on module installation, please visit the detailed CPAN module installation guide.