Exporter-Handy
view release on metacpan or search on metacpan
lib/Exporter/Handy/Util.pm view on Meta::CPAN
my @tags = _kv_sort(%tags); # sort on keys
wantarray ? @tags : \@tags; ## no critic
}
# PRIVATE utilities
# ref
sub _is_plain_arrayref { ref( $_[0] ) eq 'ARRAY' }
sub _is_plain_hashref { ref( $_[0] ) eq 'HASH' }
sub _is_plain_scalarref { ref( $_[0] ) eq 'SCALAR' }
sub _is_plain_scalar { !ref( $_[0] ) }
# List
sub _flat { # shamelessly copied from: [List::_flat](https://metacpan.org/pod/List::_flat)
my @results;
while (@_) {
if ( _is_plain_arrayref( my $element = shift @_ ) ) {
unshift @_, @{$element};
}
else {
push @results, $element;
}
}
return wantarray ? @results : \@results; ## no critic
}
sub _kv_sort {
unpairs sort { $a->[0] cmp $b->[0] } pairs(@_)
}
1;
__END__
=pod
=encoding UTF-8
=for :stopwords Tabulo[n] cxtags sig
=head1 NAME
Exporter::Handy::Util - Routines useful when exporting symbols thru Exporter and friends
=head1 VERSION
version 1.000004
=head1 SYNOPSIS
Define a module with exports
package My::Utils;
use Exporter::Handy -exporter_setup => 1;
export(qw( foo $x @STUFF -strict_and_warnings ), ':baz' => ['foo'] );
sub foo { ... }
sub strict_and_warnings {
strict->import;
warnings->import;
}
Create a new module which exports all that, and more
package My::MoreUtils;
use My::Utils -exporter_setup => 1;
sub util_fn3 : Export(:baz) { ... }
Use the module
use My::MoreUtils qw( -strict_and_warnings :baz @STUFF );
# Use the exported things
push @STUFF, foo(), util_fn3();
=head1 DESCRIPTION
This module is currently EXPERIMENTAL. You are advised to restrain from using it.
You have been warned.
=head1 FUNCTIONS
=head2 cxtags
Same as C<xtags()> described below, except that this one assumes {sig => ':'} as part of the options.
Hence, this one is more suitable to be used in conjunction with L<Exporter::Extensible> and descendants,
such as L<Exporter::Handy>, like below:
use Exporter::Handy::Util qw(cxtags);
use Exporter::Handy -exporter_setup => 1
export(
foo
goo
cxtags (
bar => [qw( $bozo @baza boom )],
util => {
io => [qw(slurp)],
text => [qw(ltrim rtrim trim)],
},
)
);
which is the same as:
use Exporter::Handy -exporter_setup => 1
export(
foo
goo
':bar' => [qw( $bozo @baza boom )],
':util_io' => [qw(slurp)],
':util_text' => [qw(ltrim rtrim trim)],
);
=head2 xtags
Build one or more B<export tags> suitable for L<Exporter> and friends, such as:
( run in 2.548 seconds using v1.01-cache-2.11-cpan-0d23b851a93 )