| 1 | package Pegex::Regex; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Pegex::Parser; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Pegex::Grammar; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Pegex::Receiver; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | my @parsers; | |||||||||||||||||||||||||||
| 8 | 1 | my $PASS = ''; | |||||||||||||||||||||||||||
| 9 | 1 | my $FAIL = '(*FAIL)'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub generate_regex { | ||||||||||||||||||||||||||
|
Subroutine
generate_regex: not called CC=1 SCAR=1.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 0 | push @parsers, Pegex::Parser->new( | |||||||||||||||||||||||||||
| 13 | grammar => Pegex::Grammar->new( text => shift ), | ||||||||||||||||||||||||||||
| 14 | receiver => Pegex::Receiver->new, | ||||||||||||||||||||||||||||
| 15 | throw_on_error => 0, | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | 0 | my $index = $#parsers; | |||||||||||||||||||||||||||
| 18 | 0 | my $regex = "(??{Pegex::Regex::parse($index, \$_)})"; | |||||||||||||||||||||||||||
| 19 | 1 | ▶ | use re 'eval'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 0 | return qr{$regex}; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 0 | my ($index, $input) = @_; | |||||||||||||||||||||||||||
| 25 | 0 | undef %/; | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | my $ast = $parsers[$index]->parse($input) or return $FAIL; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | %/ = %$ast if ref($ast) eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 0 | return $PASS; | |||||||||||||||||||||||||||
| 29 | }; | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # The following code was mutated from Damian Conway's Regexp::Grammars | ||||||||||||||||||||||||||||
| 32 | 1 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=2.1
| |||||||||||||||||||||||||||||
| 33 | # Signal lexical scoping (active, unless something was exported)... | ||||||||||||||||||||||||||||
| 34 | 1 | $^H{'Pegex::Regex::active'} = 1; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # Process any regexes in module's active lexical scope... | ||||||||||||||||||||||||||||
| 37 | 1 | ▶ | use overload; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | overload::constant( | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | qr => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 40 | 0 | my ($raw, $cooked, $type) = @_; | |||||||||||||||||||||||||||
| 41 | # If active scope and really a regex... | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | return generate_regex($raw) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
_module_is_active() and $type =~ /qq?/
MC/DC0%0/2
_module_is_active() and $type =~ /qq?/
_module_is_active()
$type =~ /qq?/
Truth table0%0/3
A and B
A= _module_is_active()B= $type =~ /qq?/
| |||||||||||||||||||||||||||||
| 43 | if _module_is_active() and $type =~ /qq?/; | ||||||||||||||||||||||||||||
| 44 | # Ignore everything else... | ||||||||||||||||||||||||||||
| 45 | 0 | return $cooked; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 1 | ); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # Deactivate module's regex effect when it is "anti-imported" with 'no'... | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub unimport { | ||||||||||||||||||||||||||
|
Subroutine
unimport: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 52 | # Signal lexical (non-)scoping... | ||||||||||||||||||||||||||||
| 53 | 0 | $^H{'Pegex::Regex::active'} = 0; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # Encapsulate the hoopy user-defined pragma interface... | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub _module_is_active { | ||||||||||||||||||||||||||
|
Subroutine
_module_is_active: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 58 | 0 | return (caller 1)[10]->{'Pegex::Regex::active'}; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1 | 1; | |||||||||||||||||||||||||||