GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  MO::DEFAULT (3)

.ds Aq ’

Name

Mo::default - Adds the default feature to Mo’s has

CONTENTS

Synopsis



    use Mo qwdefault;
    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 qwdefault;
    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 qwdefault nonlazy;
    has status   => active;                 # eager
    has location => sub { ... }, lazy => 1;   # lazy
    has target   => sub { ... }, lazy => 0;   # eager



Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 MO::DEFAULT (3) 2014-09-04

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.