lib/Lingy/Main.pm

filter: Statementstmt 96.4% 81 / 84 Branchbran 81.8% 36 / 44 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 16 / 16 Podpod 0.0% 0 / 8 totaltotal 84.4% 136 / 161 CC 26 SCAR 19.8
CC
26
Cov
90%
getopt
14.8
run
7.1
do_eval
4.0
CRAP 7.2
« lib/Lingy/Env.pm ↑ Summary lib/Lingy/HashMap.pm »
1 22 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Lingy::Main;
3  
4 22 ▶use Lingy::RT;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 22 ▶use Lingy::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 22 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 22 ▶use constant default => '--repl';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 22 use constant options => +{
11 'clj|C' => 'bool',
12 'dev|D' => 'bool',
13 'eval|e' => 'str',
14 ppp => 'bool',
15 repl => 'bool',
16 run => 'arg',
17 version => 'bool',
18 xxx => 'bool',
19 22 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 sub new {
22 20 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
23  
24 bless {
25 20 map( ($_, ''), keys %{$class->options} ),
26 @_,
27 }, $class;
28 }
29  
30 sub run {
31 20 ▶ my ($self, @args) = @_;
Subroutine run: called CC=7 SCAR=19.7
Pod undocumented
32  
33 20 $self->getopt(@args);
34  
35 my ($repl, $run, $eval, $version, $clj, $dev, $args) =
36 17 @{$self}{qw<repl run eval version clj dev args>};
37 17 local @ARGV = @$args;
38  
39 17 RT->init;
40 17 ▶ RT->rep(qq<(clojure-repl-on)>) if $clj;
Branch: 1 branch
BranchTrueFalseTotal
if $clj 0 17 17
41 17 ▶ RT->rep(qq<(use 'lingy.devel)>) if $dev;
Branch: 1 branch
BranchTrueFalseTotal
if $dev 0 17 17
42  
43 17 ▶ $version ? $self->do_version() :
Branch: 4 branches
BranchTrueFalseTotal
$version ? : 1 16 17
$eval ? : 5 11 16
$repl ? : 2 9 11
$run ? : 9 0 9
44 $eval ? $self->do_eval() :
45 $repl ? $self->do_repl() :
46 $run ? $self->do_run() :
47 $self->do_repl();
48 }
49  
50 sub do_version {
51 1 ▶ RT->rep(
Subroutine do_version: called CC=1 SCAR=0.0
Pod undocumented
52 '(println (str "Lingy [" *HOST* "] version " (lingy-version)))',
53 );
54 }
55  
56 sub do_eval {
57 5 ▶ my ($self) = @_;
Subroutine do_eval: called CC=4 SCAR=13.9
Pod undocumented
58 my ($repl, $eval, $ppp, $xxx) =
59 5 @{$self}{qw<repl eval ppp xxx>};
60  
61 5 ▶ if ($repl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($repl) { } 1 4 5
62 1 RT->rep(qq<(do $eval\n)>);
63 1 RT->repl;
64 } else {
65 4 ▶ if ($ppp) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ppp) { } 1 3 4
elsif ($xxx) { } 1 2 3
66 1 RT->rep(qq<(use 'lingy.devel) (PPP (quote $eval\n))>);
67 } elsif ($xxx) {
68 1 RT->rep(qq<(use 'lingy.devel) (XXX (quote $eval\n))>);
69 } else {
70 2 unshift @ARGV, '-';
71 2 map print("$_\n"),
72 grep $_ ne 'nil',
73 RT->rep($eval);
74 }
75 }
76 }
77  
78 sub do_repl {
79 2 ▶ RT->repl;
Subroutine do_repl: called CC=1 SCAR=0.0
Pod undocumented
80 }
81  
82 sub do_run {
83 9 ▶ my ($self) = @_;
Subroutine do_run: called CC=3 SCAR=11.0
Pod undocumented
84 9 my $run = $self->{run};
85 9 ▶ if ($run ne '/dev/stdin') {
Branch: 1 branch
BranchTrueFalseTotal
if ($run ne "/dev/stdin") 6 3 9
86 6 ▶ -f $run or err "No such file '$run'";
Branch: 1 branch
BranchTrueFalseTotal
-f $run or err("No such file '${run}'") 0 6 6
87 }
88 9 RT->rep(qq<(load-file "$run")>);
89 }
90  
91 sub from_stdin {
92 11 ▶ not -t STDIN or exists $ENV{LINGY_TEST_STDIN};
Subroutine from_stdin: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
not -t STDIN or exists $ENV{"LINGY_TEST_STDIN"} 0 11 11
93 }
94  
95 sub getopt {
96 20 ▶ my ($self, @args) = @_;
Subroutine getopt: called CC=14 SCAR=26.9
Pod undocumented
97  
98 20 my $default = $self->default;
99  
100 20 ▶ if ($default and not(@args or $self->from_stdin)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($default and not @args || $self->from_stdin) 0 20 20
Condition50%3/6
$default and not @args || $self->from_stdin
!ll&&!rl&&r
0200
@args || $self->from_stdin
l!l&&r!l&&!r
1820
MC/DC0%0/3
$default and not @args || $self->from_stdin
$default @args $self->from_stdin
Truth table50%2/4
A and not(B || C)
A= $defaultB= @argsC= $self->from_stdin
ABCresult
0XX0
11X0
1010
1001
101 0 @args = ($default);
102 }
103  
104 20 local @ARGV = @args;
105  
106 20 my $spec = {};
107 20 my $opts = $self->options;
108 20 for my $key (keys %$opts) {
109 160 (my $name = $key) =~ s/\|.*//;
110 160 my $type = $opts->{$key};
111 160 ▶ if ($type eq 'bool') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'bool') { } 120 40 160
elsif ($type eq 'str') { } 20 20 40
elsif ($type eq 'arg') { } 20 0 20
112 120 $spec->{$key} = \$self->{$name};
113 }
114 elsif ($type eq 'str') {
115 20 $spec->{"$key=s"} = \$self->{$name};
116 }
117 elsif ($type eq 'arg') {
118 }
119 else {
120 0 err "Option type '$type' not supported";
121 }
122 }
123  
124 $spec->{help} = sub {
125 1 ▶ print $ENV{LINGY_USAGE};
Subroutine __ANON__: called CC=1 SCAR=0.0
126 1 exit 0;
127 20 };
128  
129 20 Getopt::Long::Configure(qw(
130 gnu_getopt
131 no_auto_abbrev
132 no_ignore_case
133 ));
134 20 eval {
135 20 ▶ GetOptions (%$spec) or
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(%$spec) or err("Error in command line arguments") 2 17 19
136 err "Error in command line arguments";
137 };
138 19 ▶ die "$@$ENV{LINGY_USAGE}" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 2 17 19
139  
140 17 ▶ if (@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV) { } 8 9 17
141 8 ▶ if ($self->{repl}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'repl'}) { } 1 7 8
142 1 unshift @ARGV, 'NO_SOURCE_PATH';
143 } else {
144 7 $self->{run} = $ARGV[0];
145 $self->{run} = '/dev/stdin'
146 7 ▶ if $self->{run} eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"run"} eq "-" 1 6 7
147 }
148  
149 } else {
150 9 ▶ if ($self->from_stdin) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->from_stdin) { } 9 0 9
151 9 $self->{run} = '/dev/stdin';
152 9 unshift @ARGV, '<stdin>';
153 } else {
154 0 unshift @ARGV, 'NO_SOURCE_PATH';
155 }
156 }
157  
158 17 $self->{args} = [@ARGV];
159 }
160  
161 22 1;
« lib/Lingy/Env.pm ↑ Summary lib/Lingy/HashMap.pm »