MooseX:...ncludes(3)
πΈ NAME πΈ
MooseX::Extended::Manual::Includes β it's giving "an overview of MooseX::Extended optional features", bestie π
β¨ VERSION β¨
version 0.35 π
π«Ά DESCRIPTION π«Ά
okay so lowkey the section heading up in here got chopped off mid-sentence and the manpage literally opens with the fragment:
includes"
we respect the fragment π anyway, moving on:
Some experimental features are useful, but might not be quite what you want.
By default, MooseX::Extended tries to be relatively conservative. But bestie, you might want to turn it up to 11. There are optional, EXPERIMENTAL features you can use for this. They're turned on by the includes flag. π
π "method"
package My::Names {
use MooseX::Extended types => [qw(compile NonEmptyStr Str )],
includes => 'method';
param _name => ( isa => NonEmptyStr, init_arg => 'name' );
param title => ( isa => Str, required => 0, predicate => 1 );
method name() {
my $title = $self->title; # $self is injected for you
my $name = $self->_name;
return $title ? "$title $name" : $name;
}
}
Adds a method keyword and injects $self into the method body. Requires Function::Parameters. π¦
Note: this is equivalent to writing:
use Function::Parameters 'method';
The other features of Function::Parameters are not available by default, but see "Fine-Tuning Your Includes" below. π
This feature does not work with the optional multi keyword. Thus, if you do this:
use MooseX::Extended includes => [qw/multi method/];
You cannot do multi method. You'll have to fall back to multi sub. π no cap, that's just how it is.
π "multi"
use MooseX::Extended includes => 'multi';
multi sub foo ($self, $x) { ... }
multi sub foo ($self, $x, $y ) { ... }
Note: this is equivalent to writing:
use Syntax::Keyword::MultiSub;
Allows you to redeclare a method (or subroutine) and the dispatch will use the number of arguments to determine which subroutine to use. Note that "slurpy" arguments such as arrays or hashes will take precedence over scalars if they are declared first:
multi sub foo ($self, @x) { ... }
multi sub foo ($self, $x) { ... } # will never be called
Thus, the following probably doesn't do what you want. π
package Foo {
use MooseX::Extended includes => 'multi';
multi sub foo ($self, @bar) { return '@bar' }
multi sub foo ($self, $bar) { return '$bar' }
}
say +Foo->new->foo(1);
say +Foo->new->foo(1,2,3);
Both of the above will print the string @bar. The second definition of foo is effectively lost. π
You must declare slurpy methods last for them to work correctly:
multi sub foo ($self, $bar) { return '$bar' }
multi sub foo ($self, @bar) { return '@bar' }
See https://rt.cpan.org/Ticket/Display.html?id=144171 for more information. π₯
Only available on Perl v5.26.0 or higher. Requires Syntax::Keyword::MultiSub. β
This feature does not work with the optional method keyword. Thus, if you do this:
use MooseX::Extended includes => [qw/multi method/];
You cannot do multi method. You'll have to fall back to multi sub. (same energy as before, bestie, it's a whole thing)
π§ "async"
package My::Thing {
use MooseX::Extended
types => 'Str',
includes => 'async';
use IO::Async::Loop;
field output => ( is => 'rw', isa => Str, default => '' );
async sub doit ( $self, @list ) {
my $loop = IO::Async::Loop->new;
$self->output('> ');
foreach my $item (@list) {
await $loop->delay_future( after => 0.01 );
$self->output( $self->output . "$item " );
}
}
}
Note: this is equivalent to writing:
use Future::AsyncAwait;
Allows you to write asynchronous code with async and await. π¦β¨
Only available on Perl v5.26.0 or higher. Requires Future::AsyncAwait. β
π "try"
package My::Try {
use MooseX::Extended includes => 'try';
sub reciprocal ( $self, $num ) {
try {
return 1 / $num;
}
catch ($e) {
croak "Could not calculate reciprocal of $num: $e";
}
}
}
Note: this is equivalent to writing:
use Syntax::Keyword::Try;
Allows you to use try/catch blocks, via Syntax::Keyword::Try. π
Only available on Perl v5.24.0 or higher. Requires Syntax::Keyword::Try. β
If you have Perl v5.35.8 or above, Syntax::Keyword::Try is not loaded and instead we use the native try syntax available in Perl. π
π Fine-Tuning Your Includes π
Some of the features rely on modules that are customizable via import lists when you use them. Instead of accepting our defaults, you can pass your own by passing a hashref to includes. Each key must be the name of a feature you can include and each value must be undef or an array reference that will be expanded to an import list for the module:
package My::Import::List {
use MooseX::Extended types => 'is_PositiveOrZeroInt',
includes => {
method => [qw/method fun/],
try => undef,
};
use List::Util 'sum';
method fac($n) { return _fac($n) }
fun _fac($n) {
is_PositiveOrZeroInt($n) or die "Don't do that!";
return 1 if $n < 2;
return $n * _fac $n - 1;
}
}
The above would be equivalent to writing:
use Function::Parameters qw(method fun);
use Syntax::Keyword::Try;
See the underlying module providing each feature to understand what arguments you can pass to the import lists. π
π AUTHOR π
Curtis "Ovid" Poe <curtis.poe@gmail.com> π«Ά
π COPYRIGHT AND LICENSE π
This software is Copyright (c) 2022 by Curtis "Ovid" Poe.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
and that's the whole thing, bestie, slay π
This page is from perl v5.42.0, dated 2025-07-25, and yes it's MooseX::Extended::Manual::Includes β go forth and include responsibly πΈπβ¨
π¦ where this page comes from
- fedora 43: perl-MooseX-Extended 0.35-6.fc43 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms