* Class::MOP::Package
- we now deal with stub methods properly
- added tests for this
+ * Class::MOP::Attribute
+ - added get_read_method and get_write_method
+ - added tests and POD for this
0.37 Sat. March 10, 2007
~~ Many, many documentation updates ~~
# end bootstrapped away method section.
# (all methods below here are kept intact)
+sub get_read_method { $_[0]->reader || $_[0]->accessor }
+sub get_write_method { $_[0]->writer || $_[0]->accessor }
+
sub is_default_a_coderef {
('CODE' eq (reftype($_[0]->{'$!default'} || $_[0]->{default}) || ''))
}
Returns a list of slots required by the attribute. This is usually
just one, which is the name of the attribute.
+=item B<get_read_method>
+
+=item B<get_write_method>
+
+Return the name of a method suitable for reading / writing the value of the
+attribute in the associated class. Suitable for use whether C<reader> and
+C<writer> or C<accessor> was used.
+
=back
=head2 Informational predicates
use strict;
use warnings;
-use Test::More tests => 43;
+use Test::More tests => 47;
use Test::Exception;
BEGIN {
::ok($meta->has_attribute('$bar'), '... Bar has $bar attribute');
::is($meta->get_attribute('$bar'), $BAR_ATTR, '... got the right attribute back for Bar');
+ my $attr = $meta->get_attribute('$bar');
+ ::is($attr->get_read_method, 'bar', '... got the right read method for Bar');
+ ::is($attr->get_write_method, 'bar', '... got the right write method for Bar');
+
::ok($meta->has_method('bar'), '... an accessor has been created');
::isa_ok($meta->get_method('bar'), 'Class::MOP::Method::Accessor');
}
::ok($meta->has_attribute('$baz'), '... Baz has $baz attribute');
::is($meta->get_attribute('$baz'), $BAZ_ATTR, '... got the right attribute back for Baz');
+ my $attr = $meta->get_attribute('$baz');
+ ::is($attr->get_read_method, 'get_baz', '... got the right read method for Baz');
+ ::is($attr->get_write_method, 'set_baz', '... got the right write method for Baz');
+
::ok($meta->has_method('get_baz'), '... a reader has been created');
::ok($meta->has_method('set_baz'), '... a writer has been created');