Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Sub-Exporter CPAN distribution.

Report information
The Basics
Id: 38885
Status: resolved
Priority: 0/
Queue: Sub-Exporter

People
Owner: Nobody in particular
Requestors: trendele [...] imtek.de
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: merging of group arguments does not work for group generators
Download (untitled) / with headers
text/plain 728b
Hi, in a setup with nested groups, where the "inner" group is a group generator, like this: package MyPackage; use Sub::Exporter -setup => { groups => { inner => \&group_generator, outer => [':inner'], }, }; when importing the "outer" group with arguments: use MyPackage -outer => { foo => 'bar' }; then these arguments are not passed to group_generator(), although they should. It looks to me that the bug is on line 489 in Sub/Exporter.pm. The value passed to the generator should be $merge, not $group_args (which has already been merged into $merge, anyway). I have attached a patch against v0.979 (with test case) which fixes the issue for me. Regards, Stanis
Subject: group_generator_args.patch
diff -Naur Sub-Exporter-0.979.orig/lib/Sub/Exporter.pm Sub-Exporter-0.979/lib/Sub/Exporter.pm --- Sub-Exporter-0.979.orig/lib/Sub/Exporter.pm 2008-04-29 12:28:03.000000000 +0200 +++ Sub-Exporter-0.979/lib/Sub/Exporter.pm 2008-08-31 16:26:02.000000000 +0200 @@ -486,7 +486,7 @@ # I'm not very happy with this code for hiding -prefix and -suffix, but # it's needed, and I'm not sure, offhand, how to make it better. # -- rjbs, 2006-12-05 - my $group_arg = $group_arg ? { %$group_arg } : {}; + my $group_arg = $merge ? { %$merge } : {}; delete $group_arg->{-prefix}; delete $group_arg->{-suffix}; diff -Naur Sub-Exporter-0.979.orig/t/group-generator.t Sub-Exporter-0.979/t/group-generator.t --- Sub-Exporter-0.979.orig/t/group-generator.t 2007-08-17 16:56:27.000000000 +0200 +++ Sub-Exporter-0.979/t/group-generator.t 2008-08-31 16:28:59.000000000 +0200 @@ -12,7 +12,7 @@ # XXX: The framework is stolen from expand-group. I guess it should be # factored out. Whatever. -- rjbs, 2006-03-12 -use Test::More tests => 10; +use Test::More tests => 12; BEGIN { use_ok('Sub::Exporter'); } @@ -41,6 +41,7 @@ alphabet => sub { { A => $alfa, b => $bravo } }, broken => sub { [ qw(this is broken because it is not a hashref) ] }, generated => $returner, + nested => [qw( :generated )], }, collectors => [ 'col1' ], }; @@ -155,3 +156,28 @@ ); } } + +{ + my $got = Sub::Exporter::_expand_groups( + 'Class', + $config, + [ [ -nested => { xyz => 1 } ] ], + { col1 => { value => 2 } }, + ); + + my %code = map { $_->[0] => $_->[1] } @$got; + + for (qw(foo bar)) { + is_deeply( + $code{$_}->(), + { + name => $_, + class => 'Class', + group => 'generated', + arg => { xyz => 1 }, + collection => { col1 => { value => 2 } }, + }, + "generated foo (via nested group) does what we expect", + ); + } +}
Thanks! That's a great catch. 0.980, resolved. -- rjbs


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.