| 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
| |||||||||||||||
| 28 | 0 | ▶ | if ($env eq 'classic') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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__ | ||||||||||||||