| 1 | package Best; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 20 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 20 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 20 | our $VERSION = '0.15'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 20 | our %WHICH; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # !! is more idiomatic, but messes up vim's hilighter :( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 20 | ▶ | use constant TRACE => ! ! $ENV{TRACE_BEST}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 20 | ▶ | use constant DEBUG => ! ! ($ENV{DEBUG_BEST} || $ENV{TRACE_BEST}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
Condition33%1/3
$ENV{'DEBUG_BEST'} || $ENV{'TRACE_BEST'}
MC/DC0%0/2
$ENV{'DEBUG_BEST'} || $ENV{'TRACE_BEST'}
$ENV{'DEBUG_BEST'}
$ENV{'TRACE_BEST'}
Truth table33%1/3
A || B
A= $ENV{'DEBUG_BEST'}B= $ENV{'TRACE_BEST'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | Best - Load modules with fallback | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # Load the best available YAML module with default imports | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | use Best qw/YAML::Syck YAML/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | use Best [ qw/YAML::Syck YAML/ ]; # also works | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # Load a YAML module and import some symbols | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | use Best [ [ qw/YAML::Syck YAML/ ], qw/DumpFile LoadFile/ ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # And fancier stuff... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # Load a new enough YAML module | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | use Best qw/YAML 0.58 YAML::Syck/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | use Best [ qw/YAML 0.58 YAML::Syck/ ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | use Best [ [ 'YAML' => { version => '0.58' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 'YAML::Syck' ] ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # Don't load too-new YAML module and import DumpFile | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | use Best [ [ 'YAML' => { ok => sub { YAML->VERSION <= 0.23 } }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 'YAML::Syck', ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | qw/DumpFile/ ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # Use the best Carp module w/ different parameter lists | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | use Best [ [ 'Carp::Clan' => { args => [] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 'Carp' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | qw/croak confess carp cluck/ ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # Choose alternate implementations | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | use Best [ [ 'My::Memoize' => { if => sub { $] <= 5.006 } }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 'Memoize' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | qw/memoize/ ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # Load a CGI module but import nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | use Best [ [ qw/CGI::Simple CGI/ ], [] ]; # akin to 'use CGI ()' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | Often there are several possible providers of some functionality your | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | program needs, but you don't know which is available at the run site. For | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | example, one of the modules may be implemented with XS, or not in the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | core Perl distribution and thus not necessarily installed. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | B<Best> attempts to load modules from a list, stopping at the first | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | successful load and failing only if no alternative was found. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | Most of the functionality B<Best> provides is on the C<use> line; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | there is only one callable functions as such (see C<which> below) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | If the arguments are either a simple list or a reference to a simple list, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | the elements are taken to be module names and are loaded in order with | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | their default import function called. Any exported symbols are installed | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | in the caller package. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | use Best qw/A Simple List/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | use Best [ qw/A Simple List/ ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | =head2 IMPORT LISTS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | If the arguments are a listref with a listref as its first element, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | this interior list is treated as the specification of modules to attempt | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | loading, in order; the rest of the arguments are treated as options to | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | pass on to the loaded module's import function. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | use Best [ [ qw/A Simple List/ ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | qw/Argument list goes here/ ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | use Best [ [ qw/A Simple List/ ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | [ qw/Argument list goes here/ ] ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | To specify a null import (C<use Some::Module ()>), pass a zero-element | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | listref as the argument list. In the pathological case where you really | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | want to load a module and pass it C<[]> as an argument, specify C<[ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | [] ]> as the argument list to B<Best>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # use Module (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | use Best [ [ 'Module' ], [] ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # use Module ( [] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | use Best [ [ 'Module' ], [[]] ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | To customize the import list for a module, use the C<args> parameter | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | in a hash reference following the module's name. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # use Carp::Clan; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # use Carp qw/carp croak confess cluck/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | use Best [ [ 'Carp::Clan' => { args => [] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 'Carp' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | qw/carp croak confess cluck/ ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | =head2 MINIMUM VERSIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | You can specify a minimum version for a module by following the module | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | name with something that looks like a number or by a hash reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | with a C<version> key. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | use Best [ [ YAML => '0.58', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 'YAML::Syck' ] ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | use Best [ [ YAML => { version => '0.58' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 'YAML::Syck' ] ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | =head2 PRE-VALIDATION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | use Best Module => { if => CODEREF }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | You may prevent B<Best> from attempting to load a module by providing | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | a function as a parameter to C<if>. The module will only be loaded if | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | your function returns a true value. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | =head2 POST-VALIDATION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | use Best Module => { ok => CODEREF }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | You may prevent B<Best> from settling on a successfully loaded module | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | by providing a function as a parameter to C<ok>. B<Best> will follow | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | all of its normal rules to attempt to load your module but can be told | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | to continue retrying if your function returns false. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | =head2 ARBITRARY CODE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | A code reference may be substituted for module names. It will be | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | called instead of attempting to load a module. You may do anything you | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | wish in this code. It will be skipped if your code throws an exception | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | or returns false. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | use Best [ sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # Decline | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # Oops! | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | die 'Some error'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 'Bad::Module', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # Ok! | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | }, ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # See if dereferencing it throws an error. This is meant to allow | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # overloaded things to pretend to be array/hashes/coderefs. It also | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # allows blessed array/hashes/coderefs to pass. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 20 | ▶ | use overload (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | sub does_arrayref { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 64 | ▶ | my($thing) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
does_arrayref: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 64 | ▶ | return if not defined $thing; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # This does not share the void context hash dereferencing bug | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # (see C<does_hashref>) but I'm being consistent about the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # style of returning a value. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 20 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 56 | return eval { return 1 + @{ $thing } }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | sub does_hashref { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 52 | ▶ | my($thing) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
does_hashref: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 52 | ▶ | return if not defined $thing; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # There is a bug in 5.8 where void context %{...} doesn't | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # evaluate. This was originally coded to check $@ but given the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # bug, it's not reliable. The fix is to use the value of the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # dereference. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 20 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 41 | return eval { return 1 + %{ $thing } }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | sub does_coderef { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 47 | ▶ | my($thing) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
does_coderef: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 47 | ▶ | return overload::Method($thing, '&{}') || | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
overload::Method($thing, '&{}') || overload::StrVal($thing) =~ /CODE\(0x[\da-f]+\)\z/
MC/DC100%2/2
overload::Method($thing, '&{}') || overload::StrVal($thing) =~ /CODE\(0x[\da-f]+\)\z/
overload::Method($thing, '&{}')
overload::StrVal($thing) =~ /CODE\(0x[\da-f]+\)\z/
Truth table100%3/3
A || B
A= overload::Method($thing, '&{}')B= overload::StrVal($thing) =~ /CODE\(0x[\da-f]+\)\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | overload::StrVal($thing) =~ /CODE\(0x[\da-f]+\)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | sub looks_like_version { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 56 | ▶ | my($version) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
looks_like_version: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 56 | ▶ | return defined $version && | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $version && $version =~ /\Av?\d+(?:\.[\d_]+)?\z/
MC/DC100%2/2
defined $version && $version =~ /\Av?\d+(?:\.[\d_]+)?\z/
defined $version
$version =~ /\Av?\d+(?:\.[\d_]+)?\z/
Truth table100%3/3
A && B
A= defined $versionB= $version =~ /\Av?\d+(?:\.[\d_]+)?\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | $version =~ /\Av?\d+(?:\.[\d_]+)?\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | sub assert { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # We'll pretend to be Carp::Assert here. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | return 1 if shift @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
assert: not called CC=3 SCAR=24.8
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | require Carp; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | Carp::confess(@_ ? @_ : "Something's wrong!"); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | sub diag { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # This output is safe to inline for Test::Harness. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | my($msg) = join '', @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
diag: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my ($package, $file, $line) = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | $msg =~ s/^/# /gm; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | $msg =~ s/(?<!\n)\z/\n/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | print "# $file on line $line\n$msg"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 20 | ▶ | TRACE and do { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | require Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | Data::Dumper->import('Dumper'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 19 | ▶ | my $caller = caller; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=27 SCAR=33.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 19 | shift @_; # "Best" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 19 | ▶ | return unless @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # Unflatten the module list. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # @_ = [ module arrayref, args arrayref ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 18 | TRACE and diag(Dumper(@_)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 18 | ▶ | if (not does_arrayref($_[0])) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # use Best qw/a b/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 3 | TRACE and diag('Totally flattened module list'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 3 | @_ = [[@_]]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | elsif (not does_arrayref($_[0][0])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # use Best [qw/a b/]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | TRACE and diag('Semi-flattened module list'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 2 | @_ = [@_]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 13 | TRACE and diag('Unflattened module list'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # Unflatten the import list. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 18 | TRACE and diag(Dumper(@{$_[0]})); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 18 | DEBUG and assert(@{$_[0]} > 0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 18 | ▶ | if (@{$_[0]} == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # [ module-arrayref, undef ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 8 | $_[0][1] = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 10 | ▶ | elsif (@{$_[0]} == 2 && does_arrayref($_[0][1])) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
@{$_[0];} == 2 and does_arrayref($_[0][1])
MC/DC100%2/2
@{$_[0];} == 2 and does_arrayref($_[0][1])
@{$_[0];} == 2
does_arrayref($_[0][1])
Truth table100%3/3
A and B
A= @{$_[0];} == 2B= does_arrayref($_[0][1])
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # [ module-arrayref, args-arrayref ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # [ module-arrayref, LIST ] -> [ module-arrayref, args-arrayref ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 6 | $_[0][1] = [ splice @{$_[0]}, 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 18 | TRACE and diag(Dumper(@_)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 18 | DEBUG and assert(does_arrayref($_[0])); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 18 | my @params = @{ shift @_ }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 18 | DEBUG and assert(0 == @_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # Promote sugared and param-less modules to have specs: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # Module|Code | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # or Module|Code => VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # or Module|Code => HASHREF | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | # becomes: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # [ Module|Code => HASHREF ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 18 | DEBUG and assert(does_arrayref($params[0])); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 18 | my @modules = @{ shift @params }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 18 | DEBUG and assert(1 == @params); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 18 | ▶ | for (my $i = 0; $i <= $#modules; ++$i) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 47 | my ($module, $param) = @modules[ $i, 1+$i ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 47 | ▶ | if (looks_like_version($param)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 2 | $param = { version => $param }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 2 | splice @modules, 1+$i, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | elsif (does_hashref($param)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 16 | splice @modules, 1+$i, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 29 | $param = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 47 | DEBUG and assert(does_hashref($param)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 47 | $modules[$i] = [ $module, $param ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 18 | ▶ | do { require Carp; Carp::croak('What modules shall I load?') } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | unless @modules; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # Unpack the import arguments. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 18 | my ($has_args, @args, $no_import); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 18 | TRACE and diag(Dumper(@params)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 18 | DEBUG and do { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | assert(1 == @params); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | assert(!defined $params[0] || | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | does_arrayref($params[0])); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 18 | ▶ | if (not does_arrayref($params[0])) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 8 | TRACE and diag('no import'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 8 | DEBUG and assert(!defined, $params[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 8 | shift @params; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 10 | $has_args = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 10 | @args = @{ shift @params }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | # valid only if $has_args | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 10 | DEBUG and diag("has_args => $has_args, \@args => [@args]"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | $no_import = !@args || | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 10 | ▶ | @args == 1 && does_arrayref($args[0]) && @{ $args[0] } == 0; # use Mod () | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition55%5/9
!@args || @args == 1 && does_arrayref($args[0]) && @{$args[0];} == 0
@args == 1 and does_arrayref($args[0]) and @{$args[0];} == 0
@args == 1 and does_arrayref($args[0])
MC/DC25%1/4
!@args || @args == 1 && does_arrayref($args[0]) && @{$args[0];} == 0
!@args
@args == 1
does_arrayref($args[0])
@{$args[0];} == 0
Truth table60%3/5
not(A) || B and C and D
A= !@argsB= @args == 1C= does_arrayref($args[0])D= @{$args[0];} == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | #::YY({mod=>$modules,has=>$has_args, arg=>\@args, noimport=>$no_import}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | # If we do not assume the loaded modules use Exporter, the only | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # alternative to eval-"" here is to enter a dummy package here and then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # scan it and rexport symbols found in it. That is not necessarily | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # better, because the callee may be picky about its caller. We are in | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | # compile time, and we do need to trust our caller anyway, so what the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | # hell, let's eval away. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 18 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 18 | my $first_module = $modules[0][0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | MODULE: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 18 | for my $thing_to_try (@modules) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 46 | my ($mod, $spec) = @$thing_to_try; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 46 | ▶ | if (my $precondition = $spec->{if}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 2 | ▶ | next MODULE unless $precondition->(); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 44 | ▶ | my $version = defined $spec->{version} ? $spec->{version} : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | my $loadargs = $no_import ? '()' : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 44 | ▶ | $spec->{args} ? '@{$spec->{args}}' : | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | $has_args ? '@args' : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # Load the module/code | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 44 | TRACE and diag("Trying $mod"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 44 | my $retval; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 44 | ▶ | if (does_coderef($mod)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 2 | $retval = $mod->(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 2 | ▶ | eval { die "$mod returned false" if not $retval }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 42 | my $src = qq{ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | package $caller; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | use $mod $version $loadargs; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 42 | TRACE and diag($src); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 42 | ▶ | $retval = eval $src; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 44 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 25 | push @errors, $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 25 | next MODULE; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | elsif (my $postcondition = $spec->{ok}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 2 | ▶ | next MODULE unless $postcondition->(); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 18 | TRACE and diag( "Loaded $mod\n" ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | $WHICH{$caller}{$first_module} = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 18 | $WHICH{__latest}{$first_module} = $mod; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 18 | return $retval; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | require Carp; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | Carp::croak('No viable module found: ' . map { "$_\n" } @errors); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | =item which | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | In some cases--for example, class methods in OO modules--you want to know | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | which module B<Best> has successfully loaded. Call C<< Best->which >> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | with the I<first> in your list of module alternatives; the return value | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | is a string containing the name of the loaded module. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | sub which { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 2 | ▶ | my($class, $mod) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
which: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 2 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 2 | ▶ | return $WHICH{$caller}{$mod} if defined $WHICH{$caller}{$mod}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 1 | ▶ | return $WHICH{__latest}{$mod} if defined $WHICH{__latest}{$mod}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | =head1 DEPLOYMENT ISSUES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | If you want to use B<Best> because you aren't sure your target machine has | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | some modules installed, you may wonder what might warrant the assumption | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | that C<Best.pm> would be available, since it isn't a core module itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | One solution is to use L<Inline::Module> to inline C<Best.pm> in your | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | source code. If you don't know this module, check it out -- after you | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | learn what it does, you may decide you don't need B<Best> at all! (If your | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | fallback list includes XS modules, though, you may need to stick with us.) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | C<Best.pm> is pure Perl and a single module with a convenient license, so | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | you can also just drop it in your project's C<lib> directory. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | =item L<Module::Load> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | =item L<UNIVERSAL::require> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | =item L<Inline::Module> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | Gaal Yahas, C<< <gaal at forum2.org> >> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | Joshua ben Jore, C<< <jjore at cpan.org> >> has made some significant | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | contributions. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | =head1 DIAGNOSTICS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | =item What modules shall I load? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | C<Best> wasn't given a list of modules to load. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | =item No viable module found: %s | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | None of the module alternatives loaded. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | =item Something's wrong! | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | An assertion failed. This means that either there is a bug in the data | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | you fed to B<Best> or a bug in B<Best>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | The code is scattered with assertions and debugging output that can be | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | enabled by putting a true value in the environment variables | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | C<TRACE_BEST> and C<DEBUG_BEST>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | Enabling C<TRACE_BEST> also enables the debugging code. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | Please report any bugs or feature requests to | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | C<bug-template-patch at rt.cpan.org>, or through the web interface at | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Best>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | your bug as I make changes. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | perldoc Best | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | You can also contact the maintainer at the address above or look for information at: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | L<http://annocpan.org/dist/Best/> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | =item * CPAN Ratings | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | L<http://cpanratings.perl.org/d/Best/> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Best> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | =item * Search CPAN | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | L<http://search.cpan.org/dist/Best/> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | =item * Source repository | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | L<https://github.com/gaal/best> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | =head1 COPYRIGHT (The "MIT (X11)" License) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | Copyright (C) 2006-2012 Gaal Yahas | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | This program is distributed under the MIT (X11) License: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | L<http://www.opensource.org/licenses/mit-license.php> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | Permission is hereby granted, free of charge, to any person | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | obtaining a copy of this software and associated documentation | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | files (the "Software"), to deal in the Software without | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | restriction, including without limitation the rights to use, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | copies of the Software, and to permit persons to whom the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | Software is furnished to do so, subject to the following | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | conditions: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | The above copyright notice and this permission notice shall be | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | included in all copies or substantial portions of the Software. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | OTHER DEALINGS IN THE SOFTWARE. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | # These are my favorite debugging tools. Share and enjoy. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | #sub ::Y { require YAML::Syck; YAML::Syck::Dump(@_) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | #sub ::YY { require Carp; Carp::confess(::Y(@_)) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 20 | "You'll never see me"; # End of Best | |||||||||||||||||||||||||||||||||||||||||||||||||