« lib/Skilletor/Gitignore.pm
↑ Summary
/usr/local/lib/perl5/site_perl/5.44.0/Method/Generate/Constructor.pm »
| 1 | package Module::Implementation; | ||||||||||||||||||||||||||||
| 2 | # git description: v0.08-2-gd599347 | ||||||||||||||||||||||||||||
| 3 | 7 | $Module::Implementation::VERSION = '0.09'; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Module::Runtime 0.012 qw( require_module ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # This is needed for the benefit of Test::CleanNamespaces, which in turn loads | ||||||||||||||||||||||||||||
| 12 | # Package::Stash, which in turn loads this module and expects a minimum | ||||||||||||||||||||||||||||
| 13 | # version. | ||||||||||||||||||||||||||||
| 14 | 7 | ▶ | unless ( exists $Module::Implementation::{VERSION} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $Module::Implementation::{"VERSION"} and ${$Module::Implementation::{"VERSION"};}
MC/DC0%0/2
exists $Module::Implementation::{"VERSION"} and ${$Module::Implementation::{"VERSION"};}
exists $Module::Implementation::{"VERSION"}
${$Module::Implementation::{"VERSION"};}
Truth table33%1/3
A and B
A= exists $Module::Implementation::{"VERSION"}B= ${$Module::Implementation::{"VERSION"};}
| |||||||||||||||||||||||||||||
| 15 | 7 | && ${ $Module::Implementation::{VERSION} } ) { | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | $Module::Implementation::{VERSION} = \42; | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 7 | my %Implementation; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 14 | ▶ | sub build_loader_sub { | ||||||||||||||||||||||||||
|
Subroutine
build_loader_sub: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 14 | my $caller = caller(); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 14 | return _build_loader( $caller, @_ ); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 14 | ▶ | sub _build_loader { | ||||||||||||||||||||||||||
|
Subroutine
_build_loader: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 29 | 14 | my $package = shift; | |||||||||||||||||||||||||||
| 30 | 14 | my %args = @_; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 14 | my @implementations = @{ $args{implementations} }; | |||||||||||||||||||||||||||
| 33 | 14 | ▶ | my @symbols = @{ $args{symbols} || [] }; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{'symbols'} || []
MC/DC0%0/1
$args{'symbols'} || []
$args{'symbols'}
Truth table50%1/2
A
A= $args{'symbols'}
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 14 | my $implementation; | |||||||||||||||||||||||||||
| 36 | 14 | my $env_var = uc $package; | |||||||||||||||||||||||||||
| 37 | 14 | $env_var =~ s/::/_/g; | |||||||||||||||||||||||||||
| 38 | 14 | $env_var .= '_IMPLEMENTATION'; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 14 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | my ( $implementation, $loaded ) = _load_implementation( | ||||||||||||||||||||||||||||
| 42 | $package, | ||||||||||||||||||||||||||||
| 43 | 14 | $ENV{$env_var}, | |||||||||||||||||||||||||||
| 44 | \@implementations, | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 14 | $Implementation{$package} = $implementation; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 14 | _copy_symbols( $loaded, $package, \@symbols ); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 14 | return $loaded; | |||||||||||||||||||||||||||
| 52 | 14 | }; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 7 | ▶ | sub implementation_for { | ||||||||||||||||||||||||||
|
Subroutine
implementation_for: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 7 | my $package = shift; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 7 | return $Implementation{$package}; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 14 | ▶ | sub _load_implementation { | ||||||||||||||||||||||||||
|
Subroutine
_load_implementation: called CC=7 SCAR=29.7
| |||||||||||||||||||||||||||||
| 62 | 14 | my $package = shift; | |||||||||||||||||||||||||||
| 63 | 14 | my $env_value = shift; | |||||||||||||||||||||||||||
| 64 | 14 | my $implementations = shift; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 14 | ▶ | if ($env_value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | die "$env_value is not a valid implementation for $package" | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | unless grep { $_ eq $env_value } @{$implementations}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | my $requested = "${package}::$env_value"; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # Values from the %ENV hash are tainted. We know it's safe to untaint | ||||||||||||||||||||||||||||
| 73 | # this value because the value was one of our known implementations. | ||||||||||||||||||||||||||||
| 74 | 0 | ($requested) = $requested =~ /^(.+)$/; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 77 | 0 | require_module($requested); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 80 | 0 | require Carp; | |||||||||||||||||||||||||||
| 81 | 0 | Carp::croak("Could not load $requested: $_"); | |||||||||||||||||||||||||||
| 82 | 0 | }; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | return ( $env_value, $requested ); | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | else { | ||||||||||||||||||||||||||||
| 87 | 14 | my $err; | |||||||||||||||||||||||||||
| 88 | 14 | for my $possible ( @{$implementations} ) { | |||||||||||||||||||||||||||
| 89 | 14 | my $try = "${package}::$possible"; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 14 | my $ok; | |||||||||||||||||||||||||||
| 92 | 14 | ▶ | try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 93 | 14 | require_module($try); | |||||||||||||||||||||||||||
| 94 | 14 | $ok = 1; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | $err .= $_ if defined $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 14 | }; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 14 | ▶ | return ( $possible, $try ) if $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | require Carp; | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ( defined $err && length $err ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $err and length $err
MC/DC0%0/2
defined $err and length $err
defined $err
length $err
Truth table0%0/3
A and B
A= defined $errB= length $err
| |||||||||||||||||||||||||||||
| 105 | 0 | Carp::croak( | |||||||||||||||||||||||||||
| 106 | "Could not find a suitable $package implementation: $err"); | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | else { | ||||||||||||||||||||||||||||
| 109 | 0 | Carp::croak( | |||||||||||||||||||||||||||
| 110 | 'Module::Runtime failed to load a module but did not throw a real error. This should never happen. Something is very broken' | ||||||||||||||||||||||||||||
| 111 | ); | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 14 | ▶ | sub _copy_symbols { | ||||||||||||||||||||||||||
|
Subroutine
_copy_symbols: called CC=8 SCAR=25.2
| |||||||||||||||||||||||||||||
| 117 | 14 | my $from_package = shift; | |||||||||||||||||||||||||||
| 118 | 14 | my $to_package = shift; | |||||||||||||||||||||||||||
| 119 | 14 | my $symbols = shift; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 14 | for my $sym ( @{$symbols} ) { | |||||||||||||||||||||||||||
| 122 | 84 | ▶ | my $type = $sym =~ s/^([\$\@\%\&\*])// ? $1 : '&'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 84 | my $from = "${from_package}::$sym"; | |||||||||||||||||||||||||||
| 125 | 84 | my $to = "${to_package}::$sym"; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||
| 128 | 7 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 129 | 7 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | # Copied from Exporter | ||||||||||||||||||||||||||||
| 132 | 84 | *{$to} | |||||||||||||||||||||||||||
| 133 | 84 | ▶ | = $type eq '&' ? \&{$from} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | ▶ | : $type eq '$' ? \${$from} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | : $type eq '@' ? \@{$from} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | : $type eq '%' ? \%{$from} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | : $type eq '*' ? *{$from} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | : die | ||||||||||||||||||||||||||||
| 139 | "Can't copy symbol from $from_package to $to_package: $type$sym"; | ||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 7 | 1; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | # ABSTRACT: Loads one of several alternate underlying implementations for a module | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | __END__ | ||||||||||||||||||||||||||||