| 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
| |||||||||||
| 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
| |||||||||||
| 24 | 1904 | push @patterns, [$names, $handler]; | |||||||||
| 25 | 1904 | return; | |||||||||
| 26 | } | ||||||||||
| 27 | 6664 | ▶ | $names = [$names] unless ref($names) eq 'ARRAY'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 6664 | for my $name (@{$names}) { | |||||||||
| 29 | 11288 | ▶ | die "duplicate built-in registration: $name" if exists $registry{$name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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; | |||||||||