custom::failures::x::alias - export aliases for custom::failures
version 0.04
package MyApp::failure; use custom::failures::x::alias qw/io::flie io::network/;
This package creates importable alias subroutines for failure classes created by custom::failures.
Typically, you use custom::failures like this:
package MyApp::failure; use custom::failures qw/io::flie io::network/;
and later
package MyApp; use MyApp::failure; # somewhere deep in your code MyApp::failure::io::flie->throw();
"custom::failures::x::alias" creates shortened aliases so that you don't have to type so much:
and later,
package MyApp; use MyApp::failure ':all' # somewhere deep in your code io_flie->throw; io_network->throw;
Use it like you would custom::failures.
custom::failures
This will create alias subroutines MyApp::failure::io_flie and MyApp::failure::io_network, and make them importable. When using MyApp::failure, either import specific aliases:
MyApp::failure::io_flie
MyApp::failure::io_network
MyApp::failure
package MyApp; use MyApp::failure qw( io_flie ); io_flie->throw;
Or import them all:
package MyApp; use MyApp::failure ':all'; io_flie->throw;
The names of the alias subroutines may be modified by passing options to custom::failures::x::alias preceding the list of failure classes, e.g.
custom::failures::x::alias
package MyApp::failure; use custom::failures::x::alias -prefix => $pfx, @failures;
The options are:
The next element in the list is a string which will be prepended to the normalized class names. For example,
use custom::failures::x::alias -prefix => 'failure_, 'io::flie';
results in a alias name of
failure_io_flie
The next element in the list is a string which will be appended to the normalized class names. For example,
use custom::failures::x::alias -suffix => '_failure', 'io::flie';
io_flie_failure
This hands over complete control. $coderef should return a legal Perl subroutine name and is called as
$coderef
$alias_name = $coderef->( $class_name, \%opt);
where $class_name is the name passed via the use statement, and %opt has entries for -suffix and -prefix if specified, e.g.
$class_name
use
%opt
-suffix
-prefix
use custom::failures::x::alias -suffix => '_failure', -alias => \&mysub, 'io::flie';
results in a call to mysub:
mysub
mysub( 'io::flie', { -suffix => _failure } );
The default routine looks like this:
sub _alias { my ( $failure, $opt ) = @_; $failure =~ s/::/_/g; return ($opt->{-prefix} // '') . $failure . ($opt->{-suffix} // '') ; }
If this option is present (it takes no argument), aliases are unconditionally exported.
This will change which exporter is used. By default the standard Exporter class is used. A useful alternative is Exporter::Tiny, which allows the user of your failure module to dynamically alter the imported alias names, e.g.:
package MyApp::failure; use custom::failures::x::alias -exporter => 'Exporter::Tiny', qw/io::flie io::network/;
package MyApp; use MyApp::failure { suffix => '_failure' }, -all; # somewhere deep in your code io_flie_failure->throw; io_network_failure->throw;
An alternative is for the user of your failure module to use Importer.
custom::failures::x::alias does the following:
It uses custom::failures to create the specified classes in the caller's namespace.
For each class it installs an alias subroutine with a shortened and normalized name into the caller's namespace.
It makes the caller an exporter, either by installing the import routine from Exporter into the caller's namespace, or making the caller a subclass of a user specified exporter class (e.g. Exporter::Tiny).
import
It adds the aliases to the caller's @EXPORT_OK or (optionally) @EXPORT.
@EXPORT_OK
@EXPORT
It adds the aliases to the all entry in the caller's %EXPORT_TAGS;
all
%EXPORT_TAGS
Please report any bugs or feature requests to bug-custom-failures-x-alias@rt.cpan.org or through the web interface at: https://rt.cpan.org/Public/Dist/Display.html?Name=custom-failures-x-alias
Source is available at
https://gitlab.com/djerius/custom-failures-x-alias
and may be cloned from
https://gitlab.com/djerius/custom-failures-x-alias.git
Please see those modules/websites for more information related to this module.
Exporter
Exporter::Tiny
Importer
Diab Jerius <djerius@cpan.org>
This software is Copyright (c) 2021 by Smithsonian Astrophysical Observatory.
This is free software, licensed under:
The GNU General Public License, Version 3, June 2007
To install custom::failures::x::alias, copy and paste the appropriate command in to your terminal.
cpanm
cpanm custom::failures::x::alias
CPAN shell
perl -MCPAN -e shell install custom::failures::x::alias
For more information on module installation, please visit the detailed CPAN module installation guide.