Sub::Multi::Tiny::Util - Internal utilities for Sub::Multi::Tiny
Used by Sub::Multi::Tiny.
Set this truthy for extra debug output. "import" in Sub::Multi::Tiny sets this based on environment variable SUB_MULTI_TINY_VERBOSE.
SUB_MULTI_TINY_VERBOSE
As "croak" in Carp, but lazily loads Carp.
As "carp" in Carp, but lazily loads Carp.
Add a #line directive to a string. Usage:
#line
my $str = _line_mark_string <<EOT ; $contents EOT
or
my $str = _line_mark_string __FILE__, __LINE__, <<EOT ; $contents EOT
In the first form, information from caller will be used for the filename and line number.
caller
The #line directive will point to the line after the _line_mark_string invocation, i.e., the first line of <C$contents>. Generally, $contents will be source code, although this is not required.
_line_mark_string
$contents
$contents must be defined, but can be empty.
Log information if "$VERBOSE" is set. Usage:
_hlog { <list of things to log> } [optional min verbosity level (default 1)];
The items in the list are joined by ' ' on output, and a '\n' is added. Each line is prefixed with '# ' for the benefit of test runs.
' '
'\n'
'# '
The list is in {} so that it won't be evaluated if logging is turned off. It is a full block, so you can run arbitrary code to decide what to log. If the block returns an empty list, _hlog will not produce any output. However, if the block returns at least one element, _hlog will produce at least a '# '.
{}
_hlog
The message will be output only if "$VERBOSE" is at least the given minimum verbosity level (1 by default).
If $VERBOSE > 2, the filename and line from which _hlog was called will also be printed.
$VERBOSE > 2
Caution: Within the { } block, @_ is the arguments to that block, not the arguments to the calling function. To log @_, use something like:
{ }
@_
my $argref = \@_; _hlog { @$argref };
Makes a standard dispatcher, given code to initialize certain variables. Usage:
my $code = "..."; # See requirements below my $subref = _complete_dispatcher($multisub_hashref, $code[, ...]);
The $code argument will be inlined as-is into the generated dispatcher. The $code must:
$code
Pick which multisub candidate to use, given args in @_;
Put the subref of that candidate in $candidate; and
$candidate
Put a subref in $copier of a routine that will copy from @_ into the package variables created by "import" in Sub::Multi::Tiny.
$copier
Any arguments to _complete_dispatcher after $code are saved in my @data, which $code can access.
_complete_dispatcher
my @data
Make a sub to copy from @_ into package variables. The resulting sub copies positional parameters. Usage:
my $coderef = _make_positional_copier($defined_in, $impl_hashref);
Chris White <cxw@cpan.org>
Copyright (C) 2019 Chris White <cxw@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Sub::Multi::Tiny, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sub::Multi::Tiny
CPAN shell
perl -MCPAN -e shell install Sub::Multi::Tiny
For more information on module installation, please visit the detailed CPAN module installation guide.