« blib/lib/App/RecordStream/Clumper/Window.pm
↑ Summary
blib/lib/App/RecordStream/Aggregator/MapReduce.pm »
| 1 | package App::RecordStream::Deaggregator::Split; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 2 | ▶ | use App::RecordStream::Deaggregator::Field; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 2 | ▶ | use App::RecordStream::Deaggregator; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 2 | ▶ | use App::RecordStream::DomainLanguage::Registry; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 2 | ▶ | use base 'App::RecordStream::Deaggregator::Field'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | sub new | ||||||||||||||
| 13 | { | ||||||||||||||
| 14 | 4 | ▶ | my $class = shift; | ||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 15 | 4 | my $old_field = shift; | |||||||||||||
| 16 | 4 | my $delim = shift; | |||||||||||||
| 17 | 4 | my $new_field = shift; | |||||||||||||
| 18 | |||||||||||||||
| 19 | 4 | my $this = $class->SUPER::new($old_field); | |||||||||||||
| 20 | |||||||||||||||
| 21 | 4 | $this->{'delim'} = make_delim($delim); | |||||||||||||
| 22 | 4 | $this->{'new_field'} = $new_field; | |||||||||||||
| 23 | |||||||||||||||
| 24 | 4 | return $this; | |||||||||||||
| 25 | } | ||||||||||||||
| 26 | |||||||||||||||
| 27 | sub new_from_valuation | ||||||||||||||
| 28 | { | ||||||||||||||
| 29 | 0 | ▶ | my $class = shift; | ||||||||||||
|
Subroutine
new_from_valuation: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 30 | 0 | my $valuation = shift; | |||||||||||||
| 31 | 0 | my $delim = shift; | |||||||||||||
| 32 | 0 | my $new_field = shift; | |||||||||||||
| 33 | |||||||||||||||
| 34 | 0 | my $this = $class->SUPER::new_from_valuation($valuation); | |||||||||||||
| 35 | |||||||||||||||
| 36 | 0 | $this->{'delim'} = $delim; # not make_delim, let the domain language sort it out! | |||||||||||||
| 37 | 0 | $this->{'new_field'} = $new_field; | |||||||||||||
| 38 | |||||||||||||||
| 39 | 0 | return $this; | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | |||||||||||||||
| 42 | sub make_delim | ||||||||||||||
| 43 | { | ||||||||||||||
| 44 | 4 | ▶ | my $delim = shift; | ||||||||||||
|
Subroutine
make_delim: called CC=3 SCAR=13.3
Pod
undocumented
| |||||||||||||||
| 45 | |||||||||||||||
| 46 | 4 | ▶ | if($delim =~ /^\/(.*)\/$/) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 47 | { | ||||||||||||||
| 48 | 0 | return qr/$1/; | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | elsif($delim =~ /^\/(.*)\/i$/) | ||||||||||||||
| 51 | { | ||||||||||||||
| 52 | 0 | return qr/$1/i; | |||||||||||||
| 53 | } | ||||||||||||||
| 54 | else | ||||||||||||||
| 55 | { | ||||||||||||||
| 56 | 4 | return qr/\Q$delim\E/; | |||||||||||||
| 57 | } | ||||||||||||||
| 58 | } | ||||||||||||||
| 59 | |||||||||||||||
| 60 | sub deaggregate_field | ||||||||||||||
| 61 | { | ||||||||||||||
| 62 | 14 | ▶ | my $this = shift; | ||||||||||||
|
Subroutine
deaggregate_field: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 63 | 14 | my $values = shift; | |||||||||||||
| 64 | |||||||||||||||
| 65 | 14 | my @ret; | |||||||||||||
| 66 | |||||||||||||||
| 67 | 14 | for my $value (split($this->{'delim'}, $values, -1)) | |||||||||||||
| 68 | { | ||||||||||||||
| 69 | 32 | push @ret, {$this->{'new_field'} => $value}; | |||||||||||||
| 70 | } | ||||||||||||||
| 71 | |||||||||||||||
| 72 | 14 | return \@ret; | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | |||||||||||||||
| 75 | sub long_usage | ||||||||||||||
| 76 | { | ||||||||||||||
| 77 | 0 | ▶ | return <<EOF; | ||||||||||||
|
Subroutine
long_usage: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 78 | Usage: split,<old field>,<delimiter>,<new field> | ||||||||||||||
| 79 | Split the old field to create a new one. | ||||||||||||||
| 80 | EOF | ||||||||||||||
| 81 | } | ||||||||||||||
| 82 | |||||||||||||||
| 83 | sub short_usage | ||||||||||||||
| 84 | { | ||||||||||||||
| 85 | 1 | ▶ | return "split the provided field"; | ||||||||||||
|
Subroutine
short_usage: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 86 | } | ||||||||||||||
| 87 | |||||||||||||||
| 88 | sub argct | ||||||||||||||
| 89 | { | ||||||||||||||
| 90 | 4 | ▶ | return 3; | ||||||||||||
|
Subroutine
argct: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 91 | } | ||||||||||||||
| 92 | |||||||||||||||
| 93 | 2 | App::RecordStream::Deaggregator->register_implementation('split', __PACKAGE__); | |||||||||||||
| 94 | |||||||||||||||
| 95 | 2 | App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'split', 'VALUATION', 'SCALAR', 'SCALAR'); | |||||||||||||
| 96 | |||||||||||||||
| 97 | 2 | 1; | |||||||||||||