# from the accessor_xs test-umbrella
# Also make sure a rogue envvar will not interfere with
# things
+my $use_xs;
BEGIN {
$Class::Accessor::Grouped::USE_XS = 0
unless defined $Class::Accessor::Grouped::USE_XS;
$ENV{CAG_USE_XS} = 1;
+ $use_xs = $Class::Accessor::Grouped::USE_XS;
};
use AccessorGroups;
is(sub_fullname($alias_accessor), join('::',$class_name,$alias), 'alias FQ name');
}
-foreach (qw/singlefield multiple1 multiple2/) {
- my $name = $_;
+my $test_accessors = {
+ singlefield => {
+ is_xs => $use_xs,
+ },
+ multiple1 => {
+ },
+ multiple2 => {
+ },
+ lr1name => {
+ custom_field => 'lr1;field',
+ },
+ lr2name => {
+ custom_field => "lr2'field",
+ },
+};
+
+
+for my $name (sort keys %$test_accessors) {
my $alias = "_${name}_accessor";
+ my $field = $test_accessors->{$name}{custom_field} || $name;
can_ok($class, $name, $alias);
+ ok(!$class->can($field))
+ if $field ne $name;
is($class->$name, undef);
is($class->$alias, undef);
# get/set via name
is($class->$name('a'), 'a');
is($class->$name, 'a');
- is($class->{$name}, 'a');
+ is($class->{$field}, 'a');
# alias gets same as name
is($class->$alias, 'a');
# get/set via alias
is($class->$alias('b'), 'b');
is($class->$alias, 'b');
- is($class->{$name}, 'b');
+ is($class->{$field}, 'b');
# alias gets same as name
is($class->$name, 'b');
};
-foreach (qw/lr1 lr2/) {
- my $name = "$_".'name';
- my $alias = "_${name}_accessor";
-
- my $field = { lr1 => 'lr1;field', lr2 => q{lr2'field} }->{$_};
-
- can_ok($class, $name, $alias);
- ok(!$class->can($field));
-
- is($class->$name, undef);
- is($class->$alias, undef);
-
- # get/set via name
- is($class->$name('c'), 'c');
- is($class->$name, 'c');
- is($class->{$field}, 'c');
-
- # alias gets same as name
- is($class->$alias, 'c');
-
- # get/set via alias
- is($class->$alias('d'), 'd');
- is($class->$alias, 'd');
- is($class->{$field}, 'd');
-
- # alias gets same as name
- is($class->$name, 'd');
-};
-
# important
1;
use base 'Class::Accessor::Grouped';
__PACKAGE__->mk_group_accessors('simple', 'singlefield');
-__PACKAGE__->mk_group_accessors('simple', qw/multiple1 multiple2/);
-__PACKAGE__->mk_group_accessors('simple', [qw/lr1name lr1;field/], [qw/lr2name lr2'field/]);
+__PACKAGE__->mk_group_accessors('multiple', qw/multiple1 multiple2/);
+__PACKAGE__->mk_group_accessors('listref', [qw/lr1name lr1;field/], [qw/lr2name lr2'field/]);
sub new {
return bless {}, shift;
};
+foreach (qw/multiple listref/) {
+ no strict 'refs';
+ *{"get_$_"} = __PACKAGE__->can('get_simple');
+ *{"set_$_"} = __PACKAGE__->can('set_simple');
+};
+
1;