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} }
my $attribute = shift;
my $name = $attribute->name;
- my $key = $attribute->init_arg;
+ my $key = $name;
my $default = $attribute->default;
my $trigger = $attribute->trigger;
my $type = $attribute->type_constraint;
if ($constraint) {
$accessor .= 'do {
- my $display = defined($_) ? $_ : "undef";
+ my $display = defined($_) ? overload::StrVal($_) : "undef";
Carp::confess("Attribute ($name) does not pass the type constraint because: Validation failed for \'$type\' failed with value $display") unless $constraint->();
};'
}
$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_predicate {
my $attribute = shift;
- my $key = $attribute->init_arg;
+ my $key = $attribute->name;
my $predicate = 'sub { exists($_[0]->{$key}) }';
sub generate_clearer {
my $attribute = shift;
- my $key = $attribute->init_arg;
+ my $key = $attribute->name;
my $predicate = 'sub { delete($_[0]->{$key}) }';
=head2 has_handles -> Bool
-=head2 weak_ref -> Bool
+=head2 is_weak_ref -> Bool
=head2 init_arg -> Str