lib/Lingy/Lang/Fn.pm

filter: Statementstmt 32.5% 13 / 40 Branchbran 0.0% 0 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 37.5% 3 / 8 Podpod 0.0% 0 / 3 totaltotal 21.3% 16 / 75 CC 14 SCAR 45.1
CC
14
Cov
20%
new
156.0
__ANON__
12.0
clone
2.0
CRAP 91.3
« lib/Lingy/Eval.pm ↑ Summary lib/Lingy/Lang/Numbers.pm »
1 1 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Lingy::Lang::Fn;
3  
4 1 ▶use Lingy::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 *list = \&Lingy::Common::list;
7 1 *symbol = \&Lingy::Common::symbol;
8 sub err;
9 1 *err = \&Lingy::Common::err;
10  
11 sub new {
12 0 ▶ my ($class, $ast, $env) = @_;
Subroutine new: not called CC=12 SCAR=50.5
Pod undocumented
13  
14 0 my (undef, @exprs) = @$ast;
15 0 ▶ @exprs = (list([@exprs]))
Branch: 1 branch
BranchTrueFalseTotal
if ref $exprs[0] eq "Lingy::Lang::Vector" 0 0 0
16 if ref($exprs[0]) eq VECTOR;
17  
18 0 my $functions = [];
19 0 my $variadic = '';
20  
21 0 for my $expr (@exprs) {
22 0 ▶ err "fn expr is not a list"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $expr eq "Lingy::Lang::List" 0 0 0
23 unless ref($expr) eq LIST;
24 0 my ($sig, @body) = @$expr;
25 0 ▶ err "fn signature not a vector"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sig eq "Lingy::Lang::Vector" 0 0 0
26 unless ref($sig) eq VECTOR;
27 0 ▶ my $arity = (grep {$$_ eq '&'} @$sig) ? -1 : @$sig;
Branch: 1 branch
BranchTrueFalseTotal
grep({$$_ eq '&';} @$sig) ? : 0 0 0
28 0 ▶ if ($arity == -1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($arity == -1) { } 0 0 0
elsif ($variadic) { } 0 0 0
29 0 $variadic = @$sig - 1;
30 } elsif ($variadic) {
31 0 ▶ err "Can't have fixed arity function " .
Branch: 1 branch
BranchTrueFalseTotal
if @$sig > $variadic 0 0 0
32 "with more params than variadic function"
33 if @$sig > $variadic;
34 }
35 0 ▶ @body = (list([ symbol('do'), @body ]))
Branch: 1 branch
BranchTrueFalseTotal
if @body > 1 0 0 0
36 if @body > 1;
37 0 ▶ if (exists $functions->[$arity+1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$functions[$arity + 1]) 0 0 0
38 0 ▶ err $arity == -1
Branch: 1 branch
BranchTrueFalseTotal
$arity == -1 ? : 0 0 0
39 ? "Can't have more than 1 variadic overload"
40 : "Can't have 2 overloads with same arity";
41 }
42 0 $functions->[$arity+1] = [$sig, @body];
43 }
44  
45 bless sub {
46 0 ▶ my $arity = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
47 0 ▶ my $function =
Branch: 2 branches
BranchTrueFalseTotal
$$functions[$arity + 1] ? : 0 0 0
$arity >= @$functions - 1 ? : 0 0 0
48 $functions->[$arity+1] ? $functions->[$arity+1] :
49 $arity >= (@$functions-1) ? $functions->[0] :
50 err "Wrong number of args ($arity) passed to function";
51 0 my ($sig, $ast) = @$function;
52  
53 return (
54 0 $ast,
55 Lingy::Env->new(
56 outer => $env,
57 binds => $sig,
58 exprs => \@_,
59 ),
60 );
61 0 }, $class;
62 }
63  
64 sub clone {
65 0 ▶ my ($fn) = @_;
Subroutine clone: not called CC=1 SCAR=6.9
Pod undocumented
66 0 ▶ bless sub { goto &$fn }, ref($fn);
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 }
68  
69 0 ▶sub unbox { $_[0] }
Subroutine unbox: not called CC=1 SCAR=6.9
Pod undocumented
70  
71 1 1;
« lib/Lingy/Eval.pm ↑ Summary lib/Lingy/Lang/Numbers.pm »