blib/lib/JQ/Lite/Builtin.pm

filter: Statementstmt 100% 57 / 57 Branchbran 91.6% 11 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 2 totaltotal 96.4% 81 / 84 CC 10 SCAR 10.0
CC
10
Cov
99%
__ANON__
5.0
dispatch
4.0
_registry
3.0
CRAP 2.7
« blib/lib/JQ/Lite.pm ↑ Summary blib/lib/JQ/Lite/Runtime.pm »
1 package JQ::Lite::Builtin;
2  
3 182 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 182 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 182 ▶use JQ::Lite::Builtin::Aggregate ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 182 ▶use JQ::Lite::Builtin::Array ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 182 ▶use JQ::Lite::Builtin::Encoding ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 182 ▶use JQ::Lite::Builtin::Math ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 182 ▶use JQ::Lite::Builtin::Object ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 182 ▶use JQ::Lite::Builtin::String ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 182 ▶use JQ::Lite::Builtin::Type ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 182 my $REGISTRY;
15  
16 1285 ▶sub _registry {
Subroutine _registry: called CC=3 SCAR=11.0
17 1285 ▶ return $REGISTRY if $REGISTRY;
Branch: 1 branch
BranchTrueFalseTotal
if $REGISTRY 1149 136 1285
18  
19 136 my %registry;
20 my @patterns;
21 8568 ▶ my $register = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
22 8568 my ($names, $handler) = @_;
23 8568 ▶ if (ref($names) eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $names eq "Regexp") 1904 6664 8568
24 1904 push @patterns, [$names, $handler];
25 1904 return;
26 }
27 6664 ▶ $names = [$names] unless ref($names) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $names eq "ARRAY" 2040 4624 6664
28 6664 for my $name (@{$names}) {
29 11288 ▶ die "duplicate built-in registration: $name" if exists $registry{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $registry{$name} 0 11288 11288
30 11288 $registry{$name} = $handler;
31 }
32 136 };
33  
34 136 $_->register($register) for qw(
35 JQ::Lite::Builtin::Array
36 JQ::Lite::Builtin::Object
37 JQ::Lite::Builtin::String
38 JQ::Lite::Builtin::Math
39 JQ::Lite::Builtin::Aggregate
40 JQ::Lite::Builtin::Encoding
41 JQ::Lite::Builtin::Type
42 );
43  
44 136 $REGISTRY = { exact => \%registry, patterns => \@patterns };
45 136 return $REGISTRY;
46 }
47  
48 1284 ▶sub dispatch {
Subroutine dispatch: called CC=4 SCAR=13.9
Pod undocumented
49 1284 my ($class, $owner, $name, $inputs) = @_;
50 1284 my $registry = _registry();
51 1284 my $handler = $registry->{exact}{$name};
52 1284 ▶ return (1, $handler->($owner, $inputs)) if $handler;
Branch: 1 branch
BranchTrueFalseTotal
if $handler 268 1016 1284
53  
54 1016 for my $entry (@{ $registry->{patterns} }) {
55 13429 my ($pattern, $pattern_handler) = @{$entry};
56 13429 ▶ if (my @captures = ($name =~ $pattern)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@captures) = $name =~ /$pattern/) 139 13290 13429
57 139 return (1, $pattern_handler->($owner, $inputs, @captures));
58 }
59 }
60 877 return (0, []);
61 }
62  
63 1 ▶sub registered_names {
Subroutine registered_names: called CC=1 SCAR=0.0
Pod undocumented
64 1 return sort keys %{ _registry()->{exact} };
65 }
66  
67 182 1;
« blib/lib/JQ/Lite.pm ↑ Summary blib/lib/JQ/Lite/Runtime.pm »