| 1 | package Zed::Range::Parser; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Zed::Output; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Zed::Range::Set; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # i{01~09,-05}.xx.corp.net,i{1~3,9}.yy.corp.com,-/4/,&/net/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | #transter to: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # i*{01~09-05}*.xx.corp.net,i*{1~3,9}*.yy.corp.com-/4/&/net/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | #priority: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # 0: } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # 1: - & | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # 2: , | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # 3: * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # 4: ~ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # 5: { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | our %PRI = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | '}' => 0, '#' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | '-' => 1, '&' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | ',' => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | '*' => 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | '~' => 4, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | '{' => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub _pri { $_[0] eq '{' ? $_[1] eq '}' : $PRI{ $_[0] } >= $PRI{ $_[1] } } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pri: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub _toset{ map{ ref $_ ? $_ : Zed::Range::Set->new($_) }@_ } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_toset: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | sub oprange | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | my $values = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oprange: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | return if @$values < 2; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my ($a, $b, $zero) = splice @$values, -2 ,2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | map{$zero = length $_ if $zero < length $_; s/^(0*)//; }($a, $b); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my @num = $a > $b ? ($b..$a) : ($a..$b); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | debug("num:", \@num); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | debug("zero:", $zero); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $set = Zed::Range::Set->new( map{sprintf "%0$zero\d",$_}@num ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | push @$values, $set; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | sub opdescart | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my $values = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
opdescart: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my ($a, $b) = _toset( splice @$values, -2 ,2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | push @$values, $a*$b; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | sub opunion | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | my $values = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
opunion: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my ($a, $b) = _toset( splice @$values, -2 ,2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | push @$values, $a + $b; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | sub opdiff | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | my $values = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
opdiff: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my ($a, $b) = splice @$values, -2 ,2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | $a = ref $a ? $a : Zed::Range::Set->new($a); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | $b = ref $b ? $b : $b =~ qr!^/(.*)/$! ? $1 : Zed::Range::Set->new($b); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | push @$values, $a - $b; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | sub opintersec | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | my $values = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
opintersec: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my ($a, $b) = splice @$values, -2 ,2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $a = ref $a ? $a : Zed::Range::Set->new($a); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | $b = ref $b ? $b : $b =~ qr!^/(.*)/$! ? $1 : Zed::Range::Set->new($b); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | push @$values, $a & $b; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | sub parse | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | my( $class, $str ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $str =~ s/$/#/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $str =~ s/,([\,\&])/$1/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | #add * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | #foo.{} => foo.*{} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | #{}.bar => {}*.bar | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | #{foo,bar}{baz,foobar} => {foo,bar}*{baz,foobar} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $str =~ s!([\w\.}]){!$1*{!g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $str =~ s!}([\w\.])!}*$1!g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my @strs = split qr!(,-)|([{},~&*#])!, $str; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my (@values, @ops); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | my $calcu = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | return if @values < 2; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | #use feature "switch"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | #for(pop @ops) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | #{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # when(/\~/) { oprange(\@values) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # when(/\*/) { opdescart(\@values) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # when(/\,/) { opunion(\@values) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # when(/\-/) { opdiff(\@values) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # when(/\&/) { opintersec(\@values) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | #} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $_ = pop @ops; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if(/\~/) { oprange(\@values); last } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if(/\*/) { opdescart(\@values); last } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if(/\,/) { opunion(\@values); last } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if(/\-/) { opdiff(\@values); last } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if(/\&/) { opintersec(\@values); last } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | PARSE: foreach my $str (@strs) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | next unless $str; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $str =~ s!,-!-!; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | push @values, $str and next unless $str =~ /^[\{\}\,\~\-\&*\#]$/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$str =~ /^[\{\}\,\~\-\&*\#]$/ || push(@values, $str) && (next)
push @values, $str and next
MC/DC0%0/2
$str =~ /^[\{\}\,\~\-\&*\#]$/ || push(@values, $str) && (next)
$str =~ /^[\{\}\,\~\-\&*\#]$/
push @values, $str
Truth table0%0/3
A || B
A= $str =~ /^[\{\}\,\~\-\&*\#]$/B= push @values, $str
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | while( $ops[-1] && _pri( $ops[-1], $str ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ops[-1] and _pri($ops[-1], $str)
MC/DC0%0/2
$ops[-1] and _pri($ops[-1], $str)
$ops[-1]
_pri($ops[-1], $str)
Truth table0%0/3
A and B
A= $ops[-1]B= _pri($ops[-1], $str)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | pop @ops and next PARSE if $ops[-1] eq '{' && $str eq '}'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/8
$ops[-1] eq '{' && $str eq '}' && (pop @ops && (next PARSE))
$ops[-1] eq "{" and $str eq "}"
pop @ops and next PARSE
MC/DC0%0/3
$ops[-1] eq '{' && $str eq '}' && (pop @ops && (next PARSE))
$ops[-1] eq "{"
$str eq "}"
pop @ops
Truth table0%0/4
A and B && C
A= $ops[-1] eq "{"B= $str eq "}"C= pop @ops
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $calcu->($str); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | push @ops, $str; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | debug("ops:", \@ops); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | debug("values:", \@values); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | warn "Range expression error!" and return if scalar @ops > 1 || scalar @values > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/8
(scalar @ops > 1 || scalar @values > 1) && (warn('Range expression error!') && (return))
scalar @ops > 1 or scalar @values > 1
warn "Range expression error!" and return
MC/DC0%0/3
(scalar @ops > 1 || scalar @values > 1) && (warn('Range expression error!') && (return))
scalar @ops > 1
scalar @values > 1
warn "Range expression error!"
Truth table0%0/5
A or B && C
A= scalar @ops > 1B= scalar @values > 1C= warn "Range expression error!"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my $ret = $values[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | return ref $ret ? $ret : Zed::Range::Set->new($ret); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||