+0.00500
+ - make_accessor, make_ro_accessor, make_rw_accessor
0.00400 Oct 28, 2008
- Fix bug where a bad assumption was causing us to infinitely loop
on badly-written code like Data::Page. (Reported by marcus)
return @values;
}
+sub make_accessor {
+ my($class, $field) = @_;
+ my $meta = $class->meta;
+ my $attr = $meta->find_attribute_by_name($field) || $meta->add_attribute($field);
+ my $reader = $attr->get_read_method_ref;
+ my $writer = $attr->get_write_method_ref;
+ return sub {
+ my $self = shift;
+ return $self->$reader unless @_;
+ return $self->$writer((@_ > 1 ? [@_] : @_));
+ }
+}
+
+
+sub make_ro_accessor {
+ my($class, $field) = @_;
+ my $meta = $class->meta;
+ my $attr = $meta->find_attribute_by_name($field) || $meta->add_attribute($field);
+ return $attr->get_read_method_ref;
+}
+
+
+sub make_wo_accessor {
+ my($class, $field) = @_;
+ my $meta = $class->meta;
+ my $attr = $meta->find_attribute_by_name($field) || $meta->add_attribute($field);
+ return $attr->get_write_method_ref;
+}
+
+
1;
=head2 meta