blib/lib/Perinci/CmdLine/Any.pm

filter: Statementstmt 74.2% 26 / 35 Branchbran 33.3% 4 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod 0.0% 0 / 1 totaltotal 64.7% 33 / 51 CC 9 SCAR 24.1
CC
9
Cov
64%
new
14.7
import
2.0
BEGIN
1.0
CRAP 11.2
↑ Summary
1 package Perinci::CmdLine::Any;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 # IFUNBUILT
5 # use warnings;
6 # END IFUNBUILT
7  
8 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
9 2 our $DATE = '2022-10-19'; # DATE
10 2 our $DIST = 'Perinci-CmdLine-Any'; # DIST
11 2 our $VERSION = '0.154'; # VERSION
12  
13 2 my %Opts = (
14 -prefer_lite => 1,
15 );
16  
17 1 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
18 1 my ($class, %args) = @_;
19 1 $Opts{$_} = $args{$_} for keys %args;
20 }
21  
22 1 ▶sub new {
Subroutine new: called CC=8 SCAR=26.9
Pod undocumented
23 1 my $class = shift;
24  
25 1 my @mods;
26 1 my $env = $ENV{PERINCI_CMDLINE_ANY};
27 1 ▶ if ($env) {
Branch: 2 branches
BranchTrueFalseTotal
if ($env) { } 0 1 1
elsif ($Opts{'-prefer_lite'}) { } 1 0 1
28 0 ▶ if ($env eq 'classic') {
Branch: 2 branches
BranchTrueFalseTotal
if ($env eq 'classic') { } 0 0 0
elsif ($env eq 'lite') { } 0 0 0
29 0 $env = 'Perinci::CmdLine::Classic';
30 } elsif ($env eq 'lite') {
31 0 $env = 'Perinci::CmdLine::Lite';
32 }
33 0 @mods = ($env);
34 } elsif ($Opts{-prefer_lite}) {
35 1 @mods = qw(Perinci::CmdLine::Lite Perinci::CmdLine::Classic);
36 } else {
37 0 @mods = qw(Perinci::CmdLine::Classic Perinci::CmdLine::Lite);
38 }
39  
40 1 for my $i (1..@mods) {
41 1 my $mod = $mods[$i-1];
42 1 (my $modpm = "$mod.pm") =~ s!::!/!g;
43 1 ▶ if ($i == @mods) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == @mods) { } 0 1 1
44 0 require $modpm;
45 0 return $mod->new(@_);
46 } else {
47 1 my $res;
48 1 eval {
49 1 require $modpm;
50 1 $res = $mod->new(@_);
51 };
52 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 1 1
53 0 warn "Can't load $mod: $@";
54 0 next;
55 } else {
56 1 return $res;
57 }
58 }
59 }
60 }
61  
62 2 1;
63 # ABSTRACT: Choose Perinci::CmdLine implementation (::Lite or ::Classic)
64  
65 __END__
↑ Summary