.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" 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::Has::Sugar 3pm" .TH MooseX::Has::Sugar 3pm "2022-06-15" "perl v5.34.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::Has::Sugar \- Sugar Syntax for moose 'has' fields .SH "VERSION" .IX Header "VERSION" version 1.000006 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use Moose; \& use MooseX::Types::Moose; \& use MooseX::Has::Sugar; \& \& has attrname => ( isa => Str, ro, required ); \& has otherattrname => ( isa => Str, rw, lazy_build ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\f(CW\*(C`MooseX::Has::Sugar\*(C'\fR and its related modules provide simple, short-hand, bare-word functions that act as declarative macros for greatly compacting \f(CW\*(C`Moose\*(C'\fR \f(CW\*(C`has\*(C'\fR declarations, in a similar way to those provided by the declarative subroutines provided by \f(CW\*(C`MooseX::Types\*(C'\fR .PP This provides: .IP "\(bu" 4 Less typing when defining \f(CW\*(C`has\*(C'\fR constraints .IP "\(bu" 4 Faster, more skim-readable blocks of \f(CW\*(C`has\*(C'\fR constraints .IP "\(bu" 4 Perl Language Level syntax validation at compile time .SH "BENEFITS" .IX Header "BENEFITS" .ie n .SS "Reduced Typing in ""has"" declarations." .el .SS "Reduced Typing in \f(CWhas\fP declarations." .IX Subsection "Reduced Typing in has declarations." The constant need to type \f(CW\*(C`=>\*(C'\fR and \f(CW\*(Aq\*(Aq\fR is fine for one-off cases, but the instant you have more than about 4 attributes it starts to get annoying. .SS "More compact declarations." .IX Subsection "More compact declarations." Reduces much of the redundant typing in most cases, which makes your life easier, and makes it take up less visual space, which makes it faster to read. .SS "No String Worries" .IX Subsection "No String Worries" Strings are often problematic, due to white-space etc. Noted that if you do happen to mess them up, Moose should at \fIleast\fR warn you that you've done something daft. Using this alleviates that worry. .SH "COMPARISONS" .IX Header "COMPARISONS" .SS "Classical Moose" .IX Subsection "Classical Moose" .Vb 5 \& has foo => ( \& isa => \*(AqStr\*(Aq, \& is => \*(Aqro\*(Aq, \& required => 1, \& ); \& \& has bar => ( \& isa => \*(AqStr\*(Aq, \& is => \*(Aqrw\*(Aq \& lazy_build => 1, \& ); .Ve .SS "Lazy Evil way to do it:" .IX Subsection "Lazy Evil way to do it:" \&\fB\s-1PLEASE DO NOT DO THIS\s0\fR .PP .Vb 2 \& has qw( foo isa Str is ro required 1 ); \& has qw( bar isa Str is rw lazy_build 1 ); .Ve .SS "With this module" .IX Subsection "With this module" ( and with MooseX::Types ) .PP .Vb 2 \& use MooseX::Types::Moose qw( Str ); \& use MooseX::Has::Sugar; \& \& has foo => ( \& isa => Str, \& ro, \& required, \& ); \& has bar => ( \& isa => Str, \& rw, \& lazy_build, \& ); .Ve .PP Or even .PP .Vb 2 \& use MooseX::Types::Moose qw( Str ); \& use MooseX::Has::Sugar; \& \& has foo => ( isa => Str, ro, required, ); \& has bar => ( isa => Str, rw, lazy_build, ); .Ve .SH "ALTERNATIVE FORMS" .IX Header "ALTERNATIVE FORMS" .ie n .SS "Basic ""is"" Expansion Only" .el .SS "Basic \f(CWis\fP Expansion Only" .IX Subsection "Basic is Expansion Only" ( using ::Sugar::Minimal instead ) .PP .Vb 2 \& use MooseX::Types::Moose qw( Str ); \& use MooseX::Has::Sugar::Minimal; \& \& has foo => ( \& isa => Str, \& is => ro, \& required => 1, \& ); \& has bar => ( \& isa => Str, \& is => rw, \& lazy_build => 1, \& ); .Ve .SS "Attribute Expansions with Basic Expansions" .IX Subsection "Attribute Expansions with Basic Expansions" ( Combining parts of this and ::Sugar::Minimal ) .PP .Vb 3 \& use MooseX::Types::Moose qw( Str ); \& use MooseX::Has::Sugar::Minimal; \& use MooseX::Has::Sugar qw( :attrs ); \& \& has foo => ( \& isa => Str, \& is => ro, \& required, \& ); \& has bar => ( \& isa => Str, \& is => rw, \& lazy_build, \& ); .Ve .SH "EXPORT GROUPS" .IX Header "EXPORT GROUPS" .ie n .SS """:default""" .el .SS "\f(CW:default\fP" .IX Subsection ":default" Since 0.0300, this exports all our syntax, the same as \f(CW\*(C`:attrs\*(C'\fR \f(CW\*(C`:isattrs\*(C'\fR. Primarily because I found you generally want all the sugar, not just part of it. This also gets rid of that nasty exclusion logic. .ie n .SS """:isattrs""" .el .SS "\f(CW:isattrs\fP" .IX Subsection ":isattrs" This exports \f(CW\*(C`ro\*(C'\fR, \f(CW\*(C`rw\*(C'\fR and \f(CW\*(C`bare\*(C'\fR as lists, so they behave as stand-alone attributes like \&\*(L"lazy\*(R" does. .PP .Vb 5 \& has foo => ( \& required, \& isa => \*(AqStr\*(Aq, \& ro, \& ); .Ve .PP \&\fB\s-1NOTE:\s0 This option is incompatible with ::Sugar::Minimal\fR : \*(L"\s-1CONFLICTS\*(R"\s0 .ie n .SS """:attrs""" .el .SS "\f(CW:attrs\fP" .IX Subsection ":attrs" This exports \*(L"lazy\*(R" , \*(L"lazy_build\*(R" and \*(L"required\*(R", \*(L"coerce\*(R", \*(L"weak_ref\*(R" and \*(L"auto_deref\*(R" as subs that assume positive. .PP .Vb 4 \& has foo => ( \& required, \& isa => \*(AqStr\*(Aq, \& ); .Ve .PP \&\fB\s-1NOTE:\s0 This option is incompatible with MooseX::Types and Moose's Type Constraints Module\fR : \*(L"\s-1CONFLICTS\*(R"\s0 .ie n .SS """:is""" .el .SS "\f(CW:is\fP" .IX Subsection ":is" \&\fB\s-1DEPRECATED\s0\fR. See ::Sugar::Minimal for the same functionality .ie n .SS """:allattrs""" .el .SS "\f(CW:allattrs\fP" .IX Subsection ":allattrs" \&\fB\s-1DEPRECATED\s0\fR, just use \*(L":default\*(R" or do .PP .Vb 1 \& use MooseX::Has::Sugar; .Ve .SH "EXPORTED FUNCTIONS" .IX Header "EXPORTED FUNCTIONS" .ie n .SS """bare""" .el .SS "\f(CWbare\fP" .IX Subsection "bare" returns \f(CW\*(C`(\*(Aqis\*(Aq,\*(Aqbare\*(Aq)\*(C'\fR .ie n .SS """ro""" .el .SS "\f(CWro\fP" .IX Subsection "ro" returns \f(CW\*(C`(\*(Aqis\*(Aq,\*(Aqro\*(Aq)\*(C'\fR .ie n .SS """rw""" .el .SS "\f(CWrw\fP" .IX Subsection "rw" returns \f(CW\*(C`(\*(Aqis\*(Aq,\*(Aqrw\*(Aq)\*(C'\fR .ie n .SS """required""" .el .SS "\f(CWrequired\fP" .IX Subsection "required" returns \f(CW\*(C`(\*(Aqrequired\*(Aq,1)\*(C'\fR .ie n .SS """lazy""" .el .SS "\f(CWlazy\fP" .IX Subsection "lazy" returns \f(CW\*(C`(\*(Aqlazy\*(Aq,1)\*(C'\fR .ie n .SS """lazy_build""" .el .SS "\f(CWlazy_build\fP" .IX Subsection "lazy_build" returns \f(CW\*(C`(\*(Aqlazy_build\*(Aq,1)\*(C'\fR .ie n .SS """weak_ref""" .el .SS "\f(CWweak_ref\fP" .IX Subsection "weak_ref" returns \f(CW\*(C`(\*(Aqweak_ref\*(Aq,1)\*(C'\fR .ie n .SS """coerce""" .el .SS "\f(CWcoerce\fP" .IX Subsection "coerce" returns \f(CW\*(C`(\*(Aqcoerce\*(Aq,1)\*(C'\fR .PP \&\fB\s-1WARNING:\s0\fR Conflict with MooseX::Types and Moose::Util::TypeConstraints, see \*(L"\s-1CONFLICTS\*(R"\s0. .ie n .SS """auto_deref""" .el .SS "\f(CWauto_deref\fP" .IX Subsection "auto_deref" returns \f(CW\*(C`(\*(Aqauto_deref\*(Aq,1)\*(C'\fR .SH "CONFLICTS" .IX Header "CONFLICTS" .SS "MooseX::Has::Sugar::Minimal" .IX Subsection "MooseX::Has::Sugar::Minimal" .SS "MooseX::Has::Sugar::Saccharin" .IX Subsection "MooseX::Has::Sugar::Saccharin" This module is not intended to be used in conjunction with ::Sugar::Minimal or ::Sugar::Saccharin .PP We export many of the same symbols and its just not very sensible. .SS "MooseX::Types" .IX Subsection "MooseX::Types" .SS "Moose::Util::TypeConstraints" .IX Subsection "Moose::Util::TypeConstraints" due to exporting the \*(L"coerce\*(R" symbol, using us in the same scope as a call to .PP .Vb 1 \& use MooseX::Types .... .Ve .PP or use Moose::Util::TypeConstraints .PP will result in a symbol collision. .PP We recommend using and creating proper type libraries instead, ( which will absolve you entirely of the need to use MooseX::Types and MooseX::Has::Sugar(::*)? in the same scope ) .SH "AUTHOR" .IX Header "AUTHOR" Kent Fredric .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2017 by Kent Fredric . .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.