ShellKit/Commands.pm

filter: Statementstmt 22.4% 11 / 49 Branchbran 0.0% 0 / 28 Conditioncond 25.0% 1 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 27.2% 3 / 11 Podpod 87.5% 7 / 8 totaltotal 21.5% 22 / 102 CC 16 SCAR 32.0
CC
16
Cov
15%
eval
56.0
help
30.0
alias
12.0
CRAP 24.4
« ShellKit.pm ↑ Summary ShellKit/DBI.pm »
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
BranchTrueFalseTotal
if $@ 0 0 0
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
BranchTrueFalseTotal
!scalar(@results) ? : 0 0 0
scalar(@results == 1) ? : 0 0 0
!defined($results[0]) ? : 0 0 0
!defined($_) ? : 0 0 0
ref $_ ? : 0 0 0
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
BranchTrueFalseTotal
unless scalar @_ 0 0 0
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"
l!l
01
MC/DC0%0/1
$PODViewer ||= "Pod::Text"
$PODViewer
Truth table50%1/2
A
A= $PODViewer
Aresult
11
00
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'
l!l
00
MC/DC0%0/1
shift() || 'Term::ShellKit::Commands'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
55
56 0 $topic =~ s/kit /Term::ShellKit::/;
57 0 ▶ if ( $topic =~ /^[\w\:]+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic =~ /^[\w\:]+$/) 0 0 0
58 0 (my $lib = $topic . '.pm' ) =~ s|::|/|go;
59 0 ▶ if ( ! $::INC{$lib} ) { eval { local $SIG{__DIE__}; require $lib } }
Branch: 1 branch
BranchTrueFalseTotal
unless ($INC{$lib}) 0 0 0
60 0 ▶ $topic = $::INC{$lib} if ( $::INC{$lib} );
Branch: 1 branch
BranchTrueFalseTotal
if $INC{$lib} 0 0 0
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
BranchTrueFalseTotal
if (scalar @_) { } 0 0 0
82 0 my $cmd = shift;
83 0 ▶ if ( scalar @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) { } 0 0 0
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
BranchTrueFalseTotal
my $alias = $CommandAliases{$command} or return 0 0 0
100 or return;
101
102 0 ▶ return $alias . ( length($args) ? " $args" : '' );
Branch: 1 branch
BranchTrueFalseTotal
length $args ? : 0 0 0
103 }
104  
105 ######################################################################
106  
107 1 1;
108  
109 __END__
« ShellKit.pm ↑ Summary ShellKit/DBI.pm »