Reindeer
view release on metacpan or search on metacpan
lib/Reindeer.pm view on Meta::CPAN
default_for() is a shortcut to extend an attribute to give it a new default;
this default value may be any legal value for default options.
# attribute bar defined elsewhere (e.g. superclass)
default_for bar => 'new default';
... is the same as:
has '+bar' => (default => 'new default');
=head2 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';
=head2 requires
requires() is a synonym for abstract() and works in the way you'd expect.
=head1 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 L<MooseX::MarkAsMethods>)
=head1 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 ], ...);
=head2 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 L<MooseX::AutoDestruct> for more information.
=head2 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 L<MooseX::CascadeClearing> for more information and a significantly more
cogent description.
=head2 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 L<MooseX::Attribute::ENV> for more information.
=head2 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 L<MooseX::MultiInitArg> for more information.
=head2 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.
package My::Class;
use Reindeer;
has 'bar' => (
( run in 0.611 second using v1.01-cache-2.11-cpan-140bd7fdf52 )