| 1 | # Copyright (c) 2012-2017 Martin Becker, Blaubeuren. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # This package is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | package Math::Logic::Ternary::Calculator::Command; | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Math::Logic::Ternary::Calculator::Version; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use Math::Logic::Ternary::Calculator::Operator; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use constant OP => Math::Logic::Ternary::Calculator::Operator::; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use constant TC_MIN_ARGS => 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | use constant TC_VAR_ARGS => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use constant TC_CODE => 2; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | ▶ | use constant TC_DESCRIPTION => 3; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | our $VERSION = '0.004'; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | my %tool_commands = (); # name => [min_args, var_args, code, descr] | |||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | my @initial_commands = (); # index => [rank, code] | |||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | my $license = _read_own_license(); | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | _define_builtins(); | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | # ----- private subroutines ----- | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | ▶ | sub _version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_version: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | print Math::Logic::Ternary::Calculator::Version->long_name, "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | ▶ | sub _greeting { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_greeting: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | _version(); | |||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | ||||||||||||||||||||||||||||||||||||||||||
| 39 | qq{type "?" to get help, "/license" to display }, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | qq{license and copyright notice\n}; | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub _quit { 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quit: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub _license { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_license: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | print $license; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub _help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_help: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my ($session, $topic) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if (!defined $topic) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 55 | qq{Type "? <command>" or "? <operator>" }, | ||||||||||||||||||||||||||||||||||||||||||
| 56 | qq{to get help about a command or operator.\n}, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | qq{Available commands:\n}, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | join(q[ ], sort keys %tool_commands), "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if (exists $tool_commands{$topic}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $descr = $tool_commands{$topic}->[TC_DESCRIPTION]; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if (!defined $descr) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $descr = "$topic (description not available)\n"; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | print $descr; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ('/' eq substr $topic, 0, 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | print "$topic: unknown command\n"; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $mode = $session->state->mode; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $op = OP->find($topic, $mode); # TODO: abstraction | |||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if (!ref $op) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | print "$topic: $op\n"; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | print $op->description($mode); | |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | ▶ | sub _read_own_license { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_own_license: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | local $/ = q[]; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 4 | my $text = q[]; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | my $copy = 0; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 4 | ▶ | while (defined(my $par = <DATA>)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 92 | ▶ | if ($copy) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 12 | $par =~ s/^=head1 (?=DISCLAIMER)//; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 12 | $par =~ s/\blibrary\b/application/g; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 12 | ▶ | last if $par =~ /^=/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 8 | $text .= $par; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | elsif ($par =~ s/^=head1 (?=COPYRIGHT)//) { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | $copy = 1; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 4 | $text = $par; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | close DATA; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | ▶ | die "assertion failed: missing copyright notice" if !$copy; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | ▶ | sub _define_builtins { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_define_builtins: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 4 | my $class = caller; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 4 | $class->def_initial_command(0, \&_greeting); | |||||||||||||||||||||||||||||||||||||||||
| 107 | 4 | $class->def_tool_command('/version', 0, 0, \&_version , <<'EOT'); | |||||||||||||||||||||||||||||||||||||||||
| 108 | /version | ||||||||||||||||||||||||||||||||||||||||||
| 109 | display software version | ||||||||||||||||||||||||||||||||||||||||||
| 110 | EOT | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | $class->def_tool_command('/quit', 0, 0, \&_quit , <<'EOT'); | |||||||||||||||||||||||||||||||||||||||||
| 112 | /quit | ||||||||||||||||||||||||||||||||||||||||||
| 113 | quit calculator session | ||||||||||||||||||||||||||||||||||||||||||
| 114 | EOT | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 4 | $class->def_tool_command('/license', 0, 0, \&_license , <<'EOT'); | |||||||||||||||||||||||||||||||||||||||||
| 116 | /license | ||||||||||||||||||||||||||||||||||||||||||
| 117 | display license and copyright notice | ||||||||||||||||||||||||||||||||||||||||||
| 118 | EOT | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 4 | $class->def_tool_command('?', 0, 1, \&_help , <<'EOT'); | |||||||||||||||||||||||||||||||||||||||||
| 120 | ? [command|operator] | ||||||||||||||||||||||||||||||||||||||||||
| 121 | show general help text or describe a command or operator | ||||||||||||||||||||||||||||||||||||||||||
| 122 | EOT | ||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | # ----- class methods ----- | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 8 | ▶ | sub def_initial_command { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
def_initial_command: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 8 | my ($class, $rank, $code, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 8 | my $pos = @initial_commands; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 8 | ▶ | while ($pos && $initial_commands[$pos-1]->[0] > $rank) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$pos and $initial_commands[$pos - 1][0] > $rank
MC/DC0%0/2
$pos and $initial_commands[$pos - 1][0] > $rank
$pos
$initial_commands[$pos - 1][0] > $rank
Truth table66%2/3
A and B
A= $posB= $initial_commands[$pos - 1][0] > $rank
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | --$pos; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 8 | my $cmd = $class->custom_command($code, @args); | |||||||||||||||||||||||||||||||||||||||||
| 134 | 8 | splice @initial_commands, $pos, 0, [$rank, $cmd]; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 8 | return; | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | ▶ | sub get_initial_commands { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_initial_commands: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 2 | return map { $_->[1] } @initial_commands; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 37 | ▶ | sub def_tool_command { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
def_tool_command: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 37 | my ($class, $name, $min_args, $var_args, $code, $descr) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 37 | $tool_commands{$name} = [$min_args, $var_args, $code, $descr]; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 37 | return; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | sub greeting_command { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
greeting_command: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my $cmd = \&_greeting; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | return bless $cmd, $class; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub unknown_command { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unknown_command: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my ($class, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | return bless sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | print "unknown command: $name\n"; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | }, $class; | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | sub unknown_operator { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unknown_operator: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my ($class, $name, $comment) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | return bless sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | print "unknown operator: $name: $comment\n"; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | }, $class; | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub not_implemented { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
not_implemented: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my ($class, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | return bless sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | print "internal error: method not implemented: $name\n"; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | }, $class; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | sub wrong_usage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wrong_usage: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | my ($class, $reason) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | return bless sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | print "wrong usage: $reason\n"; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | }, $class; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | sub bad_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bad_value: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my ($class, $reason) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | return bless sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | print "bad value: $reason\n"; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | }, $class; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | sub _WRONG_ARGC { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_WRONG_ARGC: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | my ($min_args, $var_args, $act_args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 197 | return | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | $act_args < $min_args || | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$act_args < $min_args || 0 <= $var_args && $min_args + $var_args < $act_args
0 <= $var_args and $min_args + $var_args < $act_args
MC/DC0%0/3
$act_args < $min_args || 0 <= $var_args && $min_args + $var_args < $act_args
$act_args < $min_args
0 <= $var_args
$min_args + $var_args < $act_args
Truth table0%0/4
A || B and C
A= $act_args < $min_argsB= 0 <= $var_argsC= $min_args + $var_args < $act_args
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 <= $var_args && $min_args + $var_args < $act_args; | ||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | sub check_argc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_argc: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | my ($class, $name, $min_args, $var_args, $act_args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my $max_args = $min_args + $var_args; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | if ($min_args <= $act_args && ($var_args < 0 || $act_args <= $max_args)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$min_args <= $act_args and $var_args < 0 || $act_args <= $max_args
$var_args < 0 or $act_args <= $max_args
MC/DC0%0/3
$min_args <= $act_args and $var_args < 0 || $act_args <= $max_args
$min_args <= $act_args
$var_args < 0
$act_args <= $max_args
Truth table0%0/4
A and B or C
A= $min_args <= $act_argsB= $var_args < 0C= $act_args <= $max_args
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | return q[]; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | my $n = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 1 < $var_args? "$min_args .. $max_args": | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 1 == $var_args? "$min_args or $max_args": | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 > $var_args? "at least $min_args": | ||||||||||||||||||||||||||||||||||||||||||
| 212 | $min_args? "exactly $min_args" : 'no'; | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | my $s = 1 == $max_args? '': 's'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | return qq{$name takes $n argument$s}; | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | sub tool_command { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tool_command: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | my ($class, $name, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if ($name =~ s{^\?([/?\w].*)}{?}s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | unshift @args, $1; # treat "?foo" as ("?", "foo") | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | return $class->unknown_command($name) if !exists $tool_commands{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | my ($min_args, $var_args, $code) = @{$tool_commands{$name}}; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if (my $error = $class->check_argc($name, $min_args, $var_args, 0+@args)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | return $class->wrong_usage($error); | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | return bless sub { $code->($_[0], @args) }, $class; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 10 | ▶ | sub custom_command { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
custom_command: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 10 | my ($class, $code, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 10 | ▶ | return bless sub { $code->($_[0], @args) }, $class; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | # ----- object methods ----- | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 8 | ▶ | sub execute { my $cmd = shift; $cmd->(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 240 | __DATA__ | ||||||||||||||||||||||||||||||||||||||||||