sub predicate { $_[0]->{predicate} }
sub clearer { $_[0]->{clearer} }
sub handles { $_[0]->{handles} }
-sub weak_ref { $_[0]->{weak_ref} }
+sub is_weak_ref { $_[0]->{weak_ref} }
sub init_arg { $_[0]->{init_arg} }
sub type_constraint { $_[0]->{type_constraint} }
sub trigger { $_[0]->{trigger} }
$accessor .= '$self->{$key} = $_;';
- if ($attribute->weak_ref) {
- $accessor .= 'Scalar::Util::weaken($self->{$key});';
+ if ($attribute->is_weak_ref) {
+ $accessor .= 'Scalar::Util::weaken($self->{$key}) if ref($self->{$key});';
}
if ($trigger) {
sub generate_handles {
my $attribute = shift;
my $reader = $attribute->name;
+ my %handles = $attribute->_canonicalize_handles($attribute->handles);
my %method_map;
- for my $local_method (keys %{ $attribute->handles }) {
- my $remote_method = $attribute->handles->{$local_method};
+ for my $local_method (keys %handles) {
+ my $remote_method = $handles{$local_method};
my $method = 'sub {
my $self = shift;
sub create {
my ($self, $class, $name, %args) = @_;
- confess "You must specify a default for lazy attribute '$name'"
+ confess "You cannot have lazy attribute ($name) without specifying a default value for it"
if $args{lazy} && !exists($args{default}) && !exists($args{builder});
- confess "Trigger is not allowed on read-only attribute '$name'"
- if $args{trigger} && $args{is} ne 'rw';
-
confess "References are not allowed as default values, you must wrap the default of '$name' in a CODE reference (ex: sub { [] } and not [])"
if ref($args{default})
&& ref($args{default}) ne 'CODE';
- $args{handles} = { $self->_canonicalize_handles($args{handles}) }
- if $args{handles};
-
$args{type_constraint} = delete $args{isa}
if exists $args{isa};
=head2 has_handles -> Bool
-=head2 weak_ref -> Bool
+=head2 is_weak_ref -> Bool
=head2 init_arg -> Str