blib/lib/App/perlimports/Sandbox.pm

filter: Statementstmt 100% 66 / 66 Branchbran 25.0% 1 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 22 / 22 Podpod 100% 2 / 2 totaltotal 94.9% 94 / 99 CC 4 SCAR 1.9
CC
4
Cov
95%
__ANON__
3.5
_is_trial_load_warning
2.0
eval_pkg
1.0
CRAP 1.2
« test-data/lib/Local/ViaExporter.pm ↑ Summary test-data/lib/Local/MaxFacade.pm »
1 package App::perlimports::Sandbox;
2  
3 148 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 145 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 118 our $VERSION = '0.000067';
7  
8 127 ▶use Data::UUID ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 {
11 118 my $du = Data::UUID->new;
12  
13 569 ▶ sub pkg_for {
Subroutine pkg_for: called CC=1 SCAR=0.0
Pod documented
14 569 my $module_name = shift;
15 569 my $unique = 'A' . $du->create_str;
16 569 $unique =~ s{-}{}g;
17  
18 565 return sprintf(
19 'Local::%s::%s',
20 $module_name,
21 $unique
22 );
23 }
24 }
25  
26 118 ▶sub eval_pkg {
Subroutine eval_pkg: called CC=1 SCAR=0.0
Pod documented
27 284 my $module_name = shift;
28 284 my $content = shift;
29  
30 284 my $pkg = pkg_for($module_name);
31  
32 284 my $to_eval = <<"EOF";
33 package $pkg;
34 $content;
35 1;
36 EOF
37  
38 ## no critic (Variables::RequireInitializationForLocalVars)
39 284 local $@;
40  
41 # We only care about whether the eval throws an error. Trial-loading an
42 # arbitrary module can emit the "Attempt to call undefined import method"
43 # warning when a module has no import(), which we don't want to leak to
44 # the user's terminal. We suppress only that specific noise and re-dispatch
45 # anything else, so genuine diagnostics from a broken module still surface.
46 284 my $prev_warn = $SIG{__WARN__};
47 3 ▶ local $SIG{__WARN__} = sub {
Subroutine __ANON__: called CC=3 SCAR=12.5
48 3 my ($msg) = @_;
49 3 ▶ return if _is_trial_load_warning($msg);
Branch: 1 branch
BranchTrueFalseTotal
if _is_trial_load_warning($msg) 2 0 2
50 1 ▶ $prev_warn ? $prev_warn->($msg) : print {*STDERR} $msg;
Branch: 1 branch
BranchTrueFalseTotal
$prev_warn ? : 0 0 0
51 284 };
52 ## no critic (BuiltinFunctions::ProhibitStringyEval,ErrorHandling::RequireCheckingReturnValueOfEval)
53 284 ▶ eval $to_eval;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 283 my $e = $@;
56 283 return $e;
57 }
58  
59 # Recognize the noisy warning emitted when we trial-load a module that has no
60 # import() method. Perl's wording for this diagnostic changed from "undefined"
61 # to "missing" in the 5.44 development cycle, so match either variant.
62 6 ▶sub _is_trial_load_warning {
Subroutine _is_trial_load_warning: called CC=2 SCAR=7.1
63 6 my $msg = shift;
64 6 ▶ return defined $msg
Condition66%2/3
defined $msg && $msg =~ /Attempt to call (?:undefined|missing) import method/
!ll&&!rl&&r
014
MC/DC50%1/2
defined $msg && $msg =~ /Attempt to call (?:undefined|missing) import method/
defined $msg $msg =~ /Attempt to call (?:undefined|missing) import method/
Truth table66%2/3
A && B
A= defined $msgB= $msg =~ /Attempt to call (?:undefined|missing) import method/
ABresult
0X0
100
111
65 && $msg =~ m{Attempt to call (?:undefined|missing) import method};
66 }
67  
68 118 1;
69  
70 # ABSTRACT: Internal Tools for perlimports
71  
72 __END__
« test-data/lib/Local/ViaExporter.pm ↑ Summary test-data/lib/Local/MaxFacade.pm »