| MooseX-Has-Sugar documentation | Contained in the MooseX-Has-Sugar distribution. |
MooseX::Has::Sugar::Saccharin - Experimental sweetness
version 0.05070419
This is a highly experimental sugaring module. No Guarantees of stability.
use MooseX::Types::Moose qw( :all );
has name => rw Str, default { 1 };
has suffix => required rw Str;
has 'suffix', required rw Str;
Your choice.
exports ro, rw, required, lazy, lazy_build, coerce, weak_ref, auto_deref,bare, default, init_arg, predicate, clearer, builder, trigger,
bare Str
equivalent to this
is => 'bare', isa => Str
ro Str
equivalent to this
is => 'ro', isa => Str,
rw Str
equivalent to this
is => 'rw', isa => Str
this
required rw Str
is equivalent to this
required => 1, is => 'rw', isa => Str,
this
rw Str, required
is equivalent to this
is => 'rw', isa => Str , required => 1
like ( lazy => 1 , @rest )
like ( lazy_build => 1, @rest )
like ( weak_ref => 1, @rest )
like ( coerce => 1, @rest )
Conflicts with MooseX::Types's coerce method|MooseX::Types/coerce
like ( auto_deref => 1, @rest )
required rw Str, builder '_build_foo'
is like
builder => '_build_foo'
see builder
see builder
see builder
Examples:
default { 1 }
default { { } }
default { [ ] }
default { $_->otherfield }
$_ is localised as the same value as $_[0] for convenience ( usually $self )
Works exactly like default.
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.
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 )
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.
Kent Fredric <kentnl at cpan.org>
This software is copyright (c) 2011 by Kent Fredric.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
| MooseX-Has-Sugar documentation | Contained in the MooseX-Has-Sugar distribution. |
use warnings; use strict; package MooseX::Has::Sugar::Saccharin; BEGIN { $MooseX::Has::Sugar::Saccharin::VERSION = '0.05070419'; } # ABSTRACT: Experimental sweetness use Carp (); use Sub::Exporter (); Sub::Exporter::setup_exporter( { exports => [ 'ro', 'rw', 'required', 'lazy', 'lazy_build', 'coerce', 'weak_ref', 'auto_deref', 'bare', 'default', 'init_arg', 'predicate', 'clearer', 'builder', 'trigger', ], groups => { default => ['-all'], } } ); sub bare($) { return ( 'is', 'bare', 'isa', shift, ); } sub ro($) { return ( 'is', 'ro', 'isa', shift, ); } sub rw($) { return ( 'is', 'rw', 'isa', shift, ); } sub required(@) { return ( 'required', 1, @_ ); } sub lazy(@) { return ( 'lazy', 1, @_ ); } sub lazy_build(@) { return ( 'lazy_build', 1, @_ ); } sub weak_ref(@) { return ( 'weak_ref', 1, @_ ); } sub coerce(@) { return ( 'coerce', 1, @_ ); } sub auto_deref(@) { return ( 'auto_deref', 1, @_ ); } sub builder($) { return ( 'builder', shift ); } sub predicate($) { return ( 'predicate', shift ); } sub clearer($) { return ( 'clearer', shift ); } sub init_arg($) { return ( 'init_arg', shift ); } ## no critic (ProhibitBuiltinHomonyms) sub default(&) { my $code = shift; return ( 'default', sub { my $self = $_[0]; local $_ = $self; return $code->(); } ); } sub trigger(&) { my $code = shift; return ( 'trigger', sub { my $self = $_[0]; local $_ = $self; return $code->(); } ); } 1; __END__