Enlightened Perl Organization
/kent/moose/has

package foo;

use Moose;

has <-->

About

  1. Creates an object property ( $x->{foo} )
  2. Creates accessors ( $x->foo() )
  3. Governs construction parameters ( $x = new Bar( foo=> 1 ) )

Synopsis


has 'attributename'; # Optional Attribute  
has 'attributename' => (
        # properties 
        isa      =>   'str', 
        is       =>   'str', 
        required =>    bool ,
        coerce   =>    bool,
        does     =>   'str', 
        weak_ref =>    bool,
        lazy     =>    bool,
        auto_deref =>  bool,
        trigger  =>    sub {  },
        handles  =>    HANDLER,
        metaclass =>   'metaclass', 
        traits   => [ 'str', 'str', 'str' ,]
        builder  => 'str',
        default  => DEFAULT, 
        initializer => 'str',
        clearer     => 'str',
        predicate   => 'str',
        lazy_build  => bool
);  
has [qw( foo bar )];  # List of optional attributes  
has [qw( foo bar )] => ( # Easy way to create many items that are identical
        # properties, as above
        required => 1
);

Parameters

  • attributename : The Name of the attribute that will appear on the class instances.

  • properties :

    • isa :
    • is :
      • 'ro' : Read Only
      • 'rw' : Read Write
    • required :
      • 0 : Not Required
      • 1 : Required Construction Parameter. Value may never be set to undef.
    • coerce :
    • does :
    • weak_ref :
    • lazy :
    • auto_deref:
    • trigger :
    • handles :