| 1 | package Term::ShellKit::Commands; | ||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||
| 3 | 1 | require Term::ShellKit; | |||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||
| 5 | ###################################################################### | ||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||
| 7 | 0 | ▶ | sub eval ($) { | ||||||||||||||||||||||||
|
Subroutine
eval: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||
| 8 | 0 | my $input = shift; | |||||||||||||||||||||||||
| 9 | 0 | my @results = eval "package $Term::ShellKit::CurrentPackage; no strict qw( refs vars subs ); $input"; | |||||||||||||||||||||||||
| 10 | 0 | ▶ | die $@ if $@; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 11 | ! scalar( @results ) ? '' : | ||||||||||||||||||||||||||
| 12 | scalar( @results == 1 ) ? ( | ||||||||||||||||||||||||||
| 13 | ( ! defined $results[0] ) ? 'undef' : "$results[0]" | ||||||||||||||||||||||||||
| 14 | ) : | ||||||||||||||||||||||||||
| 15 | join(', ', map { | ||||||||||||||||||||||||||
| 16 | 0 | ▶ | ( ! defined ) ? 'undef' : ( ref $_ ) ? "$_" : "'$_'" | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 17 | } @results ); | ||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub package ($) { | ||||||||||||||||||||||||
|
Subroutine
package: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 21 | 0 | my $input = shift; | |||||||||||||||||||||||||
| 22 | 0 | $input =~ s/\;\s*$//; | |||||||||||||||||||||||||
| 23 | 0 | $Term::ShellKit::CurrentPackage = $input; | |||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub exit { | ||||||||||||||||||||||||
|
Subroutine
exit: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 27 | 0 | exit; | |||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub kit { | ||||||||||||||||||||||||
|
Subroutine
kit: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||
| 31 | 0 | ▶ | die "No kit name provided" unless ( scalar @_ ); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 32 | 0 | map { Term::ShellKit::load_kit( $_ ) } @_; | |||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||
| 35 | ###################################################################### | ||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub execute ($) { | ||||||||||||||||||||||||
|
Subroutine
execute: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 38 | 0 | my $command = shift; | |||||||||||||||||||||||||
| 39 | 0 | qx{$command}; | |||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||
| 42 | ###################################################################### | ||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||
| 44 | 1 | ▶ | sub echo (;$) { | ||||||||||||||||||||||||
|
Subroutine
echo: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||
| 45 | 1 | shift; | |||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||
| 48 | ###################################################################### | ||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||
| 50 | 1 | ▶ | use vars qw( $PODViewer ); | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 51 | 1 | ▶ | $PODViewer ||= "Pod::Text" || "Pod::Text::TermCap"; | ||||||||||||||||||||||||
|
Condition50%1/2
$PODViewer ||= "Pod::Text"
MC/DC0%0/1
$PODViewer ||= "Pod::Text"
$PODViewer
Truth table50%1/2
A
A= $PODViewer
| |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub help (;$) { | ||||||||||||||||||||||||
|
Subroutine
help: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||
| 54 | 0 | ▶ | my $topic = shift || 'Term::ShellKit::Commands'; | ||||||||||||||||||||||||
|
Condition0%0/2
shift() || 'Term::ShellKit::Commands'
MC/DC0%0/1
shift() || 'Term::ShellKit::Commands'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||
| 56 | 0 | $topic =~ s/kit /Term::ShellKit::/; | |||||||||||||||||||||||||
| 57 | 0 | ▶ | if ( $topic =~ /^[\w\:]+$/ ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 58 | 0 | (my $lib = $topic . '.pm' ) =~ s|::|/|go; | |||||||||||||||||||||||||
| 59 | 0 | ▶ | if ( ! $::INC{$lib} ) { eval { local $SIG{__DIE__}; require $lib } } | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 60 | 0 | ▶ | $topic = $::INC{$lib} if ( $::INC{$lib} ); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||
| 63 | 0 | Term::ShellKit::require_package( $PODViewer ); | |||||||||||||||||||||||||
| 64 | 0 | $PODViewer->new()->parse_from_file( $topic ); | |||||||||||||||||||||||||
| 65 | 0 | return; | |||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||
| 68 | ###################################################################### | ||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||
| 70 | 1 | ▶ | use vars qw( %CommandAliases ); | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 71 | 1 | %CommandAliases = ( | |||||||||||||||||||||||||
| 72 | '"' => 'echo', | ||||||||||||||||||||||||||
| 73 | '$' => 'eval', | ||||||||||||||||||||||||||
| 74 | '!' => 'execute', | ||||||||||||||||||||||||||
| 75 | 'q' => 'exit', | ||||||||||||||||||||||||||
| 76 | 'quit' => 'exit', | ||||||||||||||||||||||||||
| 77 | '?' => 'help', | ||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub alias { | ||||||||||||||||||||||||
|
Subroutine
alias: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ( scalar @_ ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 82 | 0 | my $cmd = shift; | |||||||||||||||||||||||||
| 83 | 0 | ▶ | if ( scalar @_ ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 84 | 0 | $CommandAliases{ $cmd } = join ' ', @_; | |||||||||||||||||||||||||
| 85 | 0 | return; | |||||||||||||||||||||||||
| 86 | } else { | ||||||||||||||||||||||||||
| 87 | 0 | $CommandAliases{ $cmd }; | |||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||
| 89 | } else { | ||||||||||||||||||||||||||
| 90 | 0 | map "$_: $CommandAliases{ $_ }", sort keys %CommandAliases; | |||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub _shell_rewrite { | ||||||||||||||||||||||||
|
Subroutine
_shell_rewrite: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||
| 95 | 0 | my $input = shift; | |||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||
| 97 | 0 | $input =~ s/\A\s+//; | |||||||||||||||||||||||||
| 98 | 0 | my ($command, $args) = split(' ', $input, 2); | |||||||||||||||||||||||||
| 99 | 0 | ▶ | my $alias = $CommandAliases{ $command } | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 100 | or return; | ||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||
| 102 | 0 | ▶ | return $alias . ( length($args) ? " $args" : '' ); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||
| 105 | ###################################################################### | ||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||
| 107 | 1 | 1; | |||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||
| 109 | __END__ | ||||||||||||||||||||||||||