Reindeer
view release on metacpan or search on metacpan
# attribute bar defined elsewhere (e.g. superclass)
default_for bar => 'new default';
... is the same as:
has '+bar' => (default => 'new default');
abstract
abstract() allows one to declare a method dependency that must be
satisfied by a subclass before it is invoked, and before the subclass
is made immutable.
abstract 'method_name_that_must_be_satisfied';
requires
requires() is a synonym for abstract() and works in the way you'd
expect.
OVERLOADS
It is safe to use overloads in your Reindeer classes and roles; they
will work just as you expect: overloads in classes can be inherited by
subclasses; overloads in roles will be incorporated into consuming
classes.
(See also MooseX::MarkAsMethods)
AVAILABLE OPTIONAL ATTRIBUTE TRAITS
We export the following trait aliases. These traits are not
automatically applied to attributes, and are lazily loaded (e.g. if you
don't use them, they won't be loaded and are not dependencies).
They can be used by specifying them as:
has foo => (traits => [ TraitAlias ], ...);
AutoDestruct
has foo => (
traits => [ AutoDestruct ],
is => 'ro',
lazy => 1,
builder => 1,
ttl => 600,
);
Allows for a "ttl" attribute option; this is the length of time (in
seconds) that a stored value is allowed to live; after that time the
value is cleared and the value rebuilt (given that the attribute is
lazy and has a builder defined).
See MooseX::AutoDestruct for more information.
CascadeClearing
This attribute trait allows one to designate that certain attributes
are to be cleared when certain other ones are; that is, when an
attribute is cleared that clearing will be cascaded down to other
attributes. This is most useful when you have attributes that are
lazily built.
See MooseX::CascadeClearing for more information and a significantly
more cogent description.
ENV
This is a Moose attribute trait that you use when you want the default
value for an attribute to be populated from the %ENV hash. So, for
example if you have set the environment variable USERNAME to 'John' you
can do:
package MyApp::MyClass;
use Reindeer;
has 'username' => (is=>'ro', traits=>[ ENV ]);
package main;
my $myclass = MyApp::MyClass->new();
print $myclass->username; # STDOUT => 'John';
This is basically similar functionality to something like:
has 'attr' => (
is=>'ro',
default=> sub {
$ENV{uc 'attr'};
},
);
If the named key isn't found in %ENV, then defaults will execute as
normal.
See MooseX::Attribute::ENV for more information.
MultiInitArg
has 'data' => (
traits => [ MultiInitArg ],
is => 'ro',
isa => 'Str',
init_args => [qw(munge frobnicate)],
);
This trait allows your attribute to be initialized with any one of
multiple arguments to new().
See MooseX::MultiInitArg for more information.
UndefTolerant
Applying this trait to your attribute makes it's initialization
tolerant of of undef. If you specify the value of undef to any of the
attributes they will not be initialized (or will be set to the default,
if applicable). Effectively behaving as if you had not provided a value
at all.
( run in 1.451 second using v1.01-cache-2.11-cpan-99c4e6809bf )