blib/lib/Lingy/RT.pm

filter: Statementstmt 81.5% 261 / 320 Branchbran 62.5% 75 / 120 Conditioncond 56.8% 29 / 51 MC/DCmcdc 22.5% 7 / 31 Subroutinesub 86.4% 83 / 96 Podpod 0.0% 0 / 78 totaltotal 65.3% 455 / 696 CC 87 SCAR 25.5
CC
87
Cov
74%
repl
132.0
ns
42.5
get
6.0
CRAP 12.9
« lib/Lingy/String.pm ↑ Summary lib/Lingy/Reader.pm »
1 56 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Lingy::RT;
3  
4 56 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 56 ▶use Lingy;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 56 ▶use Lingy::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 56 ▶use Lingy::Evaluator;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 56 ▶use Lingy::Namespace;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 56 ▶use Lingy::ReadLine;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 56 ▶use constant LANG => 'Lingy';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 56 ▶use constant HOST => 'perl';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 56 ▶use constant env_class => 'Lingy::Env';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 56 ▶use constant printer_class => 'Lingy::Printer';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 56 ▶use constant reader_class => 'Lingy::Reader';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 56 ▶use constant RL => Lingy::ReadLine->new;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 56 my @class_names = (
21 ATOM,
22 BOOLEAN,
23 CHARACTER,
24 CLASS,
25 CLOJURE,
26 COMPILER,
27 EXCEPTION,
28 FUNCTION,
29 HASHMAP,
30 HASHSET,
31 KEYWORD,
32 LIST,
33 LISTTYPE,
34 MACRO,
35 NIL,
36 NUMBER,
37 REGEX,
38 SEQUENTIAL,
39 STRBUILD,
40 STRING,
41 SYMBOL,
42 SYSTEM,
43 VAR,
44 VECTOR,
45 NUMBERS,
46 RT,
47 TERM,
48 THREAD,
49 UTIL,
50  
51 ILLEGALARGUMENTEXCEPTION,
52 );
53 55 ▶sub class_names { \@class_names }
Subroutine class_names: called CC=1 SCAR=0.0
Pod undocumented
54  
55 56 my $current_ns_name;
56 135 ▶sub current_ns_name { $current_ns_name = $_[1] // $current_ns_name }
Subroutine current_ns_name: called CC=2 SCAR=7.2
Pod undocumented
Condition66%2/3
$_[1] // $current_ns_name
l!l&&r!l&&!r
13410
MC/DC0%0/2
$_[1] // $current_ns_name
$_[1] $current_ns_name
Truth table66%2/3
A // B
A= $_[1]B= $current_ns_name
ABresult
1X1
011
000
57  
58 my %namespaces;
59 56 bless \%namespaces, 'lingy-internal';
60 353 ▶sub namespaces { \%namespaces }
Subroutine namespaces: called CC=1 SCAR=0.0
Pod undocumented
61 121086 ▶sub current_ns { $namespaces{$current_ns_name} }
Subroutine current_ns: called CC=1 SCAR=0.0
Pod undocumented
62  
63 56 my %classes;
64 0 ▶sub classes { \%classes }
Subroutine classes: not called CC=1 SCAR=6.9
Pod undocumented
65  
66 my %meta;
67 8283 ▶sub meta { \%meta }
Subroutine meta: called CC=1 SCAR=0.0
Pod undocumented
68  
69 56 my $env;
70 134 ▶sub env { $env }
Subroutine env: called CC=1 SCAR=0.0
Pod undocumented
71 0 ▶sub ENV { $Lingy::Evaluator::ENV }
Subroutine ENV: not called CC=1 SCAR=6.9
72  
73 56 my $reader;
74 1 ▶sub reader { $reader }
Subroutine reader: called CC=1 SCAR=0.0
Pod undocumented
75  
76 56 my $printer;
77 7 ▶sub printer { $printer }
Subroutine printer: called CC=1 SCAR=0.0
Pod undocumented
78  
79 56 my $core_ns;
80 93203 ▶sub core_ns { $core_ns }
Subroutine core_ns: called CC=1 SCAR=0.0
Pod undocumented
81  
82 56 my $user_ns;
83 0 ▶sub user_ns { $user_ns }
Subroutine user_ns: not called CC=1 SCAR=6.9
Pod undocumented
84  
85 56 our $OK = 0;
86  
87 54 ▶sub init {
Subroutine init: called CC=4 SCAR=13.9
Pod undocumented
88 54 my ($self) = @_;
89  
90 54 for my $package_name (@{RT->class_names}) {
91 1620 ▶ eval "require $package_name; 1" or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $package_name; 1" or die $@ 1620 0 1620
92 1620 my $class = CLASS->_new($package_name);
93 1620 my $class_name = $class->_name;
94 1620 $classes{$class_name} = $class;
95 1620 ▶ if ($class_name =~ /\.(\w+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class_name =~ /\.(\w+)$/) 1620 0 1620
96 1620 $classes{$1} = $class;
97 }
98 }
99  
100 54 $env = $self->require_new($self->env_class);
101 54 $reader = $self->require_new($self->reader_class);
102 54 $printer = $self->require_new($self->printer_class);
103  
104 54 $core_ns = $self->core_namespace();
105 54 $user_ns = NAMESPACE->new('user')
106 ->refer(symbol($self->core_ns->_name))
107 ->current;
108  
109 54 $OK = 1;
110  
111 54 return $self;
112 }
113  
114 54 ▶sub core_namespace {
Subroutine core_namespace: called CC=6 SCAR=17.9
Pod undocumented
115 54 my ($self) = (@_);
116  
117 54 my $ns = NAMESPACE->new('lingy.core', %classes)->current;
118  
119 54 $ns->{$_} = $classes{$_} for CORE::keys %classes;
120  
121 54 ▶ my $argv = @ARGV
Branch: 1 branch
BranchTrueFalseTotal
@ARGV ? : 13 41 54
122 ? LIST->new([
123 map STRING->new($_), @ARGV[1..$#ARGV]]
124 ) : NIL->new;
125  
126 # Define these functions first for bootstrapping:
127 54 $env->set(cons => \&cons);
128 54 $env->set(concat => \&concat);
129 54 ▶ $env->set(eval => sub { evaluate($_[0], $env) });
Subroutine __ANON__: called CC=1 SCAR=0.0
130  
131 # Clojure dynamic vars:
132 54 ▶ my $file = $ARGV[0] || "NO_SOURCE_PATH";
Condition100%2/2
$ARGV[0] || 'NO_SOURCE_PATH'
l!l
1341
MC/DC100%1/1
$ARGV[0] || 'NO_SOURCE_PATH'
$ARGV[0]
Truth table100%2/2
A
A= $ARGV[0]
Aresult
11
00
133 54 ▶ $file = Cwd::abs_path($file) unless $file eq "NO_SOURCE_PATH";
Branch: 1 branch
BranchTrueFalseTotal
unless $file eq "NO_SOURCE_PATH" 13 41 54
134 54 $env->set('*file*', STRING->new($file));
135 54 $env->set('*command-line-args*', $argv);
136  
137 # Lingy dynamic vars:
138 54 $env->set('*LANG*', STRING->new($self->LANG));
139 54 $env->set('*HOST*', STRING->new($self->HOST));
140  
141 # Work around a bug in version checking during cpanm install:
142 54 my $v = $Lingy::VERSION;
143 54 $v =~ /^(\d+)\.(\d+)\.(\d+)$/;
144  
145 54 $self->rep("
146 (def *lingy-version*
147 {
148 :major $1
149 :minor $2
150 :incremental $3
151 :qualifier nil
152 })
153  
154 (def *clojure-version*
155 {
156 :major 1
157 :minor 11
158 :incremental 1
159 :qualifier nil
160 })
161 ");
162  
163 54 my $core_ly = $INC{'Lingy/RT.pm'};
164 54 $core_ly =~ s/RT\.pm$/core.ly/;
165 54 $self->rep($self->slurp_file($core_ly));
166  
167 54 ▶ unless ($ENV{LINGY_BUILDING_CORE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"LINGY_BUILDING_CORE"}) 54 0 54
168 54 my $core_clj = $core_ly;
169 54 $core_clj =~ s/\.ly$/.clj/;
170 54 $self->rep($self->slurp_file($core_clj));
171 }
172  
173 54 return $ns;
174 }
175  
176 162 ▶sub require_new {
Subroutine require_new: called CC=2 SCAR=7.0
Pod undocumented
177 162 my $self = shift;
178 162 my $class = shift;
179 162 ▶ eval "require $class; 1" or
Branch: 1 branch
BranchTrueFalseTotal
eval "require $class; 1" or die "Can't require '${class}':\n$@" 162 0 162
180 die "Can't require '$class':\n$@";
181 162 $class->new(@_);
182 }
183  
184 133 ▶sub slurp_file {
Subroutine slurp_file: called CC=2 SCAR=7.0
Pod undocumented
185 133 my ($self, $file) = @_;
186 133 ▶ open my $slurp, '<', "$file" or
Branch: 1 branch
BranchTrueFalseTotal
open my $slurp, "<", "$file" or die "Couldn't read file '${file}'" 133 0 133
187 die "Couldn't read file '$file'";
188 133 local $/;
189 133 <$slurp>;
190 }
191  
192 41215 ▶sub is_lingy_class {
Subroutine is_lingy_class: called CC=2 SCAR=6.9
Pod undocumented
193 41215 my ($self, $class) = @_;
194 41215 ▶ $class->isa(CLASS) or $class =~ /^Lingy::\w/;
Branch: 1 branch
BranchTrueFalseTotal
$class->isa("Lingy::Class") or $class =~ /^Lingy::\w/ 2 41213 41215
195 }
196  
197 1 ▶sub eval {
Subroutine eval: called CC=1 SCAR=0.0
Pod undocumented
198 1 my ($self, $form) = @_;
199 1 evaluate(
200 $form,
201 $env,
202 );
203 }
204  
205 1308 ▶sub rep {
Subroutine rep: called CC=1 SCAR=0.0
Pod undocumented
206 1308 my ($self, $str) = @_;
207 1308 map $printer->pr_str(evaluate($_, $env)),
208 $reader->read_str($str);
209 }
210  
211 56 ▶use constant repl_intro_command =>
Subroutine BEGIN: called CC=1 SCAR=0.0
212 56 q<(println (str *LANG* " " (lingy-version) " [" *HOST* "]\n"))>;
213  
214 0 ▶sub repl {
Subroutine repl: not called CC=11 SCAR=48.8
Pod undocumented
215 0 my ($self) = @_;
216  
217 0 $self->RL->setup;
218  
219 $self->rep($self->repl_intro_command)
220 0 ▶ unless $ENV{LINGY_TEST};
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"LINGY_TEST"} 0 0 0
221 0 my ($clojure_repl) = $self->rep("(identity *clojure-repl*)");
222 0 ▶ if ($clojure_repl eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($clojure_repl eq "true") 0 0 0
223 0 require Lingy::ClojureREPL;
224 0 Lingy::ClojureREPL->start();
225 }
226  
227 0 ▶ while (defined (my $line = $self->RL->readline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = $self->RL->readline)) 0 0 0
228 0 ▶ next unless length $line;
Branch: 1 branch
BranchTrueFalseTotal
unless length $line 0 0 0
229  
230 0 my @forms = eval { $reader->read_str($line, 1) };
231 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
232 0 print "$@\n";
233 0 $self->RL->input;
234 0 next;
235 }
236  
237 0 for my $form (@forms) {
238 0 my $ret = eval {
239 0 $printer->pr_str(evaluate($form, $env));
240 };
241 0 my $err;
242 0 ▶ $err = $ret = $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
243 0 chomp $ret;
244 0 print "$ret\n";
245 }
246  
247 0 ▶ my $input = $self->RL->input // next;
Condition0%0/2
$self->RL->input // (next)
l!l
00
MC/DC0%0/1
$self->RL->input // (next)
$self->RL->input
Truth table0%0/2
A
A= $self->RL->input
Aresult
11
00
248 0 ($clojure_repl) = $self->rep("(identity *clojure-repl*)");
249  
250 0 ▶ if ($input =~ s/^;;;// or $clojure_repl eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($input =~ s/^;;;// or $clojure_repl eq "true") 0 0 0
Condition0%0/3
$input =~ s/^;;;// or $clojure_repl eq "true"
l!l&&r!l&&!r
000
MC/DC0%0/2
$input =~ s/^;;;// or $clojure_repl eq "true"
$input =~ s/^;;;// $clojure_repl eq "true"
Truth table0%0/3
A or B
A= $input =~ s/^;;;//B= $clojure_repl eq "true"
ABresult
1X1
011
000
251 0 require Lingy::ClojureREPL;
252 0 Lingy::ClojureREPL->rep($input);
253 }
254 }
255 0 print "\n";
256 }
257  
258  
259 #------------------------------------------------------------------------------
260  
261 0 ▶sub all_ns {
Subroutine all_ns: not called CC=1 SCAR=6.9
Pod undocumented
262 list([
263 0 map { $namespaces{$_} }
264 sort CORE::keys %namespaces
265 ]);
266 }
267  
268 7714 ▶sub apply {
Subroutine apply: called CC=3 SCAR=11.0
Pod undocumented
269 7714 my ($fn, $args) = @_;
270 7714 my $seq = pop(@$args);
271 7714 ▶ $seq = list([]) if ref($seq) eq NIL;
Branch: 1 branch
BranchTrueFalseTotal
if ref $seq eq "Lingy::Nil" 2 7712 7714
272 7714 push @$args, @$seq;
273 7714 ▶ ref($fn) eq 'CODE'
Branch: 1 branch
BranchTrueFalseTotal
ref $fn eq 'CODE' ? : 7548 166 7714
274 ? $fn->(@$args)
275 : evaluate($fn->(@$args));
276 }
277  
278 0 ▶sub applyTo {
Subroutine applyTo: not called CC=1 SCAR=6.9
Pod undocumented
279 0 my ($obj, $meth, $args) = @_;
280 0 $meth = "$meth";
281 0 my @args = map unbox_val(evaluate($_, ENV())), @$args;
282 0 box_val $obj->$meth(@args);
283 }
284  
285 16 ▶sub assoc {
Subroutine assoc: called CC=1 SCAR=0.0
Pod undocumented
286 16 my ($map, $key, $val) = @_;
287 16 $map->assoc($key, $val);
288 }
289  
290 9 ▶sub atom { ATOM->new($_[0]) }
Subroutine atom: called CC=1 SCAR=0.0
Pod undocumented
291  
292 5 ▶sub booleanCast {
Subroutine booleanCast: called CC=4 SCAR=13.9
Pod undocumented
293 5 my ($val) = @_;
294 5 my $type = ref($val);
295 5 ▶ $type eq NIL ? false :
Branch: 2 branches
BranchTrueFalseTotal
$type eq 'Lingy::Nil' ? : 1 4 5
$type eq 'Lingy::Boolean' && $$val == 0 ? : 2 2 4
Condition100%3/3
$type eq "Lingy::Boolean" and $$val == 0
!ll&&!rl&&r
112
MC/DC100%2/2
$type eq "Lingy::Boolean" and $$val == 0
$type eq "Lingy::Boolean" $$val == 0
Truth table100%3/3
A and B
A= $type eq "Lingy::Boolean"B= $$val == 0
ABresult
0X0
100
111
296 ($type eq BOOLEAN and $$val == 0) ? false :
297 true;
298 }
299  
300 2 ▶sub charCast {
Subroutine charCast: called CC=3 SCAR=12.0
Pod undocumented
301 2 my ($char) = @_;
302 2 my $type = ref($char);
303 2 ▶ err "Class '$type' cannot be cast to 'lingy.lang.Character'"
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "Lingy::Symbol" or $type eq "Lingy::Number" 0 2 2
Condition33%1/3
$type eq "Lingy::Symbol" or $type eq "Lingy::Number"
l!l&&r!l&&!r
020
MC/DC0%0/2
$type eq "Lingy::Symbol" or $type eq "Lingy::Number"
$type eq "Lingy::Symbol" $type eq "Lingy::Number"
Truth table33%1/3
A or B
A= $type eq "Lingy::Symbol"B= $type eq "Lingy::Number"
ABresult
1X1
011
000
304 unless $type eq SYMBOL or $type eq NUMBER;
305 2 return CHARACTER->read($char);
306 }
307  
308 7703 ▶sub concat { list([map @$_, @_]) }
Subroutine concat: called CC=1 SCAR=0.0
Pod undocumented
309  
310 29 ▶sub conj {
Subroutine conj: called CC=5 SCAR=17.1
Pod undocumented
311 29 my ($o, @args) = @_;
312 29 my $type = ref($o);
313 29 ▶ $type eq LIST ? list([reverse(@args), @$o]) :
Branch: 4 branches
BranchTrueFalseTotal
$type eq 'Lingy::List' ? : 5 24 29
$type eq 'Lingy::Vector' ? : 21 3 24
$type eq 'Lingy::HashMap' ? : 3 0 3
$type eq 'Lingy::Nil' ? : 0 0 0
314 $type eq VECTOR ? VECTOR->new([@$o, @args]) :
315 $type eq HASHMAP ? HASHMAP->new([%$o, map %$_, @args]) :
316 $type eq NIL ? nil :
317 err("conj first arg type '$type' not allowed");
318 }
319  
320 34603 ▶sub cons { list([$_[0], @{$_[1]}]) }
Subroutine cons: called CC=1 SCAR=0.0
Pod undocumented
321  
322 22 ▶sub contains {
Subroutine contains: called CC=4 SCAR=13.9
Pod undocumented
323 22 my ($map, $key) = @_;
324 22 ▶ return false unless ref($map) eq HASHMAP;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $map eq "Lingy::HashMap" 0 22 22
325 22 ▶ $key =
Branch: 2 branches
BranchTrueFalseTotal
$key->isa('Lingy::String') ? : 3 19 22
$key->isa('Lingy::Symbol') ? : 16 3 19
326 $key->isa(STRING) ? qq<"$key> :
327 $key->isa(SYMBOL) ? qq<$key > :
328 "$key";
329 22 BOOLEAN->new(exists $map->{"$key"});
330 }
331  
332 692 ▶sub count {
Subroutine count: called CC=2 SCAR=6.9
Pod undocumented
333 692 ▶ NUMBER->new(ref($_[0]) eq NIL ? 0 : scalar @{$_[0]});
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'Lingy::Nil' ? : 1 691 692
334 }
335  
336 1 ▶sub create_ns {
Subroutine create_ns: called CC=2 SCAR=7.1
Pod undocumented
337 1 my ($name) = @_;
338 1 ▶ err "Invalid ns name '$name'"
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /^\w+(\.\w+)*$/ 0 1 1
339 unless $name =~ /^\w+(\.\w+)*$/;
340 1 NAMESPACE->new($name)->refer(symbol($core_ns->_name));
341 }
342  
343 9 ▶sub deref { $_[0]->[0] }
Subroutine deref: called CC=1 SCAR=0.0
Pod undocumented
344  
345 5 ▶sub dissoc {
Subroutine dissoc: called CC=3 SCAR=11.0
Pod undocumented
346 5 my ($map, @keys) = @_;
347 @keys = map {
348 5 ▶ $_->isa(STRING) ? qq<"$_> : "$_";
Branch: 1 branch
BranchTrueFalseTotal
$_->isa('Lingy::String') ? : 6 2 8
349 } @keys;
350 5 $map = { %$map };
351 5 delete $map->{$_} for @keys;
352 5 HASHMAP->new([%$map]);
353 }
354  
355 0 ▶sub eval_perl {
Subroutine eval_perl: not called CC=2 SCAR=17.9
Pod undocumented
356 0 my ($perl) = @_;
357 0 my $ret = eval "$perl";
358 0 ▶ err("$@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
359 0 return $ret;
360 }
361  
362 8 ▶sub find_ns {
Subroutine find_ns: called CC=2 SCAR=7.1
Pod undocumented
363 8 assert_args(\@_, SYMBOL);
364 7 ▶ $namespaces{$_[0]} // nil;
Condition66%2/3
$namespaces{$_[0]} // nil()
l!l&&r!l&&!r
520
MC/DC0%0/2
$namespaces{$_[0]} // nil()
$namespaces{$_[0]} nil()
Truth table66%2/3
A // B
A= $namespaces{$_[0]}B= nil()
ABresult
1X1
011
000
365 }
366  
367 255 ▶sub first {
Subroutine first: called CC=3 SCAR=11.0
Pod undocumented
368 ref($_[0]) eq NIL
369 255 ▶ ? nil : @{$_[0]} ? $_[0]->[0] : nil;
Branch: 2 branches
BranchTrueFalseTotal
ref $_[0] eq 'Lingy::Nil' ? : 1 254 255
@{$_[0];} ? : 252 2 254
370 }
371  
372 42 ▶sub get {
Subroutine get: called CC=6 SCAR=17.9
Pod undocumented
373 42 my ($map, $key, $default) = @_;
374 42 ▶ return nil unless ref($map) eq HASHMAP or ref($map) eq HASHSET;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $map eq "Lingy::HashMap" or ref $map eq "Lingy::HashSet" 1 41 42
Condition100%3/3
ref $map eq "Lingy::HashMap" or ref $map eq "Lingy::HashSet"
l!l&&r!l&&!r
3651
MC/DC100%2/2
ref $map eq "Lingy::HashMap" or ref $map eq "Lingy::HashSet"
ref $map eq "Lingy::HashMap" ref $map eq "Lingy::HashSet"
Truth table100%3/3
A or B
A= ref $map eq "Lingy::HashMap"B= ref $map eq "Lingy::HashSet"
ABresult
1X1
011
000
375 41 ▶ $key = qq<"$key> if $key->isa(STRING);
Branch: 1 branch
BranchTrueFalseTotal
if $key->isa("Lingy::String") 8 33 41
376 41 ▶ $map->{"$key"} // $default // nil;
Condition83%5/6
($$map{"$key"} // $default) // nil()
l!l&&r!l&&!r
3290
$$map{"$key"} // $default
l!l&&r!l&&!r
2849
MC/DC0%0/3
($$map{"$key"} // $default) // nil()
$$map{"$key"} $default nil()
Truth table75%3/4
A // B // C
A= $$map{"$key"}B= $defaultC= nil()
ABCresult
1XX1
01X1
0011
0000
377 }
378  
379 0 ▶sub getenv {
Subroutine getenv: not called CC=2 SCAR=17.9
Pod undocumented
380 0 my $val = $ENV{$_[0]};
381 0 ▶ defined($val) ? string($val) : nil;
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 0 0 0
382 }
383  
384 9 ▶sub hash_map { HASHMAP->new([@_]) }
Subroutine hash_map: called CC=1 SCAR=0.0
Pod undocumented
385  
386 1 ▶sub hash_set { HASHSET->new([@_]) }
Subroutine hash_set: called CC=1 SCAR=0.0
Pod undocumented
387  
388 2 ▶sub in_ns {
Subroutine in_ns: called CC=3 SCAR=11.3
Pod undocumented
389 2 my ($name) = @_;
390 2 ▶ err "Invalid ns name '$name'"
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /^\w+(\.\w+)*$/ 0 2 2
391 unless $name =~ /^\w+(\.\w+)*$/;
392 2 ▶ my $ns = $namespaces{$name} // NAMESPACE->new($name);
Condition66%2/3
$namespaces{$name} // "Lingy::Namespace"->new($name)
l!l&&r!l&&!r
110
MC/DC0%0/2
$namespaces{$name} // "Lingy::Namespace"->new($name)
$namespaces{$name} "Lingy::Namespace"->new($name)
Truth table66%2/3
A // B
A= $namespaces{$name}B= "Lingy::Namespace"->new($name)
ABresult
1X1
011
000
393 2 $ns->current;
394 }
395  
396 9 ▶sub keys {
Subroutine keys: called CC=4 SCAR=15.2
Pod undocumented
397 list([
398 map {
399 13 ▶ s/^"// ? string($_) :
Branch: 3 branches
BranchTrueFalseTotal
s/^"// ? : 11 2 13
s/^:// ? : 2 0 2
s/ $// ? : 0 0 0
400 s/^:// ? KEYWORD->new($_) :
401 s/ $// ? symbol($_) :
402 symbol("$_");
403 9 } CORE::keys %{$_[0]}
404 ]);
405 }
406  
407 5 ▶sub keyword { KEYWORD->new($_[0]) }
Subroutine keyword: called CC=1 SCAR=0.0
Pod undocumented
408  
409 359 ▶sub list_ { list([@_]) }
Subroutine list_: called CC=1 SCAR=0.0
Pod undocumented
410  
411 18 ▶sub macroexpand {
Subroutine macroexpand: called CC=1 SCAR=0.0
Pod undocumented
412 18 Lingy::Evaluator::macroexpand($_[0], $Lingy::Evaluator::ENV);
413 }
414  
415 15 ▶sub map {
Subroutine map: called CC=1 SCAR=0.0
Pod undocumented
416 list([
417 15 map apply($_[0], [$_, []]), @{$_[1]}
418 ]);
419 }
420  
421 45 ▶sub meta_get {
Subroutine meta_get: called CC=2 SCAR=7.2
Pod undocumented
422 45 ▶ $meta{"$_[0]"} // nil;
Condition66%2/3
$meta{"$_[0]"} // nil()
l!l&&r!l&&!r
31140
MC/DC0%0/2
$meta{"$_[0]"} // nil()
$meta{"$_[0]"} nil()
Truth table66%2/3
A // B
A= $meta{"$_[0]"}B= nil()
ABresult
1X1
011
000
423 }
424  
425 460 ▶sub more {
Subroutine more: called CC=3 SCAR=11.0
Pod undocumented
426 460 my ($list) = @_;
427 460 ▶ return list([]) if $list->isa(NIL) or not @$list;
Branch: 1 branch
BranchTrueFalseTotal
if $list->isa("Lingy::Nil") or not @$list 3 457 460
Condition100%3/3
$list->isa("Lingy::Nil") or not @$list
l!l&&r!l&&!r
12457
MC/DC100%2/2
$list->isa("Lingy::Nil") or not @$list
$list->isa("Lingy::Nil") not @$list
Truth table100%3/3
A or not(B)
A= $list->isa("Lingy::Nil")B= not @$list
ABresult
1X1
011
000
428 457 list([@{$list}[1..(@$list-1)]]);
429 }
430  
431 2 ▶sub name {
Subroutine name: called CC=2 SCAR=6.9
Pod undocumented
432 2 ▶ string($_[0] =~ m{(.*?)/(.*)} ? $2 : "$_[0]");
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ m[(.*?)/(.*)] ? : 1 1 2
433 }
434  
435 2 ▶sub namespace {
Subroutine namespace: called CC=2 SCAR=6.9
Pod undocumented
436 2 ▶ $_[0] =~ m{(.*?)/(.*)} ? string($1) : nil;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ m[(.*?)/(.*)] ? : 1 1 2
437 }
438  
439 56 my $nextID = 1000;
440 685 ▶sub nextID {
Subroutine nextID: called CC=2 SCAR=6.9
Pod undocumented
441 685 ▶ return $nextID = $_[1] if @_ == 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 2 345 340 685
442 340 string(++$nextID);
443 }
444  
445 14 ▶sub ns {
Subroutine ns: called CC=10 SCAR=37.5
Pod undocumented
446 14 my ($name, $args) = @_;
447 14 ▶ err "Invalid ns name '$name'"
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /^\w+(?:\.\w+)*$/ 0 14 14
448 unless $name =~ /^\w+(?:\.\w+)*$/;
449  
450 14 my $ns;
451 14 ▶ $ns = $namespaces{$name} //
Condition66%2/3
$namespaces{$name} // "Lingy::Namespace"->new($name)->refer(symbol($core_ns->_name))
l!l&&r!l&&!r
1130
MC/DC0%0/2
$namespaces{$name} // "Lingy::Namespace"->new($name)->refer(symbol($core_ns->_name))
$namespaces{$name} "Lingy::Namespace"->new($name)->refer(symbol($core_ns->_name))
Truth table66%2/3
A // B
A= $namespaces{$name}B= "Lingy::Namespace"->new($name)->refer(symbol($core_ns->_name))
ABresult
1X1
011
000
452 NAMESPACE->new($name)->refer(symbol($core_ns->_name));
453 14 $ns->current;
454  
455 14 for my $arg (@$args) {
456 0 ▶ err "Invalid ns arg" unless
Branch: 1 branch
BranchTrueFalseTotal
unless $arg->isa("Lingy::List") and @$arg >= 2 and ref $arg->[0] eq "Lingy::Keyword" 0 0 0
Condition0%0/6
$arg->isa("Lingy::List") and @$arg >= 2 and ref $arg->[0] eq "Lingy::Keyword"
!ll&&!rl&&r
000
$arg->isa("Lingy::List") and @$arg >= 2
!ll&&!rl&&r
000
MC/DC0%0/3
$arg->isa("Lingy::List") and @$arg >= 2 and ref $arg->[0] eq "Lingy::Keyword"
$arg->isa("Lingy::List") @$arg >= 2 ref $arg->[0] eq "Lingy::Keyword"
Truth table0%0/4
A and B and C
A= $arg->isa("Lingy::List")B= @$arg >= 2C= ref $arg->[0] eq "Lingy::Keyword"
ABCresult
0XX0
10X0
1100
1111
457 $arg->isa(LIST) and
458 @$arg >= 2 and
459 ref($arg->[0]) eq KEYWORD;
460  
461 0 my ($keyword, @args) = @$arg;
462 0 ▶ if ($$keyword eq ':use') {
Branch: 2 branches
BranchTrueFalseTotal
if ($$keyword eq ':use') { } 0 0 0
elsif ($$keyword eq ':import') { } 0 0 0
463 0 for my $spec (@args) {
464 0 evaluate(
465 list([
466 symbol('use'),
467 list([symbol('quote'), $spec]),
468 ]),
469 $Lingy::Evaluator::ENV,
470 );
471 }
472 }
473 elsif ($$keyword eq ':import') {
474 0 my (undef, @args) = @$arg;
475 0 evaluate(
476 list([ symbol('import'), @args ]),
477 $Lingy::Evaluator::ENV,
478 );
479 }
480 else {
481 0 err "Invalid keyword arg '$keyword' in ns";
482 }
483 }
484  
485 14 nil;
486 }
487  
488 234 ▶sub nth { $_[0][$_[1]] }
Subroutine nth: called CC=1 SCAR=0.0
Pod undocumented
489  
490 4 ▶sub number { NUMBER->new("$_[0]" + 0) }
Subroutine number: called CC=1 SCAR=0.0
Pod undocumented
491  
492 0 ▶sub pos_Q { $_[0] > 0 ? true : false }
Subroutine pos_Q: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] > 0 ? : 0 0 0
493  
494 14 ▶sub pr_str {
Subroutine pr_str: called CC=1 SCAR=0.0
Pod undocumented
495 14 string(join ' ', map $printer->pr_str($_), @_);
496 }
497  
498 65 ▶sub println {
Subroutine println: called CC=1 SCAR=0.0
Pod undocumented
499 65 printf "%s\n", join ' ',
500 map $printer->pr_str($_, 1), @_;
501 65 nil;
502 }
503  
504 41 ▶sub prn {
Subroutine prn: called CC=1 SCAR=0.0
Pod undocumented
505 41 printf "%s\n", join ' ',
506 map $printer->pr_str($_), @_;
507 41 nil;
508 }
509  
510 45 ▶sub readString {
Subroutine readString: called CC=2 SCAR=6.9
Pod undocumented
511 45 my @forms = Lingy::Reader->new->read_str($_[0]);
512 45 ▶ return @forms ? $forms[0] : nil;
Branch: 1 branch
BranchTrueFalseTotal
@forms ? : 44 1 45
513 }
514  
515 0 ▶sub readline {
Subroutine readline: not called CC=2 SCAR=17.9
Pod undocumented
516 0 ▶ my $l = RL->readline // return;
Condition0%0/2
bless( {}, 'Lingy::ReadLine' )->readline // (return)
l!l
00
MC/DC0%0/1
bless( {}, 'Lingy::ReadLine' )->readline // (return)
bless( {}, 'Lingy::ReadLine' )->readline
Truth table0%0/2
A
A= bless( {}, 'Lingy::ReadLine' )->readline
Aresult
11
00
517 0 chomp $l;
518 0 string($l);
519 }
520  
521 56 our $require_ext = 'ly';
522 12 ▶sub require {
Subroutine require: called CC=6 SCAR=17.9
Pod undocumented
523 outer:
524 12 for my $spec (@_) {
525 12 ▶ err "'require' only works with symbols"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $spec eq "Lingy::Symbol" 0 12 12
526 unless ref($spec) eq SYMBOL;
527  
528 12 ▶ next if $namespaces{$$spec};
Branch: 1 branch
BranchTrueFalseTotal
if $namespaces{$$spec} 1 11 12
529  
530 11 my $name = $$spec;
531  
532 11 my $path = $name;
533 11 $path =~ s/^lingy\.lang\./Lingy./;
534 11 $path =~ s/^lingy\./Lingy\./;
535 11 my $module = $path;
536 11 $path =~ s/\./\//g;
537  
538 11 for my $inc (@INC) {
539 25 $inc =~ s{^([^/.])}{./$1};
540 25 my $inc_path = "$inc/$path";
541 25 ▶ if (-f "$inc_path.$require_ext") {
Branch: 1 branch
BranchTrueFalseTotal
if (-f "$inc_path.$Lingy::RT::require_ext") 10 15 25
542 10 my $ns = $namespaces{$current_ns_name};
543 10 RT->rep(qq< (load-file "$inc_path.$require_ext") >);
544 10 $ns->current;
545 10 next outer;
546 }
547 }
548  
549 1 err "Can't find library for (require '$name)";
550 }
551 11 return nil;
552 }
553  
554 1 ▶sub reset_BANG { $_[0]->[0] = $_[1] }
Subroutine reset_BANG: called CC=1 SCAR=0.0
Pod undocumented
555  
556 10 ▶sub resolve {
Subroutine resolve: called CC=4 SCAR=13.9
Pod undocumented
557 10 my ($symbol) = @_;
558 10 my ($ns_name, $sym_name, $var);
559 10 ▶ if ($symbol =~ /(.*?)\/(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($symbol =~ m[(.*?)/(.*)]) { } 4 6 10
560 4 ($ns_name, $sym_name) = ($1, $2);
561 }
562 else {
563 6 $ns_name = $current_ns_name;
564 6 $sym_name = $symbol;
565 }
566  
567 10 ▶ my $ns = $namespaces{$ns_name} or return nil;
Branch: 1 branch
BranchTrueFalseTotal
my $ns = $namespaces{$ns_name} or return nil() 8 2 10
568 8 ▶ if (exists $ns->{$sym_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ns->{$sym_name}) { } 4 4 8
569 4 $var = $ns_name . '/' . $sym_name;
570 } else {
571 4 return nil;
572 }
573 4 return VAR->new($var);
574 }
575  
576 54 ▶sub seq {
Subroutine seq: called CC=2 SCAR=6.9
Pod undocumented
577 54 my ($o) = @_;
578 54 ▶ $o->can('_to_seq') or
Branch: 1 branch
BranchTrueFalseTotal
$o->can("_to_seq") or err(sprintf("Don't know how to create ISeq from: %s", $o->NAME)) 51 3 54
579 err(sprintf "Don't know how to create ISeq from: %s", $o->NAME); # XXX NAME is Class name not namespace
580 51 $o->_to_seq;
581 }
582  
583 25 ▶sub slurp { string(RT->slurp_file($_[0])) }
Subroutine slurp: called CC=1 SCAR=0.0
Pod undocumented
584  
585 0 ▶sub sort {
Subroutine sort: not called CC=1 SCAR=6.9
Pod undocumented
586 list([
587 0 CORE::sort @{$_[0]}
588 ]);
589 }
590  
591 72 ▶sub str {
Subroutine str: called CC=1 SCAR=0.0
Pod undocumented
592 string(
593 join '',
594 map $printer->pr_str($_, 1),
595 72 grep {ref($_) ne NIL}
596 @_
597 );
598 }
599  
600 10 ▶sub swap_BANG {
Subroutine swap_BANG: called CC=1 SCAR=0.0
Pod undocumented
601 10 my ($atom, $fn, $args) = @_;
602 10 $atom->[0] = apply($fn, [[$atom->[0], @$args]]);
603 }
604  
605 5 ▶sub symbol_ { symbol("$_[0]") }
Subroutine symbol_: called CC=1 SCAR=0.0
Pod undocumented
606  
607 15 ▶sub the_ns {
Subroutine the_ns: called CC=4 SCAR=14.3
Pod undocumented
608 $_[0]->isa(NAMESPACE) ? $_[0] :
609 15 ▶ $_[0]->isa(SYMBOL) ? do {
Branch: 2 branches
BranchTrueFalseTotal
$_[0]->isa('Lingy::Namespace') ? : 8 7 15
$_[0]->isa('Lingy::Symbol') ? : 7 0 7
610 7 ▶ $namespaces{$_[0]} //
Condition66%2/3
$namespaces{$_[0]} // err("No namespace: '$_[0]' found")
l!l&&r!l&&!r
601
MC/DC0%0/2
$namespaces{$_[0]} // err("No namespace: '$_[0]' found")
$namespaces{$_[0]} err("No namespace: '$_[0]' found")
Truth table33%1/3
A // B
A= $namespaces{$_[0]}B= err("No namespace: '$_[0]' found")
ABresult
1X1
011
000
611 err "No namespace: '$_[0]' found";
612 } : err "Invalid argument for the-ns: '$_[0]'";
613 }
614  
615 2 ▶sub time_ms {
Subroutine time_ms: called CC=1 SCAR=0.0
Pod undocumented
616 2 require Time::HiRes;
617 2 my ($s, $m) = Time::HiRes::gettimeofday();
618 2 NUMBER->new($s * 1000 + $m / 1000);
619 }
620  
621 24 ▶sub type {
Subroutine type: called CC=1 SCAR=0.0
Pod undocumented
622 24 CLASS->_new(ref($_[0]));
623 }
624  
625 30 ▶sub with_meta {
Subroutine with_meta: called CC=2 SCAR=7.4
Pod undocumented
626 30 my ($o, $m) = @_;
627 0 ▶ $o = ref($o) eq 'CODE' ? sub { goto &$o } : $o->clone;
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
ref $o eq 'CODE' ? : 0 30 30
628 30 $meta{$o} = $m;
629 30 $o;
630 }
631  
632 5 ▶sub vals { list([ values %{$_[0]} ]) }
Subroutine vals: called CC=1 SCAR=0.0
Pod undocumented
633  
634 0 ▶sub var_ { VAR->new($_[0]) }
Subroutine var_: not called CC=1 SCAR=6.9
Pod undocumented
635  
636 419 ▶sub vec { VECTOR->new([@{$_[0]}]) }
Subroutine vec: called CC=1 SCAR=0.0
Pod undocumented
637  
638 3 ▶sub vector { VECTOR->new([@_]) }
Subroutine vector: called CC=1 SCAR=0.0
Pod undocumented
639  
640 56 1;
« lib/Lingy/String.pm ↑ Summary lib/Lingy/Reader.pm »