Skip to content

Commit

Permalink
convert things to postfix deref as appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbs committed May 25, 2024
1 parent 17db8c9 commit d93f8a4
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 60 deletions.
15 changes: 8 additions & 7 deletions lib/Sub/Exporter.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use v5.12.0;
use v5.20.0;
use warnings;
use stable 'postderef';
package Sub::Exporter;
# ABSTRACT: a sophisticated exporter for custom-built routines

Expand Down Expand Up @@ -442,7 +443,7 @@ sub _expand_groups {
: $groups[$i][1]{-as} ? $prefix . $groups[$i][1]{-as} . $suffix
: $prefix . $groups[$i][0] . $suffix;

$groups[$i][1] = { %{ $groups[$i][1] }, %merge, -as => $as };
$groups[$i][1] = { $groups[$i][1]->%*, %merge, -as => $as };
}
}
}
Expand Down Expand Up @@ -695,7 +696,7 @@ sub _rewrite_build_config {
$config->{groups}{default} ||= [];

# by default, build an all-inclusive 'all' group
$config->{groups}{all} ||= [ keys %{ $config->{exports} } ];
$config->{groups}{all} ||= [ keys $config->{exports}->%* ];

$config->{generator} ||= \&default_generator;
$config->{installer} ||= \&default_installer;
Expand Down Expand Up @@ -840,7 +841,7 @@ Passed arguments are:

sub default_generator {
my ($arg) = @_;
my ($class, $name, $generator) = @$arg{qw(class name generator)};
my ($class, $name, $generator) = $arg->@{qw(class name generator)};

if (not defined $generator) {
my $code = $class->can($name)
Expand Down Expand Up @@ -881,7 +882,7 @@ sub default_installer {
my ($arg, $to_export) = @_;

for (my $i = 0; $i < @$to_export; $i += 2) {
my ($as, $code) = @$to_export[ $i, $i+1 ];
my ($as, $code) = $to_export->@[ $i, $i+1 ];

# Allow as isa ARRAY to push onto an array?
# Allow into isa HASH to install name=>code into hash?
Expand Down Expand Up @@ -944,10 +945,10 @@ sub _setup {
my ($value, $arg) = @_;

if (ref $value eq 'HASH') {
push @{ $arg->{import_args} }, [ _import => { -as => 'import', %$value } ];
push $arg->{import_args}->@*, [ _import => { -as => 'import', %$value } ];
return 1;
} elsif (ref $value eq 'ARRAY') {
push @{ $arg->{import_args} },
push $arg->{import_args}->@*,
[ _import => { -as => 'import', exports => $value } ];
return 1;
}
Expand Down
13 changes: 7 additions & 6 deletions lib/Sub/Exporter/Util.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use v5.12.0;
use v5.20.0;
use warnings;
use stable 'postderef';
package Sub::Exporter::Util;
# ABSTRACT: utilities to make Sub::Exporter easier

Expand Down Expand Up @@ -104,7 +105,7 @@ sub curry_chain {
sub {
my $next = $class;

for my $i (0 .. $#$pairs) {
for my $i (0 .. $pairs->$#*) {
my $pair = $pairs->[ $i ];

unless (Params::Util::_INVOCANT($next)) { ## no critic Private
Expand All @@ -114,7 +115,7 @@ sub curry_chain {

my ($method, $args) = @$pair;

if ($i == $#$pairs) {
if ($i == $pairs->$#*) {
return $next->$method($args ? @$args : ());
} else {
$next = $next->$method($args ? @$args : ());
Expand Down Expand Up @@ -197,7 +198,7 @@ sub merge_col {
my ($class, $name, $arg, $col) = @_;

my $merged_arg = exists $col->{$default_name}
? { %{ $col->{$default_name} }, %$arg }
? { $col->{$default_name}->%*, %$arg }
: $arg;

if (Params::Util::_CODELIKE($gen)) { ## no critic Private
Expand Down Expand Up @@ -300,7 +301,7 @@ sub like {
while (my ($re, $opt) = splice @values, 0, 2) {
Carp::croak "given pattern for regex group generater is not a Regexp"
unless eval { $re->isa('Regexp') };
my @exports = keys %{ $arg->{config}->{exports} };
my @exports = keys $arg->{config}->{exports}->%*;
my @matching = grep { $_ =~ $re } @exports;

my %merge = $opt ? %$opt : ();
Expand All @@ -309,7 +310,7 @@ sub like {

for my $name (@matching) {
my $as = $prefix . $name . $suffix;
push @{ $arg->{import_args} }, [ $name => { %merge, -as => $as } ];
push $arg->{import_args}->@*, [ $name => { %merge, -as => $as } ];
}
}

Expand Down
9 changes: 5 additions & 4 deletions t/col-init.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!perl -T
use strict;
use v5.20.0;
use warnings;
use stable 'postderef';

=head1 TEST PURPOSE
Expand All @@ -25,7 +26,7 @@ my $config = {
collectors => [
INIT => sub {
my ($value, $arg) = @_;
return 0 if @{$arg->{import_args}}; # in other words, fail if args
return 0 if $arg->{import_args}->@*; # in other words, fail if args
$_[0] = [ $counter++ ];
return 1;
},
Expand All @@ -36,7 +37,7 @@ $config->{$_} = mkopt_hash($config->{$_}) for qw(exports collectors);

{
my $collection = Sub::Exporter::_collect_collections(
$config,
$config,
[ ],
'main',
);
Expand All @@ -51,7 +52,7 @@ $config->{$_} = mkopt_hash($config->{$_}) for qw(exports collectors);
{
my $collection = eval {
Sub::Exporter::_collect_collections(
$config,
$config,
[ [ handsaw => undef ] ],
'main',
);
Expand Down
7 changes: 4 additions & 3 deletions t/collection.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!perl -T
use strict;
use v5.20.0;
use warnings;
use stable 'postderef';

=head1 TEST PURPOSE
Expand Down Expand Up @@ -44,7 +45,7 @@ $config->{$_} = mkopt_hash($config->{$_})

{
my $collection = Sub::Exporter::_collect_collections(
$config,
$config,
[ [ circsaw => undef ], [ defaults => { foo => 1, bar => 2 } ] ],
'main',
);
Expand All @@ -58,7 +59,7 @@ $config->{$_} = mkopt_hash($config->{$_})

{
my $collection = Sub::Exporter::_collect_collections(
$config,
$config,
[ [ sets_own_value => undef ] ],
'main',
);
Expand Down
9 changes: 5 additions & 4 deletions t/expand-group.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!perl -T
use strict;
use v5.20.0;
use warnings;
use stable 'postderef';

=head1 TEST PURPOSE
Expand Down Expand Up @@ -161,7 +162,7 @@ my @single_tests = (

for my $test (@single_tests) {
my ($label, $given, $expected) = @$test;

my @got = Sub::Exporter::_expand_group(
'Class',
$config,
Expand All @@ -174,7 +175,7 @@ for my $test (@single_tests) {

for my $test (@single_tests) {
my ($label, $given, $expected) = @$test;

my $got = Sub::Exporter::_expand_groups(
'Class',
$config,
Expand Down Expand Up @@ -202,7 +203,7 @@ my @multi_tests = (

for my $test (@multi_tests) {
my ($label, $given, $expected) = @$test;

my $got = Sub::Exporter::_expand_groups(
'Class',
$config,
Expand Down
5 changes: 3 additions & 2 deletions t/faux-export.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!perl -T
use strict;
use v5.20.0;
use warnings;
use stable 'postderef';

=head1 TEST PURPOSE
Expand Down Expand Up @@ -66,7 +67,7 @@ my $config = {
$code->('Tools::Power', ':cutters');
exports_ok(
$exports,
[ [ circsaw => {} ], [ handsaw => {} ], [ circsaw => {} ] ],
[ [ circsaw => {} ], [ handsaw => {} ], [ circsaw => {} ] ],
"group with two export instances of one export",
);

Expand Down
3 changes: 2 additions & 1 deletion t/gen-callable.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!perl -T
use strict;
use v5.20.0;
use warnings;
use stable 'postderef';

use Test::More tests => 8;

Expand Down
13 changes: 7 additions & 6 deletions t/group-generator.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!perl -T
use strict;
use v5.20.0;
use warnings;
use stable 'postderef';

=head1 TEST PURPOSE
Expand Down Expand Up @@ -63,7 +64,7 @@ my @single_tests = (

for my $test (@single_tests) {
my ($label, $given, $expected) = @$test;

my @got = Sub::Exporter::_expand_group(
'Class',
$config,
Expand All @@ -80,7 +81,7 @@ for my $test (@single_tests) {

for my $test (@single_tests) {
my ($label, $given, $expected) = @$test;

my $got = Sub::Exporter::_expand_groups(
'Class',
$config,
Expand All @@ -100,7 +101,7 @@ my @multi_tests = (

for my $test (@multi_tests) {
my ($label, $given, $expected) = @$test;

my $got = Sub::Exporter::_expand_groups(
'Class',
$config,
Expand Down Expand Up @@ -157,7 +158,7 @@ like($@,
name => $_,
class => 'Class',
group => 'generated',
arg => { xyz => 1 },
arg => { xyz => 1 },
collection => { col1 => { value => 2 } },
},
"generated foo does what we expect",
Expand All @@ -182,7 +183,7 @@ like($@,
name => $_,
class => 'Class',
group => 'generated',
arg => { xyz => 1 },
arg => { xyz => 1 },
collection => { col1 => { value => 2 } },
},
"generated foo (via nested group) does what we expect",
Expand Down
3 changes: 2 additions & 1 deletion t/inherited.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!perl -T
use strict;
use v5.20.0;
use warnings;
use stable 'postderef';

=head1 TEST PURPOSE
Expand Down
15 changes: 8 additions & 7 deletions t/into-level.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!perl -T
use strict;
use v5.20.0;
use warnings;
use stable 'postderef';

=head1 TEST PURPOSE
Expand All @@ -11,14 +12,14 @@ exporter.

use Test::More tests => 14;

BEGIN {
use_ok('Sub::Exporter');
BEGIN {
use_ok('Sub::Exporter');
}

BEGIN {
package Test::SubExport::FROM;
use strict;
use warnings;
use warnings;
use Sub::Exporter -setup => {
exports => [ qw(A B) ],
groups => {
Expand All @@ -31,21 +32,21 @@ BEGIN {
sub A { 'A' }
sub B { 'B' }

1;
1;
}

BEGIN {
package Test::SubExport::HAS_DEFAULT_INTO_LEVEL;
use strict;
use warnings;
use warnings;
use Sub::Exporter -setup => {
exports => [ qw(C) ],
into_level => 1,
};

sub C { 'C' }

1;
1;
}

BEGIN {
Expand Down
11 changes: 6 additions & 5 deletions t/real-export-groupgen.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!perl -T
use strict;
use v5.20.0;
use warnings;
use stable 'postderef';

=head1 TEST PURPOSE
Expand Down Expand Up @@ -39,7 +40,7 @@ for my $routine (qw(foo bar)) {
name => $routine,
class => 'Test::SubExporter::GroupGen',
group => 'generated',
arg => { xyz => 1 },
arg => { xyz => 1 },
collection => { col1 => { value => 2 } },
},
"generated $routine does what we expect",
Expand All @@ -52,7 +53,7 @@ for my $routine (qw(foo bar)) {
name => $routine,
class => 'Test::SubExporter::GroupGen',
group => 'generated',
arg => { xyz => 5 },
arg => { xyz => 5 },
collection => { col1 => { value => 2 } },
},
"generated $five does what we expect",
Expand All @@ -65,7 +66,7 @@ is_deeply(
name => 'baz',
class => 'Test::SubExporter::GroupGen',
group => 'symbolic',
arg => { xyz => 2 },
arg => { xyz => 2 },
collection => { col1 => { value => 2 } },
},
"parent class's generated baz does what we expect",
Expand All @@ -77,7 +78,7 @@ is_deeply(
name => 'baz-sc',
class => 'Test::SubExporter::GroupGenSubclass',
group => 'symbolic',
arg => { xyz => 4 },
arg => { xyz => 4 },
collection => { col1 => { value => 3 } },
},
"inheriting class's generated baz does what we expect",
Expand Down
Loading

0 comments on commit d93f8a4

Please sign in to comment.