1 package Reaction::Meta::Attribute;
5 extends 'Moose::Meta::Attribute';
7 #is => 'Bool' ? or leave it open
9 (is => 'ro', reader => 'is_lazy_fail', required => 1, default => 0);
11 around _process_options => sub {
13 my ($class, $name, $options) = @_;
15 my $fail = $options->{lazy_fail};
18 confess("You may not use both lazy_build and lazy_fail for one attribute")
19 if $fail && $options->{lazy_build};
22 $options->{required} = 1;
23 $options->{default} = sub { confess "${name} must be provided before calling reader" };
26 #we are using this everywhere so might as well move it here.
27 $options->{predicate} ||= ($name =~ /^_/) ? "_has${name}" : "has_${name}"
28 if !$options->{required} || $options->{lazy};
30 $super->($class, $name, $options);
33 __PACKAGE__->meta->make_immutable(inline_constructor => 0);
41 Reaction::Meta::Attribute
45 has description => (is => 'rw', isa => 'Str', lazy_fail => 1);
47 =head1 Method-naming conventions
49 Reaction::Meta::Attribute will never override the values you set for method names,
50 but if you do not it will follow these basic rules:
52 Attributes with a name that starts with an underscore will default to using
53 builder and predicate method names in the form of the attribute name preceeded by
54 either "_has" or "_build". Otherwise the method names will be in the form of the
55 attribute names preceeded by "has_" or "build_". e.g.
57 #auto generates "_has_description" and expects "_build_description"
58 has _description => (is => 'rw', isa => 'Str', lazy_fail => 1);
60 #auto generates "has_description" and expects "build_description"
61 has description => (is => 'rw', isa => 'Str', lazy_fail => 1);
63 =head2 Predicate generation
65 All non-required or lazy attributes will have a predicate automatically
66 generated for them if one is not already specified.
70 lazy_fail will fail if it is called without first having set the value.
74 See L<Reaction::Class> for authors.
78 See L<Reaction::Class> for the license.