MooseX...ccharin(3pm)
π MooseX::Has::Sugar::Saccharin π
okay bestie, so this page is from the User Contributed Perl Documentation collection, and the module we're stanning today is MooseX::Has::Sugar::Saccharin. yes the name is long. yes it's worth it. π
β¨ VERSION β¨
we're on version 1.000006 babes π
πΈ SYNOPSIS πΈ
so like, real talk: this is a highly experimental sugaring module. there are no guarantees of stability. none. zero. it's giving chaos but make it fashion π
use MooseX::Types::Moose qw( :all );
has name => rw Str, default { 1 };
has suffix => required rw Str;
has 'suffix', required rw Str;
Your choice. pick your fighter π«Ά
π EXPORT GROUPS π
:default
this one exports:
"ro", "rw", "required", "lazy", "lazy_build", "coerce", "weak_ref",
"auto_deref", "bare", "default", "init_arg", "predicate", "clearer",
"builder", "trigger"
π¦ EXPORTED FUNCTIONS π¦
bare
bare $Type
bare Str
is literally equivalent to this:
is => 'bare', isa => Str
ro
ro $Type
ro Str
is equivalent to this:
is => 'ro', isa => Str,
rw
rw $Type
rw Str
is equivalent to this:
is => 'rw', isa => Str
required
required @rest
this:
required rw Str
is equivalent to this:
required => 1, is => 'rw', isa => Str,
and this:
rw Str, required
is equivalent to this:
is => 'rw', isa => Str , required => 1
no cap, it just slots itself wherever you put it π₯
lazy
lazy @rest
like ( lazy => 1 , @rest )
lazy_build
lazy_build @rest
like ( lazy_build => 1, @rest )
weak_ref
weak_ref @rest
like ( weak_ref => 1, @rest )
coerce
coerce @rest
like ( coerce => 1, @rest )
β οΈ WARNING: this conflicts withMooseX::Types'scoercemethod. π
auto_deref
auto_deref @rest
like ( auto_deref => 1, @rest )
builder
builder $buildername
required rw Str, builder '_build_foo'
is like:
builder => '_build_foo'
predicate
predicate $predicatename
see builder π
clearer
clearer $clearername
see builder π
init_arg
init_arg $argname
see builder π
default
default { $code }
Examples, bestie:
default { 1 }
default { { } }
default { [ ] }
default { $_->otherfield }
and here's the cute part: $_ is localized as the same value as $_[0] for convenience ( usually $self ) β¨
trigger
trigger { $code }
Works exactly like default.
π CONFLICTS π
MooseX::Has::Sugar and MooseX::Has::Sugar::Minimal
This module is not intended to be used in conjunction with ::Sugar or ::Sugar::Minimal.
We export many of the same symbols and its just not very sensible. π
MooseX::Types and Moose::Util::TypeConstraints
due to exporting the coerce symbol, using us in the same scope as a call to
use MooseX::Types ....
or
use Moose::Util::TypeConstraints
will result in a symbol collision. π
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 )
Perl 5.010 feature 'switch'
the keyword default becomes part of Perl in both these cases:
use 5.010;
use feature qw( :switch );
As such, we can't have that keyword in that scenario. π
π AUTHOR π
Kent Fredric <kentnl@cpan.org>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2017 by Kent Fredric <kentfredric@gmail.com>.
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 π«Ά this was documented with perl v5.34.0, dated 2022-06-15, straight outta the MooseX...ccharin(3pm) manpage. go forth and sugar responsibly, mwah πβ¨π
π¦ where this page comes from
- debian bookworm: libmoosex-has-sugar-perl 1.000006-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmoosex-has-sugar-perl 1.000006-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmoosex-has-sugar-perl 1.000006-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmoosex-has-sugar-perl 1.000006-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmoosex-has-sugar-perl 1.000006-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms