Revision history for Class::Accessor::Grouped.
+ - Stop leaking extra methods into the inheritance chain - there
+ are plenty already
+
0.10008 2012-11-15 09:48 (UTC)
- Allow disabling of accessor name checking introduced in 0.10007
- Pass tests if Class::XSAccessor is available but Sub::Name isn't
$0 =~ m|^ x?t / .+ \.t $|x
) ? 1 : 0 );
- *Class::Accessor::Grouped::perlstring = ($] < '5.008')
- ? do {
- require Data::Dumper;
- my $d = Data::Dumper->new([])->Indent(0)->Purity(0)->Pad('')->Useqq(1)->Terse(1)->Freezer('')->Toaster('');
- sub { $d->Values([shift])->Dump };
- }
- : do {
- require B;
- \&B::perlstring;
- }
- ;
+ require B;
+ # a perl 5.6 kludge
+ unless (B->can('perlstring')) {
+ require Data::Dumper;
+ my $d = Data::Dumper->new([])->Indent(0)->Purity(0)->Pad('')->Useqq(1)->Terse(1)->Freezer('')->Toaster('');
+ *B::perlstring = sub { $d->Values([shift])->Dump };
+ }
}
# Yes this method is undocumented
if ($name =~ /\0/) {
Carp::croak(sprintf
"Illegal accessor name %s - nulls should never appear in stash keys",
- perlstring($name),
+ B::perlstring($name),
);
}
elsif (! $ENV{CAG_ILLEGAL_ACCESSOR_NAME_OK} ) {
cxsa_call => 'accessors',
pp_generator => sub {
# my ($group, $fieldname) = @_;
- my $quoted_fieldname = perlstring($_[1]);
+ my $quoted_fieldname = B::perlstring($_[1]);
sprintf <<'EOS', ($_[0], $quoted_fieldname) x 2;
@_ > 1
cxsa_call => 'getters',
pp_generator => sub {
# my ($group, $fieldname) = @_;
- my $quoted_fieldname = perlstring($_[1]);
+ my $quoted_fieldname = B::perlstring($_[1]);
sprintf <<'EOS', $_[0], $quoted_fieldname;
@_ > 1
cxsa_call => 'setters',
pp_generator => sub {
# my ($group, $fieldname) = @_;
- my $quoted_fieldname = perlstring($_[1]);
+ my $quoted_fieldname = B::perlstring($_[1]);
sprintf <<'EOS', $_[0], $quoted_fieldname;
@_ > 1
}
# rerun the regular 3 tests under the assumption of no Sub::Name
-for my $tname (qw/accessors.t accessors_ro.t accessors_wo.t/) {
+for my $tname (qw/accessors.t accessors_ro.t accessors_wo.t clean_namespace.t/) {
subtest "$tname without Sub::Name (pass $_)" => sub {
my $tfn = catfile($Bin, $tname);
# rerun the regular 3 tests under XSAccessor
$Class::Accessor::Grouped::USE_XS = 1;
-for my $tname (qw/accessors.t accessors_ro.t accessors_wo.t/) {
+for my $tname (qw/accessors.t accessors_ro.t accessors_wo.t clean_namespace.t/) {
subtest "$tname with USE_XS (pass $_)" => sub {
my $tfn = catfile($Bin, $tname);
--- /dev/null
+use Test::More;
+use strict;
+use warnings;
+
+BEGIN {
+ plan skip_all => "Package::Stash required for this test"
+ unless eval { require Package::Stash };
+
+ require MRO::Compat if $] < 5.009_005;
+}
+
+{
+ package AccessorGroups::Clean;
+ use strict;
+ use warnings;
+ use base 'Class::Accessor::Grouped';
+
+ my $obj = bless {};
+ for (qw/simple inherited component_class/) {
+ __PACKAGE__->mk_group_accessors($_ => "${_}_a");
+ $obj->${\ "${_}_a"} ('blah');
+ }
+}
+
+is_deeply
+[ sort keys %{ { map
+ { %{Package::Stash->new($_)->get_all_symbols('CODE')} }
+ (reverse @{mro::get_linear_isa('AccessorGroups::Clean')})
+} } ],
+[ sort +(
+ (map { ( "$_", "_${_}_accessor" ) } qw/simple_a inherited_a component_class_a/ ),
+ (map { ( "get_$_", "set_$_" ) } qw/simple inherited component_class/ ),
+ qw/
+ _mk_group_accessors
+ get_super_paths
+ make_group_accessor
+ make_group_ro_accessor
+ make_group_wo_accessor
+ mk_group_accessors
+ mk_group_ro_accessors
+ mk_group_wo_accessors
+ /,
+)],
+'Expected list of methods in a freshly inheriting class';
+
+done_testing;
frew
getter
subclasses
+Benchmarking
\ No newline at end of file