| 1 | package Riji::CLI; | ||||||||||||
| 2 | 10 | ▶ | use feature ':5.10'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 10 | ▶ | use IPC::Cmd (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 10 | ▶ | use Getopt::Long (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 10 | ▶ | use Plack::Util (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 10 | ▶ | use String::CamelCase (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 10 | ▶ | sub run { | ||||||||||
|
Subroutine
run: called CC=6 SCAR=21.8
Pod
undocumented
| |||||||||||||
| 12 | 10 | my ($self, @args) = @_; | |||||||||||
| 13 | |||||||||||||
| 14 | 10 | local @ARGV = @args; | |||||||||||
| 15 | 10 | my @commands; | |||||||||||
| 16 | 10 | my $p = Getopt::Long::Parser->new( | |||||||||||
| 17 | config => [ "no_ignore_case", "pass_through" ], | ||||||||||||
| 18 | ); | ||||||||||||
| 19 | $p->getoptions( | ||||||||||||
| 20 | 0 | ▶ | "h|help" => sub { unshift @commands, 'help' }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 21 | 10 | 'version!' => \my $version, | |||||||||||
| 22 | ); | ||||||||||||
| 23 | 10 | ▶ | if ($version) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 24 | 0 | require Riji; | |||||||||||
| 25 | 0 | say "Riji: $Riji::VERSION"; exit 0; | |||||||||||
| 26 | } | ||||||||||||
| 27 | 10 | push @commands, @ARGV; | |||||||||||
| 28 | |||||||||||||
| 29 | 10 | ▶ | my $cmd = shift @commands || 'help'; | ||||||||||
|
Condition50%1/2
shift @commands || 'help'
MC/DC0%0/1
shift @commands || 'help'
shift @commands
Truth table50%1/2
A
A= shift @commands
| |||||||||||||
| 30 | 10 | ▶ | if (my $cmd = IPC::Cmd::can_run("riji-$cmd")) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 31 | 0 | exec $cmd, @commands; | |||||||||||
| 32 | } | ||||||||||||
| 33 | |||||||||||||
| 34 | 10 | $cmd =~ s/-/_/g; | |||||||||||
| 35 | 10 | my $class = String::CamelCase::camelize $cmd; | |||||||||||
| 36 | |||||||||||||
| 37 | 10 | local $@; | |||||||||||
| 38 | 10 | $class = eval { Plack::Util::load_class($class, 'Riji::CLI') }; | |||||||||||
| 39 | 10 | ▶ | if (my $err = $@) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 40 | 0 | ▶ | if ($err =~ m!Can't locate Riji/CLI!) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | 0 | warn "sub command `$cmd` not found\n"; exit 1; | |||||||||||
| 42 | } | ||||||||||||
| 43 | 0 | die $@; | |||||||||||
| 44 | } | ||||||||||||
| 45 | 10 | $class->run(@commands); | |||||||||||
| 46 | } | ||||||||||||
| 47 | |||||||||||||
| 48 | 10 | 1; | |||||||||||