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
« blib/lib/Lingy/Character.pm ↑ Summary blib/lib/Lingy/Evaluator.pm »
1 57 ▶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 57 ▶use base 'Lingy::Class';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 57 ▶use Lingy::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 57 ▶use Sub::Name 'subname';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 57 *list = \&Lingy::Common::list;
11 57 *symbol = \&Lingy::Common::symbol;
12 sub err;
13 57 *err = \&Lingy::Common::err;
14  
15 sub new {
16 8497 ▶ my ($class, $ast, $env) = @_;
Subroutine new: called CC=15 SCAR=27.1
Pod undocumented
17  
18 8497 my (undef, @exprs) = @$ast;
19  
20 8497 my $name = \'AFn';
21 8497 ▶ $name = shift @exprs if ref($exprs[0]) eq SYMBOL;
Branch: 1 branch
BranchTrueFalseTotal
if ref $exprs[0] eq "Lingy::Symbol" 522 7975 8497
22  
23 8497 ▶ shift @exprs if ref($exprs[0]) eq STRING;
Branch: 1 branch
BranchTrueFalseTotal
if ref $exprs[0] eq "Lingy::String" 2845 5652 8497
24 8497 ▶ shift @exprs if ref($exprs[0]) eq HASHMAP;
Branch: 1 branch
BranchTrueFalseTotal
if ref $exprs[0] eq "Lingy::HashMap" 2845 5652 8497
25  
26 8497 ▶ @exprs = (list([@exprs]))
Branch: 1 branch
BranchTrueFalseTotal
if ref $exprs[0] eq "Lingy::Vector" 7384 1113 8497
27 if ref($exprs[0]) eq VECTOR;
28  
29 8497 my $functions = [];
30 8497 my $variadic = '';
31  
32 8497 for my $expr (@exprs) {
33 10655 ▶ err "fn expr is not a list"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $expr eq "Lingy::List" 0 10655 10655
34 unless ref($expr) eq LIST;
35 10655 my ($sig, @body) = @$expr;
36 10655 ▶ err "fn signature not a vector"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sig eq "Lingy::Vector" 1 10654 10655
37 unless ref($sig) eq VECTOR;
38 10654 ▶ my $arity = (grep {$$_ eq '&'} @$sig) ? -1 : @$sig;
Branch: 1 branch
BranchTrueFalseTotal
grep({$$_ eq '&';} @$sig) ? : 2941 7713 10654
39 10654 ▶ if ($arity == -1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($arity == -1) { } 2941 7713 10654
elsif ($variadic) { } 1 7712 7713
40 2941 $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 10653 ▶ @body = (list([ symbol('do'), @body ]))
Branch: 1 branch
BranchTrueFalseTotal
if @body > 1 353 10300 10653
47 if @body > 1;
48 10653 ▶ if (exists $functions->[$arity+1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$functions[$arity + 1]) 2 10651 10653
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 10651 $functions->[$arity+1] = [$sig, @body];
54 }
55  
56 subname $name => bless sub {
57 101415 ▶ my $arity = @_;
Subroutine __ANON__: called CC=4 SCAR=13.9
58 101415 ▶ my $function =
Branch: 2 branches
BranchTrueFalseTotal
$$functions[$arity + 1] ? : 75688 25727 101415
$arity >= @$functions - 1 ? : 25723 4 25727
59 $functions->[$arity+1] ? $functions->[$arity+1] :
60 $arity >= (@$functions-1) ? $functions->[0] : undef;
61 101415 ▶ err "Wrong number of args ($arity) passed to function"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $function 5 101410 101415
62 unless defined $function;
63 101410 my ($sig, $ast) = @$function;
64  
65 return (
66 101410 $ast,
67 Lingy::Env->new(
68 outer => $env,
69 binds => $sig,
70 exprs => \@_,
71 ),
72 );
73 8493 }, $class;
74 }
75  
76 sub clone {
77 13 ▶ my ($fn) = @_;
Subroutine clone: called CC=1 SCAR=0.0
Pod undocumented
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 57 1;
« blib/lib/Lingy/Character.pm ↑ Summary blib/lib/Lingy/Evaluator.pm »