« blib/lib/App/RecordStream/Aggregator/MapReduce.pm
↑ Summary
blib/lib/App/RecordStream/Test/Aggregator/ArrayHelper.pm »
| 1 | package App::RecordStream::Executor::Getopt; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 20 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 20 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | sub new { | ||||||||||||||
| 7 | 54 | ▶ | my $class = shift; | ||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 54 | my $this = { | |||||||||||||
| 10 | 'STRINGS' => [], | ||||||||||||||
| 11 | 'MODULES' => [], | ||||||||||||||
| 12 | }; | ||||||||||||||
| 13 | |||||||||||||||
| 14 | 54 | bless $this, $class; | |||||||||||||
| 15 | |||||||||||||||
| 16 | 54 | return $this; | |||||||||||||
| 17 | } | ||||||||||||||
| 18 | |||||||||||||||
| 19 | sub arguments { | ||||||||||||||
| 20 | 54 | ▶ | my $this = shift; | ||||||||||||
|
Subroutine
arguments: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 21 | |||||||||||||||
| 22 | return ( | ||||||||||||||
| 23 | 1 | ▶ | 'e=s' => sub { $this->push_string($_[1]); }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 24 | 1 | ▶ | 'E=s' => sub { $this->push_file($_[1]); }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 25 | 3 | ▶ | 'M=s' => sub { $this->push_module($_[1], 1); }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 26 | 2 | ▶ | 'm=s' => sub { $this->push_module($_[1], 0); }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 27 | 54 | ); | |||||||||||||
| 28 | } | ||||||||||||||
| 29 | |||||||||||||||
| 30 | sub get_strings { | ||||||||||||||
| 31 | 48 | ▶ | my $this = shift; | ||||||||||||
|
Subroutine
get_strings: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||
| 32 | 48 | my $args = shift; | |||||||||||||
| 33 | |||||||||||||||
| 34 | 48 | my $strings = $this->{'STRINGS'}; | |||||||||||||
| 35 | 48 | ▶ | if(!@$strings) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 36 | 46 | ▶ | if(!@$args) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | 0 | die "Missing expression.\n"; | |||||||||||||
| 38 | } | ||||||||||||||
| 39 | 46 | push @$strings, shift @$args; | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | |||||||||||||||
| 42 | # Use map to avoid the undesired comma operator behaviour if we're ever | ||||||||||||||
| 43 | # called in scalar context. return @{[ ..., ... ]} could also be used. | ||||||||||||||
| 44 | 48 | return map { @$_ } $this->{'MODULES'}, $strings; | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | |||||||||||||||
| 47 | sub get_string { | ||||||||||||||
| 48 | 48 | ▶ | my $this = shift; | ||||||||||||
|
Subroutine
get_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 49 | |||||||||||||||
| 50 | 48 | return join("", $this->get_strings(@_)); | |||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | sub push_string { | ||||||||||||||
| 54 | 1 | ▶ | my $this = shift; | ||||||||||||
|
Subroutine
push_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 55 | 1 | my $string = shift; | |||||||||||||
| 56 | |||||||||||||||
| 57 | 1 | push @{$this->{'STRINGS'}}, $string; | |||||||||||||
| 58 | } | ||||||||||||||
| 59 | |||||||||||||||
| 60 | sub push_file { | ||||||||||||||
| 61 | 1 | ▶ | my $this = shift; | ||||||||||||
|
Subroutine
push_file: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 62 | 1 | my $file = shift; | |||||||||||||
| 63 | |||||||||||||||
| 64 | 1 | my $string = $this->_slurp($file); | |||||||||||||
| 65 | |||||||||||||||
| 66 | 1 | push @{$this->{'STRINGS'}}, $string; | |||||||||||||
| 67 | } | ||||||||||||||
| 68 | |||||||||||||||
| 69 | sub _slurp { | ||||||||||||||
| 70 | 1 | ▶ | my $this = shift; | ||||||||||||
|
Subroutine
_slurp: called CC=2 SCAR=7.0
| |||||||||||||||
| 71 | 1 | my $file = shift; | |||||||||||||
| 72 | |||||||||||||||
| 73 | 1 | local $/; | |||||||||||||
| 74 | 1 | undef $/; | |||||||||||||
| 75 | |||||||||||||||
| 76 | 1 | ▶ | open (my $fh, '<', $file) or die "Could not open code snippet file: $file: $!"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 77 | 1 | my $code = <$fh>; | |||||||||||||
| 78 | 1 | close $fh; | |||||||||||||
| 79 | |||||||||||||||
| 80 | 1 | return $code; | |||||||||||||
| 81 | } | ||||||||||||||
| 82 | |||||||||||||||
| 83 | sub push_module { | ||||||||||||||
| 84 | 5 | ▶ | my $this = shift; | ||||||||||||
|
Subroutine
push_module: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||
| 85 | 5 | my ($module, $import) = split /=/, shift, 2; | |||||||||||||
| 86 | 5 | my $import_default = shift; | |||||||||||||
| 87 | 5 | my $statement; | |||||||||||||
| 88 | |||||||||||||||
| 89 | 5 | ▶ | if (defined $import) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 90 | # This syntax mimics the output of: | ||||||||||||||
| 91 | # perl -MO=Deparse -MList::Util=sum,max -e1 | ||||||||||||||
| 92 | 3 | $import =~ s/(?=[\\'])/\\/g; | |||||||||||||
| 93 | 3 | $statement = "use $module (split(/,/, '$import', 0));"; | |||||||||||||
| 94 | } elsif ($import_default) { | ||||||||||||||
| 95 | 1 | $statement = "use $module;"; | |||||||||||||
| 96 | } else { | ||||||||||||||
| 97 | 1 | $statement = "use $module ();"; | |||||||||||||
| 98 | } | ||||||||||||||
| 99 | |||||||||||||||
| 100 | 5 | push @{$this->{'MODULES'}}, $statement; | |||||||||||||
| 101 | } | ||||||||||||||
| 102 | |||||||||||||||
| 103 | 20 | 1; | |||||||||||||