| 1 | package Test2::Tools::LoadModule; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | # OK, the following is probably paranoia. But if Perl 7 decides to | ||||||||||||||||||||||||||||||||
| 9 | # change this particular default I'm ready. Unless they eliminate $]. | ||||||||||||||||||||||||||||||||
| 10 | 10 | ▶ | no if $] ge '5.020', feature => qw{ signatures }; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 10 | ▶ | use Exporter 5.567; # Comes with Perl 5.8.1. | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | # use File::Find (); | ||||||||||||||||||||||||||||||||
| 15 | # use File::Spec (); | ||||||||||||||||||||||||||||||||
| 16 | # use Getopt::Long 2.34; # Comes with Perl 5.8.1. | ||||||||||||||||||||||||||||||||
| 17 | 10 | ▶ | use Test2::API 1.302096 (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | 10 | ▶ | use Test2::API::Context 1.302096 (); # for pass_and_release(). | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | 10 | ▶ | use Test2::Util 1.302096 (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 10 | ▶ | use base qw{ Exporter }; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 10 | our $VERSION = '0.010'; | |||||||||||||||||||||||||||||||
| 24 | 10 | $VERSION =~ s/ _ //smxg; | |||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||||||
| 27 | 10 | my @test2 = qw{ | |||||||||||||||||||||||||||||||
| 28 | all_modules_tried_ok | ||||||||||||||||||||||||||||||||
| 29 | clear_modules_tried | ||||||||||||||||||||||||||||||||
| 30 | load_module_ok | ||||||||||||||||||||||||||||||||
| 31 | load_module_or_skip | ||||||||||||||||||||||||||||||||
| 32 | load_module_or_skip_all | ||||||||||||||||||||||||||||||||
| 33 | }; | ||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 10 | my @more = qw{ | |||||||||||||||||||||||||||||||
| 36 | require_ok | ||||||||||||||||||||||||||||||||
| 37 | use_ok | ||||||||||||||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | 10 | my @private = qw{ | |||||||||||||||||||||||||||||||
| 41 | __build_load_eval | ||||||||||||||||||||||||||||||||
| 42 | __get_hint_hash | ||||||||||||||||||||||||||||||||
| 43 | DEFAULT_LOAD_ERROR | ||||||||||||||||||||||||||||||||
| 44 | ERR_IMPORT_BAD | ||||||||||||||||||||||||||||||||
| 45 | ERR_MODULE_UNDEF | ||||||||||||||||||||||||||||||||
| 46 | ERR_OPTION_BAD | ||||||||||||||||||||||||||||||||
| 47 | ERR_SKIP_NUM_BAD | ||||||||||||||||||||||||||||||||
| 48 | ERR_VERSION_BAD | ||||||||||||||||||||||||||||||||
| 49 | HINTS_AVAILABLE | ||||||||||||||||||||||||||||||||
| 50 | TEST_MORE_ERROR_CONTEXT | ||||||||||||||||||||||||||||||||
| 51 | TEST_MORE_LOAD_ERROR | ||||||||||||||||||||||||||||||||
| 52 | }; | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 10 | our @EXPORT_OK = ( @test2, @more, @private ); | |||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 10 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||||||
| 57 | all => [ @test2, @more ], | ||||||||||||||||||||||||||||||||
| 58 | default => \@test2, | ||||||||||||||||||||||||||||||||
| 59 | more => \@more, | ||||||||||||||||||||||||||||||||
| 60 | private => \@private, | ||||||||||||||||||||||||||||||||
| 61 | test2 => \@test2, | ||||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 10 | our @EXPORT = @{ $EXPORT_TAGS{default} }; ## no critic (ProhibitAutomaticExportation) | |||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 10 | ▶ | use constant ARRAY_REF => ref []; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 68 | 10 | ▶ | use constant HASH_REF => ref {}; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 10 | ▶ | use constant CALLER_HINT_HASH => 10; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 10 | ▶ | use constant DEFAULT_LOAD_ERROR => '%s'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 10 | ▶ | use constant ERR_IMPORT_BAD => | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 75 | 10 | 'Import list must be an array reference, or undef'; | |||||||||||||||||||||||||||||||
| 76 | 10 | ▶ | use constant ERR_MODULE_UNDEF => 'Module name must be defined'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 77 | 10 | ▶ | use constant ERR_OPTION_BAD => 'Bad option'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 78 | 10 | ▶ | use constant ERR_SKIP_NUM_BAD => | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 79 | 10 | 'Number of skipped tests must be an unsigned integer'; | |||||||||||||||||||||||||||||||
| 80 | 10 | ▶ | use constant ERR_VERSION_BAD => q/Version '%s' is invalid/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 10 | ▶ | use constant HINTS_AVAILABLE => $] ge '5.010'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | # The following cribbed shamelessly from version::regex 0.9924, | ||||||||||||||||||||||||||||||||
| 85 | # after being munged to suit by tools/version_regex 0.000_010. | ||||||||||||||||||||||||||||||||
| 86 | # This technical debt is incurred to avoid having to require a version | ||||||||||||||||||||||||||||||||
| 87 | # of the version module large enough to export the is_lax() subroutine. | ||||||||||||||||||||||||||||||||
| 88 | 10 | ▶ | use constant LAX_VERSION => qr/(?x: (?x: | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 89 | v (?-x:[0-9]+) (?-x: (?-x:\.[0-9]+)+ (?-x:_[0-9]+)? )? | ||||||||||||||||||||||||||||||||
| 90 | | | ||||||||||||||||||||||||||||||||
| 91 | (?-x:[0-9]+)? (?-x:\.[0-9]+){2,} (?-x:_[0-9]+)? | ||||||||||||||||||||||||||||||||
| 92 | ) | (?x: (?-x:[0-9]+) (?-x: (?-x:\.[0-9]+) | \. )? (?-x:_[0-9]+)? | ||||||||||||||||||||||||||||||||
| 93 | | | ||||||||||||||||||||||||||||||||
| 94 | (?-x:\.[0-9]+) (?-x:_[0-9]+)? | ||||||||||||||||||||||||||||||||
| 95 | 10 | ) )/; | |||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | 10 | ▶ | use constant TEST_MORE_ERROR_CONTEXT => q/Tried to %s '%s'./; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 98 | 10 | ▶ | use constant TEST_MORE_LOAD_ERROR => 'Error: %s'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 99 | 10 | ▶ | use constant TEST_MORE_OPT => { | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 100 | load_error => TEST_MORE_LOAD_ERROR, | ||||||||||||||||||||||||||||||||
| 101 | require => 1, | ||||||||||||||||||||||||||||||||
| 102 | 10 | }; | |||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||||||
| 105 | 10 | my %module_tried; | |||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | 16 | ▶ | sub load_module_ok (@) { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||||||
|
Subroutine
load_module_ok: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 108 | 16 | my @arg = _validate_args( 0, @_ ); | |||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | # We do this now in case _load_module_ok() throws an uncaught | ||||||||||||||||||||||||||||||||
| 111 | # exception, just so we have SOME record we tried. | ||||||||||||||||||||||||||||||||
| 112 | 12 | $module_tried{ $arg[1] } = undef; | |||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | 12 | my $ctx = Test2::API::context(); | |||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | 12 | my $rslt = _load_module_ok( @arg ); | |||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 12 | $module_tried{ $arg[1] } = $rslt; | |||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | 12 | $ctx->release(); | |||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | 12 | return $rslt; | |||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | 3 | ▶ | sub all_modules_tried_ok (@) { | ||||||||||||||||||||||||||||||
|
Subroutine
all_modules_tried_ok: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 126 | 3 | my @where = @_; | |||||||||||||||||||||||||||||||
| 127 | @where | ||||||||||||||||||||||||||||||||
| 128 | 3 | ▶ | or @where = ( 'blib/lib', 'blib/arch' ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | 3 | require File::Find; | |||||||||||||||||||||||||||||||
| 131 | 3 | require File::Spec; | |||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | 3 | my @not_tried; | |||||||||||||||||||||||||||||||
| 134 | 3 | foreach my $d ( @where ) { | |||||||||||||||||||||||||||||||
| 135 | 15 | ▶ | File::Find::find( sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 136 | 15 | ▶ | m/ [.] pm \z /smx | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 137 | or return; | ||||||||||||||||||||||||||||||||
| 138 | 3 | my ( undef, $dir, $name ) = File::Spec->splitpath( | |||||||||||||||||||||||||||||||
| 139 | File::Spec->abs2rel( $File::Find::name, $d ) ); | ||||||||||||||||||||||||||||||||
| 140 | 3 | my @dir = File::Spec->splitdir( $dir ); | |||||||||||||||||||||||||||||||
| 141 | 3 | ▶ | $dir[-1] | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 142 | or pop @dir; | ||||||||||||||||||||||||||||||||
| 143 | 3 | ( my $module = join '::', @dir, $name ) =~ s/ [.] pm //smx; | |||||||||||||||||||||||||||||||
| 144 | 3 | ▶ | exists $module_tried{$module} | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 145 | or push @not_tried, $module; | ||||||||||||||||||||||||||||||||
| 146 | 6 | }, $d ); | |||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | 3 | ▶ | if ( @not_tried ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | 2 | my $ctx = Test2::API::context(); | |||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | 2 | $ctx->fail( "Module $_ not tried" ) for sort @not_tried; | |||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | 2 | $ctx->release(); | |||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | 2 | return 0; | |||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||
| 161 | 1 | ▶ | sub clear_modules_tried () { | ||||||||||||||||||||||||||||||
|
Subroutine
clear_modules_tried: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 162 | 1 | %module_tried = (); | |||||||||||||||||||||||||||||||
| 163 | 1 | return; | |||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||
| 167 | 10 | ▶ | sub _load_module_ok { | ||||||||||||||||||||||||||||||
|
Subroutine
_load_module_ok: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 168 | 21 | my ( $opt, $module, $version, $import, $name, @diag ) = @_; | |||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | 21 | local $@ = undef; | |||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||
| 172 | 21 | my $eval = __build_load_eval( $opt, $module, $version, $import ); | |||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||
| 174 | 21 | ▶ | defined $name | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 175 | or $name = $eval; | ||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||
| 177 | 21 | my $ctx = Test2::API::context(); | |||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | 21 | ▶ | _eval_in_pkg( $eval, $ctx->trace()->call() ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 180 | and return $ctx->pass_and_release( $name ); | ||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||
| 182 | 10 | chomp $@; | |||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||
| 184 | $opt->{load_error} | ||||||||||||||||||||||||||||||||
| 185 | 10 | ▶ | and push @diag, sprintf $opt->{load_error}, $@; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | 10 | return $ctx->fail_and_release( $name, @diag ); | |||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||
| 190 | 11 | ▶ | sub load_module_or_skip (@) { ## no critic (RequireArgUnpacking,RequireFinalReturn) | ||||||||||||||||||||||||||||||
|
Subroutine
load_module_or_skip: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 191 | 11 | my ( $opt, $module, $version, $import, $name, $num ) = _validate_args( 5, @_ ); | |||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||
| 193 | 6 | ▶ | _load_module( $opt, $module, $version, $import ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 194 | and return; | ||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||
| 196 | 4 | ▶ | defined $name | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 197 | or $name = sprintf 'Unable to %s', | ||||||||||||||||||||||||||||||||
| 198 | __build_load_eval( $opt, $module, $version, $import ); | ||||||||||||||||||||||||||||||||
| 199 | 4 | ▶ | defined $num | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $num and $num =~ / [^0-9] /msx
MC/DC100%2/2
defined $num and $num =~ / [^0-9] /msx
defined $num
$num =~ / [^0-9] /msx
Truth table100%3/3
A and B
A= defined $numB= $num =~ / [^0-9] /msx
| |||||||||||||||||||||||||||||||||
| 200 | and $num =~ m/ [^0-9] /smx | ||||||||||||||||||||||||||||||||
| 201 | and croak ERR_SKIP_NUM_BAD; | ||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||
| 203 | 3 | my $ctx = Test2::API::context(); | |||||||||||||||||||||||||||||||
| 204 | 3 | ▶ | $num ||= 1; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$num ||= 1
MC/DC100%1/1
$num ||= 1
$num
Truth table100%2/2
A
A= $num
| |||||||||||||||||||||||||||||||||
| 205 | 3 | $ctx->skip( 'skipped test', $name ) for 1 .. $num; | |||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||
| 207 | 3 | $ctx->release(); | |||||||||||||||||||||||||||||||
| 208 | 10 | ▶ | no warnings qw{ exiting }; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 209 | 3 | last SKIP; | |||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||
| 212 | 10 | ▶ | sub load_module_or_skip_all (@) { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||||||
|
Subroutine
load_module_or_skip_all: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||||||
| 213 | 10 | my ( $opt, $module, $version, $import, $name ) = _validate_args( 4, @_ ); | |||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||
| 215 | 5 | ▶ | _load_module( $opt, $module, $version, $import ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 216 | and return; | ||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||
| 218 | 3 | ▶ | defined $name | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 219 | or $name = sprintf 'Unable to %s', | ||||||||||||||||||||||||||||||||
| 220 | __build_load_eval( $opt, $module, $version, $import ); | ||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||
| 222 | 3 | my $ctx = Test2::API::context(); | |||||||||||||||||||||||||||||||
| 223 | 3 | $ctx->plan( 0, SKIP => $name ); | |||||||||||||||||||||||||||||||
| 224 | 0 | $ctx->release(); | |||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||
| 226 | 0 | return; | |||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||
| 229 | 11 | ▶ | sub _load_module { | ||||||||||||||||||||||||||||||
|
Subroutine
_load_module: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 230 | 11 | my ( $opt, $module, $version, $import ) = @_; | |||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||
| 232 | 11 | local $@ = undef; | |||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||
| 234 | 11 | my $eval = __build_load_eval( $opt, $module, $version, $import ); | |||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||
| 236 | 11 | return _eval_in_pkg( $eval, _get_call_info() ) | |||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||
| 239 | { | ||||||||||||||||||||||||||||||||
| 240 | 10 | my $psr; | |||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||
| 242 | # Because we want to work with Perl 5.8.1 we are limited to | ||||||||||||||||||||||||||||||||
| 243 | # Getopt::Long 2.34, and therefore getoptions(). So we expect the | ||||||||||||||||||||||||||||||||
| 244 | # arguments to be in a suitably-localized @ARGV. The optional | ||||||||||||||||||||||||||||||||
| 245 | # argument is a reference to a hash into which we place the option | ||||||||||||||||||||||||||||||||
| 246 | # values. If omitted, we create a reference to a new hash. Either | ||||||||||||||||||||||||||||||||
| 247 | # way the hash reference gets returned. | ||||||||||||||||||||||||||||||||
| 248 | 50 | ▶ | sub _parse_opts { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_opts: called CC=8 SCAR=20.9
| |||||||||||||||||||||||||||||||||
| 249 | 50 | my ( $opt ) = @_; | |||||||||||||||||||||||||||||||
| 250 | 50 | ▶ | $opt ||= {}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$opt ||= {}
MC/DC0%0/1
$opt ||= {}
$opt
Truth table50%1/2
A
A= $opt
| |||||||||||||||||||||||||||||||||
| 251 | { | ||||||||||||||||||||||||||||||||
| 252 | 50 | ▶ | unless ( $psr ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 253 | 9 | require Getopt::Long; | |||||||||||||||||||||||||||||||
| 254 | 9 | Getopt::Long->VERSION( 2.34 ); | |||||||||||||||||||||||||||||||
| 255 | 9 | $psr = Getopt::Long::Parser->new(); | |||||||||||||||||||||||||||||||
| 256 | 9 | $psr->configure( qw{ posix_default } ); | |||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||
| 259 | 50 | my $opt_err; | |||||||||||||||||||||||||||||||
| 260 | 50 | ▶ | local $SIG{__WARN__} = sub { $opt_err = $_[0] }; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 261 | $psr->getoptions( $opt, qw{ | ||||||||||||||||||||||||||||||||
| 262 | load_error=s | ||||||||||||||||||||||||||||||||
| 263 | require|req! | ||||||||||||||||||||||||||||||||
| 264 | }, | ||||||||||||||||||||||||||||||||
| 265 | 50 | ▶ | ) or do { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 266 | 3 | ▶ | if ( defined $opt_err ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 267 | 3 | chomp $opt_err; | |||||||||||||||||||||||||||||||
| 268 | 3 | croak $opt_err; | |||||||||||||||||||||||||||||||
| 269 | } else { | ||||||||||||||||||||||||||||||||
| 270 | 0 | croak ERR_OPTION_BAD; | |||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||
| 272 | }; | ||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||
| 274 | 47 | ▶ | if ( $opt->{load_error} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 275 | $opt->{load_error} =~ m/ ( %+ ) [ #0+-]* [0-9]* s /smx | ||||||||||||||||||||||||||||||||
| 276 | and length( $1 ) % 2 | ||||||||||||||||||||||||||||||||
| 277 | 34 | ▶ | or $opt->{load_error} = '%s'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$opt->{"load_error"} =~ / ( %+ ) [ #0+-]* [0-9]* s /msx and length($1) % 2
MC/DC50%1/2
$opt->{"load_error"} =~ / ( %+ ) [ #0+-]* [0-9]* s /msx and length($1) % 2
$opt->{"load_error"} =~ / ( %+ ) [ #0+-]* [0-9]* s /msx
length($1) % 2
Truth table66%2/3
A and B
A= $opt->{"load_error"} =~ / ( %+ ) [ #0+-]* [0-9]* s /msxB= length($1) % 2
| |||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||
| 279 | 47 | return $opt; | |||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||
| 283 | 10 | ▶ | sub import { ## no critic (RequireArgUnpacking,ProhibitBuiltinHomonyms) | ||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 284 | 18 | ( my $class, local @ARGV ) = @_; # See _parse_opts | |||||||||||||||||||||||||||||||
| 285 | 18 | ▶ | if ( @ARGV ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 286 | 13 | my %opt; | |||||||||||||||||||||||||||||||
| 287 | 13 | _parse_opts( \%opt ); | |||||||||||||||||||||||||||||||
| 288 | 13 | if ( HINTS_AVAILABLE ) { | |||||||||||||||||||||||||||||||
| 289 | 13 | $^H{ _make_pragma_key() } = $opt{$_} for keys %opt; | |||||||||||||||||||||||||||||||
| 290 | } else { | ||||||||||||||||||||||||||||||||
| 291 | keys %opt | ||||||||||||||||||||||||||||||||
| 292 | and carp "Import options ignored under Perl $]"; | ||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||
| 294 | @ARGV | ||||||||||||||||||||||||||||||||
| 295 | 13 | ▶ | or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||
| 297 | 14 | return $class->export_to_level( 1, $class, @ARGV ); | |||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||
| 300 | 4 | ▶ | sub require_ok ($) { | ||||||||||||||||||||||||||||||
|
Subroutine
require_ok: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 301 | 4 | my ( $module ) = @_; | |||||||||||||||||||||||||||||||
| 302 | 4 | ▶ | defined $module | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 303 | or croak ERR_MODULE_UNDEF; | ||||||||||||||||||||||||||||||||
| 304 | 3 | my $ctx = Test2::API::context(); | |||||||||||||||||||||||||||||||
| 305 | 3 | my $rslt = _load_module_ok( TEST_MORE_OPT, | |||||||||||||||||||||||||||||||
| 306 | $module, undef, undef, "require $module;", | ||||||||||||||||||||||||||||||||
| 307 | sprintf( TEST_MORE_ERROR_CONTEXT, require => $module ), | ||||||||||||||||||||||||||||||||
| 308 | ); | ||||||||||||||||||||||||||||||||
| 309 | 3 | $ctx->release(); | |||||||||||||||||||||||||||||||
| 310 | 3 | return $rslt; | |||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||
| 313 | 7 | ▶ | sub use_ok ($;@) { | ||||||||||||||||||||||||||||||
|
Subroutine
use_ok: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 314 | 7 | my ( $module, @arg ) = @_; | |||||||||||||||||||||||||||||||
| 315 | 7 | ▶ | defined $module | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 316 | or croak ERR_MODULE_UNDEF; | ||||||||||||||||||||||||||||||||
| 317 | 6 | ▶ | my $version = ( defined $arg[0] && $arg[0] =~ LAX_VERSION ) ? | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $arg[0] and $arg[0] =~ /(?x: (?x:
v (?-x:[0-9]+) (?-x: (?-x:\.[0-9]+)+ (?-x:_[0-9]+)? )?
|
(?-x:[0-9]+)? (?-x:\.[0-9]+){2,} (?-x:_[0-9]+)?
) | (?x: (?-x:[0-9]+) (?-x: (?-x:\.[0-9]+) | \. )? (?-x:_[0-9]+)?
|
(?-x:\.[0-9]+) (?-x:_[0-9]+)?
) )/
MC/DC100%2/2
defined $arg[0] and $arg[0] =~ /(?x: (?x:
v (?-x:[0-9]+) (?-x: (?-x:\.[0-9]+)+ (?-x:_[0-9]+)? )?
|
(?-x:[0-9]+)? (?-x:\.[0-9]+){2,} (?-x:_[0-9]+)?
) | (?x: (?-x:[0-9]+) (?-x: (?-x:\.[0-9]+) | \. )? (?-x:_[0-9]+)?
|
(?-x:\.[0-9]+) (?-x:_[0-9]+)?
) )/
defined $arg[0]
$arg[0] =~ /(?x: (?x:
v (?-x:[0-9]+) (?-x: (?-x:\.[0-9]+)+ (?-x:_[0-9]+)? )?
|
(?-x:[0-9]+)? (?-x:\.[0-9]+){2,} (?-x:_[0-9]+)?
) | (?x: (?-x:[0-9]+) (?-x: (?-x:\.[0-9]+) | \. )? (?-x:_[0-9]+)?
|
(?-x:\.[0-9]+) (?-x:_[0-9]+)?
) )/
Truth table100%3/3
A and B
A= defined $arg[0]B= $arg[0] =~ /(?x: (?x:
v (?-x:[0-9]+) (?-x: (?-x:\.[0-9]+)+ (?-x:_[0-9]+)? )?
|
(?-x:[0-9]+)? (?-x:\.[0-9]+){2,} (?-x:_[0-9]+)?
) | (?x: (?-x:[0-9]+) (?-x: (?-x:\.[0-9]+) | \. )? (?-x:_[0-9]+)?
|
(?-x:\.[0-9]+) (?-x:_[0-9]+)?
) )/
| |||||||||||||||||||||||||||||||||
| 318 | shift @arg : undef; | ||||||||||||||||||||||||||||||||
| 319 | 6 | my $ctx = Test2::API::context(); | |||||||||||||||||||||||||||||||
| 320 | 6 | my $rslt = _load_module_ok( TEST_MORE_OPT, | |||||||||||||||||||||||||||||||
| 321 | $module, $version, \@arg, undef, | ||||||||||||||||||||||||||||||||
| 322 | sprintf( TEST_MORE_ERROR_CONTEXT, use => $module ), | ||||||||||||||||||||||||||||||||
| 323 | ); | ||||||||||||||||||||||||||||||||
| 324 | 6 | $ctx->release(); | |||||||||||||||||||||||||||||||
| 325 | 6 | return $rslt; | |||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||
| 328 | 4 | ▶ | sub _make_pragma_key { | ||||||||||||||||||||||||||||||
|
Subroutine
_make_pragma_key: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 329 | 4 | return join '', __PACKAGE__, '/', $_; | |||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||
| 332 | 4 | ▶ | sub _caller_class { | ||||||||||||||||||||||||||||||
|
Subroutine
_caller_class: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 333 | 4 | my ( $lvl ) = @_; | |||||||||||||||||||||||||||||||
| 334 | 4 | ▶ | my ( $pkg ) = caller( $lvl || 1 ); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$lvl || 1
MC/DC0%0/1
$lvl || 1
$lvl
Truth table50%1/2
A
A= $lvl
| |||||||||||||||||||||||||||||||||
| 335 | 4 | ▶ | my $code = $pkg->can( 'CLASS' ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 336 | or croak ERR_MODULE_UNDEF; | ||||||||||||||||||||||||||||||||
| 337 | 1 | return $code->(); | |||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||
| 340 | { | ||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||
| 342 | 10 | my %default_hint = ( | |||||||||||||||||||||||||||||||
| 343 | load_error => DEFAULT_LOAD_ERROR, | ||||||||||||||||||||||||||||||||
| 344 | ); | ||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||
| 346 | 42 | ▶ | sub __get_hint_hash { | ||||||||||||||||||||||||||||||
|
Subroutine
__get_hint_hash: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 347 | 42 | my ( $level ) = @_; | |||||||||||||||||||||||||||||||
| 348 | 42 | ▶ | $level ||= 0; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$level ||= 0
MC/DC100%1/1
$level ||= 0
$level
Truth table100%2/2
A
A= $level
| |||||||||||||||||||||||||||||||||
| 349 | 42 | my $hint_hash = ( caller( $level ) )[ CALLER_HINT_HASH ]; | |||||||||||||||||||||||||||||||
| 350 | 42 | my %rslt = %default_hint; | |||||||||||||||||||||||||||||||
| 351 | 42 | if ( HINTS_AVAILABLE ) { | |||||||||||||||||||||||||||||||
| 352 | 42 | foreach ( keys %{ $hint_hash } ) { | |||||||||||||||||||||||||||||||
| 353 | 4 | my ( $hint_pkg, $hint_key ) = split qr< / >smx; | |||||||||||||||||||||||||||||||
| 354 | __PACKAGE__ eq $hint_pkg | ||||||||||||||||||||||||||||||||
| 355 | 4 | ▶ | and $rslt{$hint_key} = $hint_hash->{$_}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||
| 358 | 42 | return \%rslt; | |||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||
| 362 | 10 | ▶ | sub __build_load_eval { | ||||||||||||||||||||||||||||||
|
Subroutine
__build_load_eval: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||
| 363 | 73 | my @arg = @_; | |||||||||||||||||||||||||||||||
| 364 | 73 | ▶ | HASH_REF eq ref $arg[0] | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 365 | or unshift @arg, {}; | ||||||||||||||||||||||||||||||||
| 366 | 73 | my ( $opt, $module, $version, $import ) = @arg; | |||||||||||||||||||||||||||||||
| 367 | 73 | my @eval = "use $module"; | |||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||
| 369 | 73 | ▶ | defined $version | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 370 | and push @eval, $version; | ||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||
| 372 | 73 | ▶ | if ( $import && @{ $import } ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$import and @{$import;}
MC/DC100%2/2
$import and @{$import;}
$import
@{$import;}
Truth table100%3/3
A and B
A= $importB= @{$import;}
| |||||||||||||||||||||||||||||||||
| 373 | 19 | push @eval, "qw{ @{ $import } }"; | |||||||||||||||||||||||||||||||
| 374 | ▶ | } elsif ( defined $import xor not $opt->{require} ) { | |||||||||||||||||||||||||||||||
|
Condition100%4/4
defined $import xor not $opt->{"require"}
MC/DC100%2/2
defined $import xor not $opt->{"require"}
defined $import
not $opt->{"require"}
Truth table100%4/4
A xor not(B)
A= defined $importB= not $opt->{"require"}
| |||||||||||||||||||||||||||||||||
| 375 | # Do nothing. | ||||||||||||||||||||||||||||||||
| 376 | } else { | ||||||||||||||||||||||||||||||||
| 377 | 12 | push @eval, '()'; | |||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||
| 380 | 73 | return "@eval;"; | |||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||
| 383 | 37 | ▶ | sub _validate_args { | ||||||||||||||||||||||||||||||
|
Subroutine
_validate_args: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||
| 384 | 37 | ( my $max_arg, local @ARGV ) = @_; | |||||||||||||||||||||||||||||||
| 385 | 37 | my $opt = _parse_opts( __get_hint_hash( 2 ) ); | |||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||
| 387 | 34 | ▶ | if ( $max_arg && @ARGV > $max_arg ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$max_arg and @ARGV > $max_arg
MC/DC100%2/2
$max_arg and @ARGV > $max_arg
$max_arg
@ARGV > $max_arg
Truth table100%3/3
A and B
A= $max_argB= @ARGV > $max_arg
| |||||||||||||||||||||||||||||||||
| 388 | 2 | ( my $sub_name = ( caller 1 )[3] ) =~ s/ .* :: //smx; | |||||||||||||||||||||||||||||||
| 389 | 2 | croak sprintf '%s() takes at most %d arguments', $sub_name, $max_arg; | |||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||
| 392 | 32 | my ( $module, $version, $import, $name, @diag ) = @ARGV; | |||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||
| 394 | 32 | ▶ | defined $module | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 395 | or $module = _caller_class( 2 ); | ||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||
| 397 | 29 | ▶ | if ( defined $version ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 398 | 7 | ▶ | $version =~ LAX_VERSION | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 399 | or croak sprintf ERR_VERSION_BAD, $version; | ||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||
| 402 | 26 | ▶ | not defined $import | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $import or "ARRAY" eq ref $import
MC/DC100%2/2
not defined $import or "ARRAY" eq ref $import
not defined $import
"ARRAY" eq ref $import
Truth table100%3/3
not(A) or B
A= not defined $importB= "ARRAY" eq ref $import
| |||||||||||||||||||||||||||||||||
| 403 | or ARRAY_REF eq ref $import | ||||||||||||||||||||||||||||||||
| 404 | or croak ERR_IMPORT_BAD; | ||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||
| 406 | 23 | return ( $opt, $module, $version, $import, $name, @diag ); | |||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||
| 409 | 32 | ▶ | sub _eval_in_pkg { | ||||||||||||||||||||||||||||||
|
Subroutine
_eval_in_pkg: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 410 | 32 | my ( $eval, $pkg, $file, $line ) = @_; | |||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||
| 412 | 32 | my $e = <<"EOD"; | |||||||||||||||||||||||||||||||
| 413 | package $pkg; | ||||||||||||||||||||||||||||||||
| 414 | #line $line "$file" | ||||||||||||||||||||||||||||||||
| 415 | $eval; | ||||||||||||||||||||||||||||||||
| 416 | 1; | ||||||||||||||||||||||||||||||||
| 417 | EOD | ||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||
| 419 | # We need the stringy eval() so we can mess with Perl's concept of | ||||||||||||||||||||||||||||||||
| 420 | # what the current file and line number are for the purpose of | ||||||||||||||||||||||||||||||||
| 421 | # formatting the exception, AND as a convenience to get symbols | ||||||||||||||||||||||||||||||||
| 422 | # imported. | ||||||||||||||||||||||||||||||||
| 423 | 32 | my $rslt = eval $e; ## no critic (ProhibitStringyEval) | |||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||
| 425 | 32 | return $rslt; | |||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||
| 428 | 11 | ▶ | sub _get_call_info { | ||||||||||||||||||||||||||||||
|
Subroutine
_get_call_info: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||
| 429 | 11 | my $lvl = 0; | |||||||||||||||||||||||||||||||
| 430 | 11 | ▶ | while ( my @info = caller $lvl++ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 431 | 33 | ▶ | __PACKAGE__ eq $info[0] | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 432 | and next; | ||||||||||||||||||||||||||||||||
| 433 | 11 | ▶ | $info[1] =~ m/ \A [(] eval \b /smx # ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 434 | or return @info; | ||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||
| 436 | 0 | confess 'Bug - Unable to determine caller'; | |||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||
| 439 | 10 | 1; | |||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||
| 441 | __END__ | ||||||||||||||||||||||||||||||||