MooseX::OneArgNew(3)
πΈ NAME πΈ
okay bestie, welcome to the User Contributed Perl Documentation page for MooseX::OneArgNew(3) π β this is all about MooseX::OneArgNew, which exists to teach ->new to accept single, non-hashref arguments. iconic behavior, honestly.
π VERSION π
version 0.007 β yes, that's the actual number, no cap.
β¨ SYNOPSIS β¨
So in our class definition, you'd do this whole thing:
package Delivery;
use Moose;
with('MooseX::OneArgNew' => {
type => 'Existing::Message::Type',
init_arg => 'message',
});
has message => (isa => 'Existing::Message::Type', required => 1);
has to => (
is => 'ro',
isa => 'Str',
lazy => 1,
default => sub {
my ($self) = @_;
$self->message->get('To');
},
);
Then when you're making a message, you've got options, bestie:
# The traditional way:
my $delivery = Delivery->new({ message => $message });
# or
my $delivery = Delivery->new({ message => $message, to => $to });
# With one-arg new:
my $delivery = Delivery->new($message);
π¦ DESCRIPTION π¦
MooseX::OneArgNew lets your constructor take a single argument, and that argument gets translated into the value for a one-entry hashref. It's a parameterized role with three parameters, and they are:
typeβ this is the Moose type that the single argument has to be for the one-arg form to work. It should be an existing type, and it may be either a string type or aMooseX::Type.init_argβ this is the string that will be used as the key for the hashref constructed from the one-arg call tonew.coerceβ if true, a single argument tonewwill be coerced into the expected type if possible. Keep in mind that if there are no coercions for the type, this will be an error, and that if a coercion fromHashRefexists, you might be getting yourself into a weird situation. π«
β οΈ WARNINGS β οΈ
Okay so listen: you can apply MooseX::OneArgNew more than once, but if more than one application's type matches a single argument to "new", the behavior is undefined and likely to cause bugs. not cute. π
Also, it would be a very bad idea to supply a type that could accept a normal hashref of arguments to "new". like, genuinely do not do that.
π PERL VERSION π
This module should work on any version of perl still receiving updates from the Perl 5 Porters. This means it should work on any version of perl released in the last two to three years. (That is, if the most recently released version is v5.40, then this module should work on both v5.40 and v5.38.)
Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl.
π AUTHOR π
Ricardo Signes <cpan@semiotic.systems> β main character energy, honestly. π
π CONTRIBUTORS π
- George Hartzell <hartzell@alerce.com>
- Ricardo Signes <rjbs@semiotic.systems>
- William Orr <will@worrbase.com>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2022 by Ricardo Signes.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie π β MooseX::OneArgNew(3), version 0.007, rendered from perl v5.42.0 on 2023-01-02. slay, go forth and one-arg responsibly π¦β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-MooseX-OneArgNew 0.007-bp160.1.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms