| 1 | package Zed::Range::Set; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | use overload | ||||||||||
| 4 | 1 | '""' => \&dump, | |||||||||
| 5 | '*' => \&descartes, | ||||||||||
| 6 | '&' => \&intersection, | ||||||||||
| 7 | '-' => \&diff, | ||||||||||
| 8 | 1 | ▶ | '+' => \&union; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | sub new | ||||||||||
| 11 | { | ||||||||||
| 12 | 0 | ▶ | my( $class, @vars) = @_; | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 13 | 0 | bless [@vars], $class; | |||||||||
| 14 | } | ||||||||||
| 15 | 0 | ▶ | sub _list{ map{ ref $_ ? $_ : [$_] }@_ } | ||||||||
|
Subroutine
_list: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||
| 16 | |||||||||||
| 17 | sub add | ||||||||||
| 18 | { | ||||||||||
| 19 | 0 | ▶ | my( $this, @vars ) = @_; | ||||||||
|
Subroutine
add: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 20 | 0 | ▶ | push @$this, ref $_ ? $_->dump : $_ for @vars; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | sub union | ||||||||||
| 24 | { | ||||||||||
| 25 | 0 | ▶ | my( $left, $right ) = _list(@_); | ||||||||
|
Subroutine
union: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 26 | 0 | Zed::Range::Set->new(@$left, @$right); | |||||||||
| 27 | } | ||||||||||
| 28 | sub descartes | ||||||||||
| 29 | { | ||||||||||
| 30 | 0 | ▶ | my @values = _list( splice @_, 0, 2 ); | ||||||||
|
Subroutine
descartes: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 31 | 0 | ▶ | my( $left, $right ) = $_[0] ? reverse @values : @values; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | |||||||||||
| 33 | Zed::Range::Set->new( | ||||||||||
| 34 | 0 | map{ my $front = $_; map{ $front.$_ }@$right }@$left | |||||||||
| 35 | ); | ||||||||||
| 36 | } | ||||||||||
| 37 | sub intersection | ||||||||||
| 38 | { | ||||||||||
| 39 | 0 | ▶ | my( $left, $right ) = @_; | ||||||||
|
Subroutine
intersection: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | $right = qr/$right/ unless ref $right; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 0 | ▶ | my $cut = ref $right eq "Regexp" ? sub{$_ =~ $right} : sub{my $t = shift; grep { $t =~ /$_/ } @$right}; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 43 | |||||||||||
| 44 | 0 | Zed::Range::Set->new( grep{ $cut->($_) }@$left ); | |||||||||
| 45 | } | ||||||||||
| 46 | sub diff | ||||||||||
| 47 | { | ||||||||||
| 48 | 0 | ▶ | my( $left, $right ) = @_; | ||||||||
|
Subroutine
diff: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 49 | 0 | ▶ | $right = qr/$right/ unless ref $right; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | ▶ | my $cut = ref $right eq "Regexp" ? sub{$_ !~ $right} : sub{my $t = shift; !grep { $t =~ /$_/ } @$right}; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 51 | 0 | Zed::Range::Set->new( grep{ $cut->($_) }@$left ); | |||||||||
| 52 | } | ||||||||||
| 53 | sub dump | ||||||||||
| 54 | { | ||||||||||
| 55 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
dump: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 56 | 0 | ▶ | wantarray ? @$self : $self; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | |||||||||||
| 60 | 1 | 1; | |||||||||
| 61 | |||||||||||
| 62 | __END__ | ||||||||||