aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/Meta/Attribute.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Reaction/Meta/Attribute.pm')
-rw-r--r--lib/Reaction/Meta/Attribute.pm40
1 files changed, 7 insertions, 33 deletions
diff --git a/lib/Reaction/Meta/Attribute.pm b/lib/Reaction/Meta/Attribute.pm
index 01540e0..16e5ed9 100644
--- a/lib/Reaction/Meta/Attribute.pm
+++ b/lib/Reaction/Meta/Attribute.pm
@@ -7,39 +7,26 @@ extends 'Moose::Meta::Attribute';
#is => 'Bool' ? or leave it open
has lazy_fail =>
(is => 'ro', reader => 'is_lazy_fail', required => 1, default => 0);
-has lazy_build =>
- (is => 'ro', reader => 'is_lazy_build', required => 1, default => 0);
around _process_options => sub {
my $super = shift;
my ($class, $name, $options) = @_;
- my $fail = $options->{lazy_fail}; #will this autovivify?
- my $build = $options->{lazy_build};
+ my $fail = $options->{lazy_fail};
- if ( $fail || $build) {
+ if ( $fail ) {
confess("You may not use both lazy_build and lazy_fail for one attribute")
- if $fail && $build;
- confess("You may not supply a default value when using lazy_build or lazy_fail")
- if exists $options->{default};
+ if $fail && $options->{lazy_build};
$options->{lazy} = 1;
$options->{required} = 1;
-
- my $builder = ($name =~ /^_/) ? "_build${name}" : "build_${name}";
- $options->{default} = $fail ?
- sub { confess "${name} must be provided before calling reader" } :
- sub{ shift->$builder };
-
- $options->{clearer} ||= ($name =~ /^_/) ? "_clear${name}" : "clear_${name}"
- if $build;
+ $options->{default} = sub { confess "${name} must be provided before calling reader" };
}
#we are using this everywhere so might as well move it here.
$options->{predicate} ||= ($name =~ /^_/) ? "_has${name}" : "has_${name}"
if !$options->{required} || $options->{lazy};
-
$super->($class, $name, $options);
};
@@ -57,14 +44,6 @@ Reaction::Meta::Attribute
has description => (is => 'rw', isa => 'Str', lazy_fail => 1);
- # OR
- has description => (is => 'rw', isa => 'Str', lazy_build => 1);
- sub build_description{ "My Description" }
-
- # OR
- has _description => (is => 'rw', isa => 'Str', lazy_build => 1);
- sub _build_description{ "My Description" }
-
=head1 Method-naming conventions
Reaction::Meta::Attribute will never override the values you set for method names,
@@ -76,10 +55,10 @@ either "_has" or "_build". Otherwise the method names will be in the form of the
attribute names preceeded by "has_" or "build_". e.g.
#auto generates "_has_description" and expects "_build_description"
- has _description => (is => 'rw', isa => 'Str', lazy_build => 1);
+ has _description => (is => 'rw', isa => 'Str', lazy_fail => 1);
#auto generates "has_description" and expects "build_description"
- has description => (is => 'rw', isa => 'Str', lazy_build => 1);
+ has description => (is => 'rw', isa => 'Str', lazy_fail => 1);
=head2 Predicate generation
@@ -88,12 +67,7 @@ generated for them if one is not already specified.
=head2 lazy_fail
-=head2 lazy_build
-
-lazy_build will lazily build to the return value of a user-supplied builder sub
- The builder sub will recieve C<$self> as the first argument.
-
-lazy_fail will simply fail if it is called without first having set the value.
+lazy_fail will fail if it is called without first having set the value.
=head1 AUTHORS