| 1 | package App::optex::help; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | help - help module for optex | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | optex -MB<help> [ I<options> ] | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | optex I<command> -MB<help> [ I<options> ] | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | =head1 OPTIONS | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | =over 7 | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | =item -x | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | Show options without help. | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | =item -l | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | Show module path. | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | =item -m | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | Show module content. | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | =item -h, --man | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | Show document. | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | =back | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | =cut | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 38 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 39 | 3 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 40 | 3 | $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 3 | my $rcloader = $main::rcloader; | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 3 | my $opt_with_help = 1; | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 2 | ▶ | sub usage { | ||||||||||||||||||
|
Subroutine
usage: called CC=8 SCAR=21.4
Pod
undocumented
| |||||||||||||||||||||
| 47 | 2 | my $quote = qr/[\\(){}\|\*?]/; | |||||||||||||||||||
| 48 | 2 | print "OPTIONS\n"; | |||||||||||||||||||
| 49 | 2 | for my $bucket ($rcloader->buckets) { | |||||||||||||||||||
| 50 | 2 | ▶ | my @options = $bucket->options or next; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 2 | my $indent = " " x 4; | |||||||||||||||||||
| 52 | 2 | my $title = do { | |||||||||||||||||||
| 53 | 2 | my $shown; | |||||||||||||||||||
| 54 | 2 | ▶ | sub { $shown++ or print "${indent}$_[0] options:\n" }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||
| 55 | }; | ||||||||||||||||||||
| 56 | 10 | ▶ | my $option = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 57 | 10 | printf "%s%-20s %s\n", $indent x 2, @_; | |||||||||||||||||||
| 58 | 2 | }; | |||||||||||||||||||
| 59 | 2 | for my $name (@options) { | |||||||||||||||||||
| 60 | 10 | ▶ | my $help = $opt_with_help ? $bucket->help($name) // "" : ""; | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$bucket->help($name) // ""
MC/DC0%0/1
$bucket->help($name) // ""
$bucket->help($name)
Truth table50%1/2
A
A= $bucket->help($name)
| |||||||||||||||||||||
| 61 | 10 | ▶ | next if $help eq 'ignore'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 10 | my @list = $bucket->getopt($name, ALL => 1); | |||||||||||||||||||
| 63 | 10 | $title->($bucket->title); | |||||||||||||||||||
| 64 | 10 | ▶ | $option->($name, $help || join(' ', shellquote(@list))); | ||||||||||||||||||
|
Condition33%1/3
$help || join(' ', shellquote(@list))
MC/DC0%0/2
$help || join(' ', shellquote(@list))
$help
join(' ', shellquote(@list))
Truth table33%1/3
A || B
A= $helpB= join(' ', shellquote(@list))
| |||||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | 2 | print "\n"; | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | ## | ||||||||||||||||||||
| 71 | ## easy implementation. don't be serious. | ||||||||||||||||||||
| 72 | ## | ||||||||||||||||||||
| 73 | 0 | ▶ | sub shellquote { | ||||||||||||||||||
|
Subroutine
shellquote: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 74 | 0 | my $quote = qr/[\s\\(){}\|\*?]/; | |||||||||||||||||||
| 75 | 0 | ▶ | map { /^(-+\w+=)(.*$quote.*)$/ | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 76 | ? "$1\'$2\'" | ||||||||||||||||||||
| 77 | : /^(.*$quote.*)$/ | ||||||||||||||||||||
| 78 | ? "\'$1\'" | ||||||||||||||||||||
| 79 | : $_ } | ||||||||||||||||||||
| 80 | @_; | ||||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 0 | ▶ | sub perldoc { | ||||||||||||||||||
|
Subroutine
perldoc: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||
| 84 | 0 | my %opt = @_; | |||||||||||||||||||
| 85 | 0 | ▶ | my @modules = do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 86 | 0 | grep { $_ ne 'default' } | |||||||||||||||||||
| 87 | 0 | grep { $_ !~ m:^/: } | |||||||||||||||||||
| 88 | 0 | grep { defined } | |||||||||||||||||||
| 89 | 0 | map { $_->module } | |||||||||||||||||||
| 90 | $rcloader->buckets; | ||||||||||||||||||||
| 91 | } or die "No modules.\n"; | ||||||||||||||||||||
| 92 | 0 | my $mod; | |||||||||||||||||||
| 93 | 0 | ▶ | while (@modules > 0) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | 0 | ▶ | last if ($mod = pop @modules) ne __PACKAGE__; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | my @command = ("perldoc", | ||||||||||||||||||||
| 97 | $opt{l} ? '-l' : (), | ||||||||||||||||||||
| 98 | 0 | ▶ | $opt{m} ? '-m' : (), | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 99 | $mod); | ||||||||||||||||||||
| 100 | 0 | $ENV{PERL5LIB} = join ':', @INC; | |||||||||||||||||||
| 101 | 0 | ▶ | warn "exec @command\n" if $main::debug; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | 0 | ▶ | exec @command or die $!; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 2 | ▶ | sub initialize { | ||||||||||||||||||
|
Subroutine
initialize: called CC=6 SCAR=18.4
Pod
undocumented
| |||||||||||||||||||||
| 106 | 2 | my($rc, $argv) = @_; | |||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 3 | ▶ | use Getopt::Long 'GetOptionsFromArray'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 109 | 2 | Getopt::Long::Configure(qw"bundling require_order"); | |||||||||||||||||||
| 110 | 2 | my %opt; | |||||||||||||||||||
| 111 | my @optargs = ( | ||||||||||||||||||||
| 112 | "x" => \$opt{x}, | ||||||||||||||||||||
| 113 | "l" => \$opt{l}, | ||||||||||||||||||||
| 114 | "m" => \$opt{m}, | ||||||||||||||||||||
| 115 | "M" => \$opt{M}, | ||||||||||||||||||||
| 116 | "h|man" => \$opt{man}, | ||||||||||||||||||||
| 117 | "u|usage" => \$opt{usage}, | ||||||||||||||||||||
| 118 | 2 | ); | |||||||||||||||||||
| 119 | # suppress unknown option message. | ||||||||||||||||||||
| 120 | 2 | ▶ | for (sub { }, undef) { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 121 | 4 | ▶ | $SIG{__WARN__} = $_ or last; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 122 | 2 | GetOptionsFromArray $argv, @optargs; | |||||||||||||||||||
| 123 | } | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 2 | ▶ | $opt_with_help = 0 if $opt{x}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | 2 | ▶ | if (grep $opt{$_}, qw( l m man )) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 128 | 0 | perldoc %opt; | |||||||||||||||||||
| 129 | } | ||||||||||||||||||||
| 130 | elsif ($opt{M}) { | ||||||||||||||||||||
| 131 | 0 | main::show_modules(); | |||||||||||||||||||
| 132 | } else { | ||||||||||||||||||||
| 133 | 2 | usage(); | |||||||||||||||||||
| 134 | } | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | 2 | exit 0; | |||||||||||||||||||
| 137 | } | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | 3 | 1; | |||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | __DATA__ | ||||||||||||||||||||