FLAT/Regex/WithExtraOps.pm

filter: Statementstmt 53.1% 34 / 64 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 14 / 28 Podpod 50.0% 1 / 2 totaltotal 50.0% 49 / 98 CC 3 SCAR 7.3
CC
3
Cov
50%
as_string
6.0
as_string
6.0
negate
2.0
CRAP 2.1
« FLAT/Regex/Op.pm ↑ Summary FLAT.pm »
1 package FLAT::Regex::WithExtraOps;
2 6 ▶use parent 'FLAT::Regex';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 #### Precedence
8 # 30 ::star
9 # 20 ::concat
10 # 15 ::negate <---<< WithExtraOps
11 # 12 ::shuffle <---<< WithExtraOps
12 # 10 ::alt
13 # 0 ::atomic
14  
15 6 my $PARSER = FLAT::Regex::Parser->new(qw[ alt concat star negate shuffle ]);
16 2960 ▶sub _parser {$PARSER}
Subroutine _parser: called CC=1 SCAR=0.0
17  
18 0 ▶sub negate {
Subroutine negate: not called CC=1 SCAR=6.9
Pod undocumented
19 0 my $self = $_[0];
20 0 my $op = FLAT::Regex::Op::negate->new(map {$_->as_regex->op} @_);
21 0 $self->_from_op($op);
22 }
23  
24 ###############################
25 0 ▶sub shuffle {
Subroutine shuffle: not called CC=1 SCAR=6.9
Pod documented
26 0 my $self = $_[0];
27 0 my $op = FLAT::Regex::Op::shuffle->new(map {$_->as_regex->op} @_);
28 0 $self->_from_op($op);
29 }
30  
31 package FLAT::Regex::Op::negate;
32 6 ▶use parent "FLAT::Regex::Op";
Subroutine BEGIN: called CC=1 SCAR=0.0
33 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 6 ▶sub parse_spec {"'~' %s";}
Subroutine parse_spec: called CC=1 SCAR=0.0
36 6 ▶sub precedence {15} # between concat and alternation
Subroutine precedence: called CC=1 SCAR=0.0
37  
38 0 ▶sub as_string {
Subroutine as_string: not called CC=2 SCAR=17.9
39 0 my ($self, $prec) = @_;
40 0 my $result = "~" . $self->members->as_string($self->precedence);
41 0 ▶ return $prec > $self->precedence ? "($result)" : $result;
Branch: 1 branch
BranchTrueFalseTotal
$prec > $self->precedence ? : 0 0 0
42 }
43  
44 0 ▶sub from_parse {
Subroutine from_parse: not called CC=1 SCAR=6.9
45 0 my ($pkg, @item) = @_;
46 0 $pkg->new($item[2]);
47 }
48  
49 ## note: "reverse" conflicts with perl builtin
50 0 ▶sub reverse {
Subroutine reverse: not called CC=1 SCAR=6.9
51 0 my $self = shift;
52 0 my $op = $self->members->reverse;
53 0 __PACKAGE__->new($op);
54 }
55  
56 0 ▶sub is_empty {
Subroutine is_empty: not called CC=1 SCAR=6.9
57 0 croak "Not implemented for negated regexes";
58 }
59  
60 0 ▶sub has_nonempty_string {
Subroutine has_nonempty_string: not called CC=1 SCAR=6.9
61 0 croak "Not implemented for negated regexes";
62 }
63  
64 0 ▶sub is_finite {
Subroutine is_finite: not called CC=1 SCAR=6.9
65 0 croak "Not implemented for negated regexes";
66 }
67  
68 ###############################
69 package FLAT::Regex::Op::shuffle;
70 6 ▶use parent 'FLAT::Regex::Op';
Subroutine BEGIN: called CC=1 SCAR=0.0
71 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 6 ▶sub parse_spec {"%s(2.. /[&]/)"}
Subroutine parse_spec: called CC=1 SCAR=0.0
74 6 ▶sub precedence {12}
Subroutine precedence: called CC=1 SCAR=0.0
75  
76 0 ▶sub as_string {
Subroutine as_string: not called CC=2 SCAR=17.9
77 0 my ($self, $prec) = @_;
78 0 my $result = join "&", map {$_->as_string($self->precedence)} $self->members;
79 0 ▶ return $prec > $self->precedence ? "($result)" : $result;
Branch: 1 branch
BranchTrueFalseTotal
$prec > $self->precedence ? : 0 0 0
80 }
81  
82 0 ▶sub as_perl_regex {
Subroutine as_perl_regex: not called CC=1 SCAR=6.9
83 0 my $self = shift;
84 0 croak "Not implemented for shuffled regexes";
85 }
86  
87 1358 ▶sub from_parse {
Subroutine from_parse: called CC=1 SCAR=0.0
88 1358 my ($pkg, @item) = @_;
89 1358 $pkg->new(@{$item[1]});
90 }
91  
92 48 ▶sub as_pfa {
Subroutine as_pfa: called CC=1 SCAR=0.0
93 48 my $self = shift;
94 48 my @parts = map {$_->as_pfa} $self->members;
95 48 $parts[0]->shuffle(@parts[1 .. $#parts]);
96 }
97  
98 # Implement?
99 0 ▶sub reverse {
Subroutine reverse: not called CC=1 SCAR=6.9
100 0 my $self = shift;
101 0 croak "Not implemented for shuffled regexes";
102 }
103  
104 0 ▶sub is_empty {
Subroutine is_empty: not called CC=1 SCAR=6.9
105 0 croak "Not implemented for shuffled regexes";
106 }
107  
108 0 ▶sub has_nonempty_string {
Subroutine has_nonempty_string: not called CC=1 SCAR=6.9
109 0 croak "Not implemented for shuffled regexes";
110 }
111  
112 0 ▶sub is_finite {
Subroutine is_finite: not called CC=1 SCAR=6.9
113 0 croak "Not implemented for shuffled regexes";
114 }
« FLAT/Regex/Op.pm ↑ Summary FLAT.pm »