lib/Lingy/Fn.pm

filter: Statementstmt 98.0% 50 / 51 Branchbran 93.7% 30 / 32 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 3 totaltotal 92.7% 89 / 96 CC 18 SCAR 22.3
CC
18
Cov
96%
new
15.0
__ANON__
4.0
unbox
2.0
CRAP 9.3
« lib/Lingy/Reader.pm ↑ Summary blib/lib/Lingy/Evaluator.pm »
1 53 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Lingy::Fn;
3  
4 53 ▶use base 'Lingy::Class';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 53 ▶use Lingy::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 53 ▶use Sub::Name 'subname';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 53 *list = \&Lingy::Common::list;
11 53 *symbol = \&Lingy::Common::symbol;
12 sub err;
13 53 *err = \&Lingy::Common::err;
14  
15 7925 ▶sub new {
Subroutine new: called CC=15 SCAR=27.1
Pod undocumented
16 7925 my ($class, $ast, $env) = @_;
17  
18 7925 my (undef, @exprs) = @$ast;
19  
20 7925 my $name = \'AFn';
21 7925 ▶ $name = shift @exprs if ref($exprs[0]) eq SYMBOL;
Branch: 1 branch
BranchTrueFalseTotal
if ref $exprs[0] eq "Lingy::Symbol" 486 7439 7925
22  
23 7925 ▶ shift @exprs if ref($exprs[0]) eq STRING;
Branch: 1 branch
BranchTrueFalseTotal
if ref $exprs[0] eq "Lingy::String" 2649 5276 7925
24 7925 ▶ shift @exprs if ref($exprs[0]) eq HASHMAP;
Branch: 1 branch
BranchTrueFalseTotal
if ref $exprs[0] eq "Lingy::HashMap" 2649 5276 7925
25  
26 7925 ▶ @exprs = (list([@exprs]))
Branch: 1 branch
BranchTrueFalseTotal
if ref $exprs[0] eq "Lingy::Vector" 6888 1037 7925
27 if ref($exprs[0]) eq VECTOR;
28  
29 7925 my $functions = [];
30 7925 my $variadic = '';
31  
32 7925 for my $expr (@exprs) {
33 9935 ▶ err "fn expr is not a list"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $expr eq "Lingy::List" 0 9935 9935
34 unless ref($expr) eq LIST;
35 9935 my ($sig, @body) = @$expr;
36 9935 ▶ err "fn signature not a vector"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sig eq "Lingy::Vector" 1 9934 9935
37 unless ref($sig) eq VECTOR;
38 9934 ▶ my $arity = (grep {$$_ eq '&'} @$sig) ? -1 : @$sig;
Branch: 1 branch
BranchTrueFalseTotal
grep({$$_ eq '&';} @$sig) ? : 2741 7193 9934
39 9934 ▶ if ($arity == -1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($arity == -1) { } 2741 7193 9934
elsif ($variadic) { } 1 7192 7193
40 2741 $variadic = @$sig - 1;
41 } elsif ($variadic) {
42 1 ▶ err "Can't have fixed arity function " .
Branch: 1 branch
BranchTrueFalseTotal
if @$sig > $variadic 1 0 1
43 "with more params than variadic function"
44 if @$sig > $variadic;
45 }
46 9933 ▶ @body = (list([ symbol('do'), @body ]))
Branch: 1 branch
BranchTrueFalseTotal
if @body > 1 329 9604 9933
47 if @body > 1;
48 9933 ▶ if (exists $functions->[$arity+1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$functions[$arity + 1]) 2 9931 9933
49 2 ▶ err $arity == -1
Branch: 1 branch
BranchTrueFalseTotal
$arity == -1 ? : 1 1 2
50 ? "Can't have more than 1 variadic overload"
51 : "Can't have 2 overloads with same arity";
52 }
53 9931 $functions->[$arity+1] = [$sig, @body];
54 }
55  
56 99897 ▶ subname $name => bless sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
57 99897 my $arity = @_;
58 99897 ▶ my $function =
Branch: 2 branches
BranchTrueFalseTotal
$$functions[$arity + 1] ? : 75684 24213 99897
$arity >= @$functions - 1 ? : 24209 4 24213
59 $functions->[$arity+1] ? $functions->[$arity+1] :
60 $arity >= (@$functions-1) ? $functions->[0] : undef;
61 99897 ▶ err "Wrong number of args ($arity) passed to function"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $function 5 99892 99897
62 unless defined $function;
63 99892 my ($sig, $ast) = @$function;
64  
65 return (
66 99892 $ast,
67 Lingy::Env->new(
68 outer => $env,
69 binds => $sig,
70 exprs => \@_,
71 ),
72 );
73 7921 }, $class;
74 }
75  
76 13 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod undocumented
77 13 my ($fn) = @_;
78 13 ▶ bless sub { goto &$fn }, ref($fn);
Subroutine __ANON__: called CC=1 SCAR=0.0
79 }
80  
81 0 ▶sub unbox { $_[0] }
Subroutine unbox: not called CC=1 SCAR=6.9
Pod undocumented
82  
83 53 1;
« lib/Lingy/Reader.pm ↑ Summary blib/lib/Lingy/Evaluator.pm »