| 1 | 18 | ▶ | 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 | 18 | ▶ | use Lingy::RT; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 18 | ▶ | use Lingy::Common; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 18 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 18 | ▶ | use constant default => '--repl'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 18 | ▶ | use constant options => +{ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 'clj|C' => 'bool', | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 'dev|D' => 'bool', | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 'eval|e' => 'str', | ||||||||||||||||||||||||||||||||||||||||||
| 14 | nrepl => 'bool', | ||||||||||||||||||||||||||||||||||||||||||
| 15 | ppp => 'bool', | ||||||||||||||||||||||||||||||||||||||||||
| 16 | repl => 'bool', | ||||||||||||||||||||||||||||||||||||||||||
| 17 | run => 'arg', | ||||||||||||||||||||||||||||||||||||||||||
| 18 | version => 'bool', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | xxx => 'bool', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 18 | }; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 16 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 16 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | bless { | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 16 | map( ($_, undef), keys %{$class->options} ), | |||||||||||||||||||||||||||||||||||||||||
| 28 | @_, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 16 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=8 SCAR=21.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 16 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 16 | $self->getopt(@args); | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | my ($repl, $run, $eval, $version, $clj, $dev, $nrepl, $args) = | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 13 | @{$self}{qw<repl run eval version clj dev nrepl args>}; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 13 | local @ARGV = @$args; | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 13 | ▶ | return $self->do_nrepl if $nrepl; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 13 | RT->init; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 13 | ▶ | RT->rep(qq<(clojure-repl-on)>) if $clj; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 13 | ▶ | RT->rep(qq<(use 'lingy.devel)>) if $dev; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 13 | ▶ | $version ? $self->do_version : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | $eval ? $self->do_eval : | ||||||||||||||||||||||||||||||||||||||||||
| 49 | $repl ? $self->do_repl : | ||||||||||||||||||||||||||||||||||||||||||
| 50 | $run ? $self->do_run : | ||||||||||||||||||||||||||||||||||||||||||
| 51 | $self->do_repl; | ||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | sub do_version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_version: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | RT->rep( | |||||||||||||||||||||||||||||||||||||||||
| 56 | '(println (str "Lingy [" *HOST* "] version " (lingy-version)))', | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 4 | ▶ | sub do_eval { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_eval: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 62 | my ($repl, $eval, $ppp, $xxx) = | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | @{$self}{qw<repl eval ppp xxx>}; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 4 | ▶ | if ($repl) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | RT->rep(qq<(do $eval\n)>); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | RT->repl; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 4 | ▶ | if ($ppp) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | RT->rep(qq<(use 'lingy.devel) (PPP (quote $eval\n))>); | |||||||||||||||||||||||||||||||||||||||||
| 71 | } elsif ($xxx) { | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | RT->rep(qq<(use 'lingy.devel) (XXX (quote $eval\n))>); | |||||||||||||||||||||||||||||||||||||||||
| 73 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | unshift @ARGV, '-'; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | map print("$_\n"), | |||||||||||||||||||||||||||||||||||||||||
| 76 | grep $_ ne 'nil', | ||||||||||||||||||||||||||||||||||||||||||
| 77 | RT->rep($eval); | ||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub do_nrepl { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_nrepl: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | require Lingy::nREPL; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | Lingy::nREPL->new->start->run; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub do_repl { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_repl: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | RT->repl; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 8 | ▶ | sub do_run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_run: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 8 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 8 | my $run = $self->{run}; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 8 | ▶ | if ($run ne '/dev/stdin') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 6 | ▶ | -f $run or err "No such file '$run'"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | RT->rep(qq<(load-file "$run")>); | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 7 | ▶ | sub from_stdin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_stdin: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 7 | ▶ | not -t STDIN or exists $ENV{LINGY_TEST_STDIN}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 16 | ▶ | sub getopt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getopt: called CC=14 SCAR=27.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 16 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 16 | my $default = $self->default; | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 16 | ▶ | if ($default and not(@args or $self->from_stdin)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$default and not @args || $self->from_stdin
@args || $self->from_stdin
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
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | @args = ($default); | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 16 | local @ARGV = @args; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 16 | my $spec = {}; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 16 | my $opts = $self->options; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 16 | for my $key (keys %$opts) { | |||||||||||||||||||||||||||||||||||||||||
| 119 | 144 | (my $name = $key) =~ s/\|.*//; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 144 | my $type = $opts->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 144 | ▶ | if ($type eq 'bool') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 112 | $spec->{$key} = \$self->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | elsif ($type eq 'str') { | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 16 | $spec->{"$key=s"} = \$self->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | elsif ($type eq 'arg') { | ||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | err "Option type '$type' not supported"; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | ▶ | $spec->{help} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | print $ENV{LINGY_USAGE}; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 16 | }; | |||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 16 | Getopt::Long::Configure(qw( | |||||||||||||||||||||||||||||||||||||||||
| 140 | gnu_getopt | ||||||||||||||||||||||||||||||||||||||||||
| 141 | no_auto_abbrev | ||||||||||||||||||||||||||||||||||||||||||
| 142 | no_ignore_case | ||||||||||||||||||||||||||||||||||||||||||
| 143 | )); | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 16 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 145 | 16 | ▶ | GetOptions (%$spec) or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | err "Error in command line arguments"; | ||||||||||||||||||||||||||||||||||||||||||
| 147 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 15 | ▶ | die "$@$ENV{LINGY_USAGE}" if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 13 | ▶ | if (@ARGV) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 7 | ▶ | if ($self->{repl}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | unshift @ARGV, 'NO_SOURCE_PATH'; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 7 | $self->{run} = $ARGV[0]; | |||||||||||||||||||||||||||||||||||||||||
| 155 | $self->{run} = '/dev/stdin' | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 7 | ▶ | if $self->{run} eq '-'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 6 | ▶ | if ($self->from_stdin) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 6 | $self->{run} = '/dev/stdin'; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 6 | unshift @ARGV, '<stdin>'; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | unshift @ARGV, 'NO_SOURCE_PATH'; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 13 | $self->{args} = [@ARGV]; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 18 | 1; | |||||||||||||||||||||||||||||||||||||||||