.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "MooseX::OneArgNew 3pm" .TH MooseX::OneArgNew 3pm "2023-01-07" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" MooseX::OneArgNew \- teach \->new to accept single, non\-hashref arguments .SH "VERSION" .IX Header "VERSION" version 0.007 .SH "SYNOPSIS" .IX Header "SYNOPSIS" In our class definition: .PP .Vb 6 \& package Delivery; \& use Moose; \& with(\*(AqMooseX::OneArgNew\*(Aq => { \& type => \*(AqExisting::Message::Type\*(Aq, \& init_arg => \*(Aqmessage\*(Aq, \& }); \& \& has message => (isa => \*(AqExisting::Message::Type\*(Aq, required => 1); \& \& has to => ( \& is => \*(Aqro\*(Aq, \& isa => \*(AqStr\*(Aq, \& lazy => 1, \& default => sub { \& my ($self) = @_; \& $self\->message\->get(\*(AqTo\*(Aq); \& }, \& ); .Ve .PP When making a message: .PP .Vb 1 \& # 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); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" MooseX::OneArgNew lets your constructor take a single argument, which will be translated into the value for a one-entry hashref. It is a parameterized role with three parameters: .IP "type" 4 .IX Item "type" The Moose type that the single argument must be for the one-arg form to work. This should be an existing type, and may be either a string type or a MooseX::Type. .IP "init_arg" 4 .IX Item "init_arg" This is the string that will be used as the key for the hashref constructed from the one-arg call to new. .IP "coerce" 4 .IX Item "coerce" If true, a single argument to new will 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 from HashRef exists, you might be getting yourself into a weird situation. .SS "\s-1WARNINGS\s0" .IX Subsection "WARNINGS" You can apply MooseX::OneArgNew more than once, but if more than one application's type matches a single argument to \f(CW\*(C`new\*(C'\fR, the behavior is undefined and likely to cause bugs. .PP It would be a \fBvery bad idea\fR to supply a type that could accept a normal hashref of arguments to \f(CW\*(C`new\*(C'\fR. .SH "PERL VERSION" .IX Header "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.) .PP 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. .SH "AUTHOR" .IX Header "AUTHOR" Ricardo Signes .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" .IP "\(bu" 4 George Hartzell .IP "\(bu" 4 Ricardo Signes .IP "\(bu" 4 William Orr .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2022 by Ricardo Signes. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.