| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Perinci::CmdLine::Any; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-06-20'; # DATE |
|
4
|
|
|
|
|
|
|
our $VERSION = '0.151'; # VERSION |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# IFUNBUILT |
|
7
|
|
|
|
|
|
|
# use strict; |
|
8
|
|
|
|
|
|
|
# use warnings; |
|
9
|
|
|
|
|
|
|
# END IFUNBUILT |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my %Opts = ( |
|
12
|
|
|
|
|
|
|
-prefer_lite => 1, |
|
13
|
|
|
|
|
|
|
); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub import { |
|
16
|
1
|
|
|
1
|
|
8
|
my ($class, %args) = @_; |
|
17
|
1
|
|
|
|
|
2043
|
$Opts{$_} = $args{$_} for keys %args; |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
|
21
|
1
|
|
|
1
|
0
|
3040
|
my $class = shift; |
|
22
|
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
2
|
my @mods; |
|
24
|
1
|
|
|
|
|
4
|
my $env = $ENV{PERINCI_CMDLINE_ANY}; |
|
25
|
1
|
50
|
|
|
|
6
|
if ($env) { |
|
|
|
50
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
0
|
if ($env eq 'classic') { |
|
|
|
0
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
0
|
$env = 'Perinci::CmdLine::Classic'; |
|
28
|
|
|
|
|
|
|
} elsif ($env eq 'lite') { |
|
29
|
0
|
|
|
|
|
0
|
$env = 'Perinci::CmdLine::Lite'; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
0
|
|
|
|
|
0
|
@mods = ($env); |
|
32
|
|
|
|
|
|
|
} elsif ($Opts{-prefer_lite}) { |
|
33
|
1
|
|
|
|
|
4
|
@mods = qw(Perinci::CmdLine::Lite Perinci::CmdLine::Classic); |
|
34
|
|
|
|
|
|
|
} else { |
|
35
|
0
|
|
|
|
|
0
|
@mods = qw(Perinci::CmdLine::Classic Perinci::CmdLine::Lite); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
5
|
for my $i (1..@mods) { |
|
39
|
1
|
|
|
|
|
3
|
my $mod = $mods[$i-1]; |
|
40
|
1
|
|
|
|
|
2
|
my $modpm = $mod; $modpm =~ s!::!/!g; $modpm .= ".pm"; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
3
|
|
|
41
|
1
|
50
|
|
|
|
5
|
if ($i == @mods) { |
|
42
|
0
|
|
|
|
|
0
|
require $modpm; |
|
43
|
0
|
|
|
|
|
0
|
return $mod->new(@_); |
|
44
|
|
|
|
|
|
|
} else { |
|
45
|
1
|
|
|
|
|
2
|
my $res; |
|
46
|
1
|
|
|
|
|
2
|
eval { |
|
47
|
1
|
|
|
|
|
1698
|
require $modpm; |
|
48
|
1
|
|
|
|
|
24093
|
$res = $mod->new(@_); |
|
49
|
|
|
|
|
|
|
}; |
|
50
|
1
|
50
|
|
|
|
6129
|
if ($@) { |
|
51
|
0
|
|
|
|
|
0
|
next; |
|
52
|
|
|
|
|
|
|
} else { |
|
53
|
1
|
|
|
|
|
10
|
return $res; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
|
60
|
|
|
|
|
|
|
# ABSTRACT: Choose Perinci::CmdLine implementation (::Lite or ::Classic) |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=pod |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=encoding UTF-8 |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 NAME |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Perinci::CmdLine::Any - Choose Perinci::CmdLine implementation (::Lite or ::Classic) |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 VERSION |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This document describes version 0.151 of Perinci::CmdLine::Any (from Perl distribution Perinci-CmdLine-Any), released on 2019-06-20. |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
In your command-line script (this will pick ::Lite first): |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
#!perl |
|
81
|
|
|
|
|
|
|
use Perinci::CmdLine::Any; |
|
82
|
|
|
|
|
|
|
Perinci::CmdLine::Any->new(url => '/Package/func')->run; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
In your command-line script (this will pick ::Classic first, and falls back to |
|
85
|
|
|
|
|
|
|
::Lite): |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#!perl |
|
88
|
|
|
|
|
|
|
use Perinci::CmdLine::Any -prefer_lite=>0; |
|
89
|
|
|
|
|
|
|
Perinci::CmdLine::Any->new(url => '/Package/func')->run; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This module lets you use L<Perinci::CmdLine::Lite> or |
|
94
|
|
|
|
|
|
|
L<Perinci::CmdLine::Classic>. |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
If you want to force using a specific class, you can set the |
|
97
|
|
|
|
|
|
|
C<PERINCI_CMDLINE_ANY> environment variable, e.g. the command below will only |
|
98
|
|
|
|
|
|
|
try to use Perinci::CmdLine::Classic: |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
% PERINCI_CMDLINE_ANY=Perinci::CmdLine::Classic yourapp.pl |
|
101
|
|
|
|
|
|
|
% PERINCI_CMDLINE_ANY=classic yourapp.pl |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
If you want to prefer to Perinci::CmdLine::Classic (but user will still be able |
|
104
|
|
|
|
|
|
|
to override using C<PERINCI_CMDLINE_ANY>): |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
use Perinci::CmdLine::Any -prefer_lite => 0; |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=for Pod::Coverage ^(new)$ |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 ENVIRONMENT |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 PERINCI_CMDLINE_ANY => str |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Either specify module name, or C<lite> or C<classic>. |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 HOMEPAGE |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Please visit the project's homepage at L<https://metacpan.org/release/Perinci-CmdLine-Any>. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 SOURCE |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Source repository is at L<https://github.com/perlancar/perl-Perinci-CmdLine-Any>. |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 BUGS |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-CmdLine-Any> |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
|
129
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
|
130
|
|
|
|
|
|
|
feature. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
L<Perinci::CmdLine::Lite>, L<Perinci::CmdLine::Classic> |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Another alternative backend, but not available through Perinci::CmdLine::Any |
|
137
|
|
|
|
|
|
|
since it works by generating script instead: L<Perinci::CmdLine::Inline> |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 AUTHOR |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
perlancar <perlancar@cpan.org> |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
This software is copyright (c) 2019, 2017, 2016, 2015, 2014 by perlancar@cpan.org. |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
148
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |