« blib/lib/Perinci/CmdLine/PluginBase.pm
↑ Summary
blib/lib/Perinci/CmdLine/Plugin/Run/DebugCompletion.pm »
| 1 | package Perinci::CmdLine::Plugin::Run::DumpObject; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # put pragmas + Log::ger here | ||||||||||||||||||||
| 4 | 86 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 86 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 86 | ▶ | use Log::ger; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 86 | ▶ | use parent 'Perinci::CmdLine::PluginBase'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | # put other modules alphabetically here | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | # put global variables alphabetically here | ||||||||||||||||||||
| 12 | 86 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||
| 13 | 86 | our $DATE = '2023-11-23'; # DATE | |||||||||||||||||||
| 14 | 86 | our $DIST = 'Perinci-CmdLine-Lite'; # DIST | |||||||||||||||||||
| 15 | 86 | our $VERSION = '1.929'; # VERSION | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 85 | ▶ | sub meta { | ||||||||||||||||||
|
Subroutine
meta: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 18 | return { | ||||||||||||||||||||
| 19 | 85 | summary => 'Dump object mode', | |||||||||||||||||||
| 20 | description => <<'_', | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | This plugin is included by default at a high priority and activated if the | ||||||||||||||||||||
| 23 | PERINCI_CMDLINE_DUMP_OBJECT environmnent is true. | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | _ | ||||||||||||||||||||
| 26 | conf => { | ||||||||||||||||||||
| 27 | }, | ||||||||||||||||||||
| 28 | prio => 10, # high | ||||||||||||||||||||
| 29 | tags => ['category:run-handler', 'category:debugging'], | ||||||||||||||||||||
| 30 | }; | ||||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 82 | ▶ | sub on_run { | ||||||||||||||||||
|
Subroutine
on_run: called CC=4 SCAR=24.6
Pod
undocumented
| |||||||||||||||||||||
| 34 | 82 | my ($self, $r) = @_; | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 82 | ▶ | return [100] unless $ENV{PERINCI_CMDLINE_DUMP_OBJECT}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | require Data::Dump; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 0 | local $r->{in_dump_object} = 1; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | # check whether subcommand is defined. try to search from --cmd, first | ||||||||||||||||||||
| 43 | # command-line argument, or default_subcommand. | ||||||||||||||||||||
| 44 | 0 | $self->cmdline->hook_before_parse_argv($r); | |||||||||||||||||||
| 45 | 0 | $self->cmdline->_parse_argv1($r); | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 0 | ▶ | if ($r->{read_env}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | 0 | my $env_words = $self->cmdline->_read_env($r); | |||||||||||||||||||
| 49 | 0 | unshift @ARGV, @$env_words; | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | my $scd = $r->{subcommand_data}; | |||||||||||||||||||
| 53 | # we do get_meta() currently because some common option like dry_run is | ||||||||||||||||||||
| 54 | # added in hook_after_get_meta(). | ||||||||||||||||||||
| 55 | 0 | ▶ | my $meta = $self->cmdline->get_meta($r, $scd->{url} // $self->cmdline->{url}); | ||||||||||||||||||
|
Condition0%0/3
$scd->{"url"} // $self->cmdline->{"url"}
MC/DC0%0/2
$scd->{"url"} // $self->cmdline->{"url"}
$scd->{"url"}
$self->cmdline->{"url"}
Truth table0%0/3
A // B
A= $scd->{"url"}B= $self->cmdline->{"url"}
| |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | # additional information, because scripts often put their metadata in 'main' | ||||||||||||||||||||
| 58 | # package | ||||||||||||||||||||
| 59 | { | ||||||||||||||||||||
| 60 | 0 | ▶ | no warnings 'once'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||
| 61 | 0 | $self->cmdline->{'x.main.spec'} = \%main::SPEC; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | my $label = $ENV{PERINCI_CMDLINE_DUMP_OBJECT}; | |||||||||||||||||||
| 65 | 0 | my $dump = join( | |||||||||||||||||||
| 66 | "", | ||||||||||||||||||||
| 67 | "# BEGIN DUMP $label\n", | ||||||||||||||||||||
| 68 | Data::Dump::dump($self->cmdline), "\n", | ||||||||||||||||||||
| 69 | "# END DUMP $label\n", | ||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | $r->{res} = [ | ||||||||||||||||||||
| 73 | 0 | 200, "OK", $dump, | |||||||||||||||||||
| 74 | { | ||||||||||||||||||||
| 75 | stream => 0, | ||||||||||||||||||||
| 76 | "cmdline.skip_format" => 1, | ||||||||||||||||||||
| 77 | }, | ||||||||||||||||||||
| 78 | ]; | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 0 | $self->cmdline->_format($r); | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 0 | [201, "OK"]; # skip the rest of the event handlers | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 86 | 1; | |||||||||||||||||||
| 86 | # ABSTRACT: Dump object mode | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||