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 3005 ▶sub _parser {$PARSER}
Subroutine _parser: called CC=1 SCAR=0.0
17  
18 sub negate {
19 0 ▶ my $self = $_[0];
Subroutine negate: not called CC=1 SCAR=6.9
Pod undocumented
20 0 my $op = FLAT::Regex::Op::negate->new(map {$_->as_regex->op} @_);
21 0 $self->_from_op($op);
22 }
23  
24 ###############################
25 sub shuffle {
26 0 ▶ my $self = $_[0];
Subroutine shuffle: not called CC=1 SCAR=6.9
Pod documented
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 sub as_string {
39 0 ▶ my ($self, $prec) = @_;
Subroutine as_string: not called CC=2 SCAR=17.9
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 sub from_parse {
45 0 ▶ my ($pkg, @item) = @_;
Subroutine from_parse: not called CC=1 SCAR=6.9
46 0 $pkg->new($item[2]);
47 }
48  
49 ## note: "reverse" conflicts with perl builtin
50 sub reverse {
51 0 ▶ my $self = shift;
Subroutine reverse: not called CC=1 SCAR=6.9
52 0 my $op = $self->members->reverse;
53 0 __PACKAGE__->new($op);
54 }
55  
56 sub is_empty {
57 0 ▶ croak "Not implemented for negated regexes";
Subroutine is_empty: not called CC=1 SCAR=6.9
58 }
59  
60 sub has_nonempty_string {
61 0 ▶ croak "Not implemented for negated regexes";
Subroutine has_nonempty_string: not called CC=1 SCAR=6.9
62 }
63  
64 sub is_finite {
65 0 ▶ croak "Not implemented for negated regexes";
Subroutine is_finite: not called CC=1 SCAR=6.9
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 sub as_string {
77 0 ▶ my ($self, $prec) = @_;
Subroutine as_string: not called CC=2 SCAR=17.9
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 sub as_perl_regex {
83 0 ▶ my $self = shift;
Subroutine as_perl_regex: not called CC=1 SCAR=6.9
84 0 croak "Not implemented for shuffled regexes";
85 }
86  
87 sub from_parse {
88 1345 ▶ my ($pkg, @item) = @_;
Subroutine from_parse: called CC=1 SCAR=0.0
89 1345 $pkg->new(@{$item[1]});
90 }
91  
92 sub as_pfa {
93 39 ▶ my $self = shift;
Subroutine as_pfa: called CC=1 SCAR=0.0
94 39 my @parts = map {$_->as_pfa} $self->members;
95 39 $parts[0]->shuffle(@parts[1 .. $#parts]);
96 }
97  
98 # Implement?
99 sub reverse {
100 0 ▶ my $self = shift;
Subroutine reverse: not called CC=1 SCAR=6.9
101 0 croak "Not implemented for shuffled regexes";
102 }
103  
104 sub is_empty {
105 0 ▶ croak "Not implemented for shuffled regexes";
Subroutine is_empty: not called CC=1 SCAR=6.9
106 }
107  
108 sub has_nonempty_string {
109 0 ▶ croak "Not implemented for shuffled regexes";
Subroutine has_nonempty_string: not called CC=1 SCAR=6.9
110 }
111  
112 sub is_finite {
113 0 ▶ croak "Not implemented for shuffled regexes";
Subroutine is_finite: not called CC=1 SCAR=6.9
114 }
« FLAT/Regex/Op.pm ↑ Summary FLAT.pm »