-
-
06 Jul 2016 22:11:23 UTC
- Distribution: Mo
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues (12)
- Testers (8969 / 7 / 0)
- Kwalitee
Bus factor: 2- 93.85% Coverage
- License: perl_5
- Perl: v5.6.0
- Activity
24 month- Tools
- Download (39.19KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
- Dependencies
- none
- Reverse dependencies
- CPAN Testers List
- Dependency graph
Name
Mo::default - Adds the default feature to Mo's has
Synopsis
use Mo qw'default'; has job => ( default => 'Killer' ); has name => ( default => sub { 'Joe' } ); has age => 42; has colors => [ 'green', 'blue' ];
Description
Adds the default parameter to has, which expects a value. If the value is a code ref, it is called to produce the default. If the value is a hash or array ref, then a shallow copy is made for the default. If there is an odd number of arguments after the attribute name, then the first value is the default.
These 3 lines are the same:
has things => default => sub {+{}}; has things => default => {}; has things => {};
Laziness
Default attribute values in Mo are lazy by default. This can be changed by explicitly setting the
lazy
argument to false, in order to cause it to be initialized during instantiation.use Mo qw'default'; has status => 'active'; # lazy has location => sub { ... }, lazy => 1; # lazy has target => sub { ... }, lazy => 0; # eager
To change the default behavior and make attributes to be initialized eagerly by default, import
nonlazy
.use Mo qw'default nonlazy'; has status => 'active'; # eager has location => sub { ... }, lazy => 1; # lazy has target => sub { ... }, lazy => 0; # eager
Module Install Instructions
To install Mo, copy and paste the appropriate command in to your terminal.
cpanm Mo
perl -MCPAN -e shell install Mo
For more information on module installation, please visit the detailed CPAN module installation guide.