—## no critic: Subroutines::ProhibitSubroutinePrototypes
package
Getopt::Long::Patch::DumpAndExit;
use
5.010001;
use
strict;
no
warnings;
use
Data::Dmp;
use
Module::Patch ();
our
$AUTHORITY
=
'cpan:PERLANCAR'
;
# AUTHORITY
our
$DATE
=
'2022-08-10'
;
# DATE
our
$DIST
=
'Getopt-Long-Dump'
;
# DIST
our
$VERSION
=
'0.112'
;
# VERSION
our
%config
;
sub
_dump {
"# BEGIN DUMP $config{-tag}\n"
;
local
$Data::Dmp::OPT_DEPARSE
= 0;
say
dmp(
$_
[0]);
"# END DUMP $config{-tag}\n"
;
}
sub
_GetOptions(@) {
if
(
ref
(
$_
[0]) eq
'HASH'
) {
# discard hash storage
my
$h
=
shift
;
}
_dump([
@_
]);
$config
{-exit_method} eq
'exit'
?
exit
(0) :
die
;
}
sub
_GetOptionsFromArray(@) {
# discard array
shift
;
if
(
ref
(
$_
[0]) eq
'HASH'
) {
# discard hash storage
my
$h
=
shift
;
}
_dump([
@_
]);
$config
{-exit_method} eq
'exit'
?
exit
(0) :
die
;
}
sub
_GetOptionsFromString(@) {
# discard string
shift
;
if
(
ref
(
$_
[0]) eq
'HASH'
) {
# discard hash storage
my
$h
=
shift
;
}
_dump([
@_
]);
$config
{-exit_method} eq
'exit'
?
exit
(0) :
die
;
}
sub
patch_data {
return
{
v
=> 3,
patches
=> [
{
action
=>
'replace'
,
sub_name
=>
'GetOptions'
,
code
=> \
&_GetOptions
,
},
{
action
=>
'replace'
,
sub_name
=>
'GetOptionsFromArray'
,
code
=> \
&_GetOptionsFromArray
,
},
{
action
=>
'replace'
,
sub_name
=>
'GetOptionsFromString'
,
code
=> \
&_GetOptionsFromString
,
},
],
config
=> {
-tag
=> {
schema
=>
'str*'
,
default
=>
'TAG'
,
},
-exit_method
=> {
schema
=>
'str*'
,
default
=>
'exit'
,
},
},
};
}
1;
# ABSTRACT: Patch Getopt::Long to dump option spec and exit
__END__
=pod
=encoding UTF-8
=head1 NAME
Getopt::Long::Patch::DumpAndExit - Patch Getopt::Long to dump option spec and exit
=head1 VERSION
This document describes version 0.112 of Getopt::Long::Patch::DumpAndExit (from Perl distribution Getopt-Long-Dump), released on 2022-08-10.
=head1 DESCRIPTION
This patch can be used to extract Getopt::Long options specification from a
script by running the script but exiting early after getting the specification.
=for Pod::Coverage ^(patch_data)$
=head1 HOMEPAGE
Please visit the project's homepage at L<https://metacpan.org/release/Getopt-Long-Dump>.
=head1 SOURCE
Source repository is at L<https://github.com/perlancar/perl-Getopt-Long-Dump>.
=head1 AUTHOR
perlancar <perlancar@cpan.org>
=head1 CONTRIBUTING
To contribute, you can send patches by email/via RT, or send pull requests on
GitHub.
Most of the time, you don't need to build the distribution yourself. You can
simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your
system), you can install L<Dist::Zilla>,
L<Dist::Zilla::PluginBundle::Author::PERLANCAR>,
L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other
Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond
that are considered a bug and can be reported to me.
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2022, 2016, 2015, 2014 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=head1 BUGS
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Getopt-Long-Dump>
When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.
=cut