| 1 | package Acme::Partitioner; | ||||||||||||||||||||
| 2 | 4 | ▶ | use 5.012000; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 4 | require Exporter; | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 4 | our @ISA = qw(Exporter); | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 4 | our %EXPORT_TAGS = ( 'all' => [ qw( | |||||||||||||||||||
| 11 | ) ] ); | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 4 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 4 | our @EXPORT = qw( | |||||||||||||||||||
| 16 | ); | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 4 | our $VERSION = '0.01'; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 0 | ▶ | sub using { | ||||||||||||||||||
|
Subroutine
using: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 21 | 0 | my ($class, @list) = @_; | |||||||||||||||||||
| 22 | bless { | ||||||||||||||||||||
| 23 | 0 | by_string => { map { $_ => 0 } @list }, | |||||||||||||||||||
| 24 | sublists => [\@list], | ||||||||||||||||||||
| 25 | }, $class; | ||||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 0 | ▶ | sub once_by { | ||||||||||||||||||
|
Subroutine
once_by: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 29 | 0 | my ($self, $sub) = @_; | |||||||||||||||||||
| 30 | 0 | Acme::Partitioner::Actor::_new(undef, "once", $sub, $self); | |||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 0 | ▶ | sub partition_of { | ||||||||||||||||||
|
Subroutine
partition_of: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 34 | 0 | my ($self, $item) = @_; | |||||||||||||||||||
| 35 | 0 | $self->{by_string}{$item}; | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | ▶ | sub items_in { | ||||||||||||||||||
|
Subroutine
items_in: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 39 | 0 | my ($self, $partition) = @_; | |||||||||||||||||||
| 40 | 0 | @{ $self->{sublists}[$partition] } | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 0 | ▶ | sub size { | ||||||||||||||||||
|
Subroutine
size: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 44 | 0 | my ($self) = @_; | |||||||||||||||||||
| 45 | 0 | scalar @{ $self->{sublists} } | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | ▶ | sub all_partitions { | ||||||||||||||||||
|
Subroutine
all_partitions: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 49 | 0 | my ($self) = @_; | |||||||||||||||||||
| 50 | 0 | map { [@$_] } @{ $self->{sublists} } | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | package Acme::Partitioner::Actor; | ||||||||||||||||||||
| 54 | 4 | ▶ | use 5.012000; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 55 | 4 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 56 | 4 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 0 | ▶ | sub _new { | ||||||||||||||||||
|
Subroutine
_new: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 59 | 0 | my ($old, $type, $sub, $partitioner) = @_; | |||||||||||||||||||
| 60 | 0 | ▶ | $partitioner //= $old->{partitioner}; | ||||||||||||||||||
|
Condition0%0/3
$partitioner //= $old->{"partitioner"}
MC/DC0%0/2
$partitioner //= $old->{"partitioner"}
$partitioner
$old->{"partitioner"}
Truth table0%0/3
A //= B
A= $partitionerB= $old->{"partitioner"}
| |||||||||||||||||||||
| 61 | bless { | ||||||||||||||||||||
| 62 | partitioner => $partitioner, | ||||||||||||||||||||
| 63 | subs => [ | ||||||||||||||||||||
| 64 | 0 | ▶ | ($old ? @{ $old->{subs} } : ()), | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | [$type, $sub], | ||||||||||||||||||||
| 66 | ], | ||||||||||||||||||||
| 67 | }, __PACKAGE__ | ||||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 0 | ▶ | sub once_by { | ||||||||||||||||||
|
Subroutine
once_by: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 71 | 0 | my ($self, $sub) = @_; | |||||||||||||||||||
| 72 | 0 | _new($self, "once", $sub); | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 0 | ▶ | sub then_by { | ||||||||||||||||||
|
Subroutine
then_by: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 76 | 0 | my ($self, $sub) = @_; | |||||||||||||||||||
| 77 | 0 | _new($self, "then", $sub); | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 0 | ▶ | sub refine { | ||||||||||||||||||
|
Subroutine
refine: not called CC=10 SCAR=47.0
| |||||||||||||||||||||
| 81 | 0 | my ($self) = @_; | |||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 0 | ▶ | unless (@{ $self->{subs} }) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | 0 | warn "Attempt to refine partitions without active refiners"; | |||||||||||||||||||
| 85 | 0 | return; | |||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | my $old_size = $self->{partitioner}->size(); | |||||||||||||||||||
| 89 | 0 | my $next_id = $old_size; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | ▶ | for (my $ix = 0; $ix < @{ $self->{subs} }; ++$ix) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | my @temp; | |||||||||||||||||||
| 94 | 0 | for my $sublist (@{ $self->{partitioner}{sublists} }) { | |||||||||||||||||||
| 95 | 0 | my %h; | |||||||||||||||||||
| 96 | 0 | for my $item (@{ $sublist }) { | |||||||||||||||||||
| 97 | 0 | local $_ = $item; | |||||||||||||||||||
| 98 | 0 | my $key = $self->{subs}[$ix][1]->($item); | |||||||||||||||||||
| 99 | 0 | push @{ $h{$key} }, $item; | |||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | 0 | push @temp, values %h; | |||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | ################################################################# | ||||||||||||||||||||
| 105 | # | ||||||||||||||||||||
| 106 | ################################################################# | ||||||||||||||||||||
| 107 | 0 | my %occupied; | |||||||||||||||||||
| 108 | my @new_list; | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 0 | ▶ | for (my $ix = 0; $ix < @temp; ++$ix) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 111 | 0 | my $first = $temp[$ix]->[0]; | |||||||||||||||||||
| 112 | 0 | ▶ | my $first_id = $self->{partitioner}->partition_of($first) // 0; | ||||||||||||||||||
|
Condition0%0/2
$self->{"partitioner"}->partition_of($first) // 0
MC/DC0%0/1
$self->{"partitioner"}->partition_of($first) // 0
$self->{"partitioner"}->partition_of($first)
Truth table0%0/2
A
A= $self->{"partitioner"}->partition_of($first)
| |||||||||||||||||||||
| 113 | 0 | ▶ | if (not $occupied{ $first_id }++) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 114 | 0 | $new_list[ $first_id ] = $temp[$ix]; | |||||||||||||||||||
| 115 | 0 | next; | |||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | 0 | my $new_id = $next_id++; | |||||||||||||||||||
| 118 | 0 | $new_list[ $new_id ] = $temp[$ix]; | |||||||||||||||||||
| 119 | $self->{partitioner}{by_string}{$_} = $new_id | ||||||||||||||||||||
| 120 | 0 | for @{ $temp[$ix] }; | |||||||||||||||||||
| 121 | } | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 0 | $self->{partitioner}{sublists} = \@new_list; | |||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | ################################################################# | ||||||||||||||||||||
| 126 | # | ||||||||||||||||||||
| 127 | ################################################################# | ||||||||||||||||||||
| 128 | 0 | splice @{ $self->{ subs } }, $ix--, 1 | |||||||||||||||||||
| 129 | 0 | ▶ | if $self->{subs}[$ix]->[0] eq 'once'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 130 | } | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 0 | return $self->{partitioner}->size() != $old_size; | |||||||||||||||||||
| 133 | } | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | 4 | 1; | |||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | __END__ | ||||||||||||||||||||