File Coverage: t/05-xshift_and_deref.t

# File Coverage

File: | t/05-xshift_and_deref.t
Coverage: | 55.6%

line | stmt | bran | cond | sub | pod | time | code
--- | --- | --- | --- | --- | --- | --- | ---
1 | 1 1 1 |  |  | 1 |  | 4304 3 36 | use strict;
2 | 1 1 1 |  |  | 1 |  | 6 1 48 | use warnings;
3 | 1 1 1 |  |  | 1 |  | 386 2 91 | use Dispatch::Fu;
4 | 1 1 1 |  |  | 1 |  | 542 120112 10 | use Test::More tests => 6;
5 |
6 | 1 |  |  |  |  | 66644 | my $INPUT = [qw/1 2 3 4 5/];
7 |
8 |  |  |  |  |  |  | my ($val0, $val1, $val2) = dispatch {
9 | 1 |  |  | 1 |  | 2 | my @input_arr = xshift_and_deref @_; # <~ NOTE: derefs $_[0] into @input_arr
10 | 1 | 50 |  |  |  | 6 | return ( scalar @input_arr > 5 ) # <~ return a string that must be
11 |  |  |  |  |  |  | ? q{case5} # defined below using the 'on' keyword
12 |  |  |  |  |  |  | : sprintf qq{case%d}, scalar @input_arr;
13 |  |  |  |  |  |  | } $INPUT, # <~ input reference, SCALAR passed to dispatch BLOCK
14 | 0 0 |  |  | 0 |  | 0 0 | on case0 => sub { my $INPUT = shift; return qq{case 0}}, # <~ if dispatch returns 'case0', run this CODE
15 | 0 0 |  |  | 0 |  | 0 0 | on case1 => sub { my $INPUT = shift; return qq{case 1}}, # <~ if dispatch returns 'case1', run this CODE
16 | 0 0 |  |  | 0 |  | 0 0 | on case2 => sub { my $INPUT = shift; return qq{case 2}}, # ... ... ... ... ... ... ...
17 | 0 0 |  |  | 0 |  | 0 0 | on case3 => sub { my $INPUT = shift; return qq{case 3}}, # ... ... ... ... ... ... ... ...
18 | 0 0 |  |  | 0 |  | 0 0 | on case4 => sub { my $INPUT = shift; return qq{case 4}}, # ... ... ... ... ... ... ...
19 | 1 1 1 |  |  | 1 |  | 11 1 3 | on case5 => sub { my $INPUT = shift; return qw/val0 val1 val2/ }; # <~ if dispatch returns a LIST
20 |
21 |
22 | 1 |  |  |  |  | 7 | is $val0, q{val0}, q{multi return val0 worked as expected};
23 | 1 |  |  |  |  | 243 | is $val1, q{val1}, q{multi return val1 worked as expected};
24 | 1 |  |  |  |  | 207 | is $val2, q{val2}, q{multi return val2 worked as expected};
25 |
26 | 1 |  |  |  |  | 204 | $INPUT = { 1 => q{foo}, 2 => q{bar}, 3 => q{baz}, 4 => q{herp}, 5 => q{derp} };
27 |
28 |  |  |  |  |  |  | ($val0, $val1, $val2) = dispatch {
29 | 1 |  |  | 1 |  | 1 | my %input_hash = xshift_and_deref @_; # <~ NOTE: derefs $_[0] into %input_hash
30 | 1 | 50 |  |  |  | 6 | return ( scalar keys %input_hash > 5 ) # <~ return a string that must be
31 |  |  |  |  |  |  | ? q{case5} # defined below using the 'on' keyword
32 |  |  |  |  |  |  | : sprintf qq{case%d}, scalar keys %input_hash;
33 |  |  |  |  |  |  | } $INPUT, # <~ input reference, SCALAR passed to dispatch BLOCK
34 | 0 0 |  |  | 0 |  | 0 0 | on case0 => sub { my $INPUT = shift; return qq{case 0}}, # <~ if dispatch returns 'case0', run this CODE
35 | 0 0 |  |  | 0 |  | 0 0 | on case1 => sub { my $INPUT = shift; return qq{case 1}}, # <~ if dispatch returns 'case1', run this CODE
36 | 0 0 |  |  | 0 |  | 0 0 | on case2 => sub { my $INPUT = shift; return qq{case 2}}, # ... ... ... ... ... ... ...
37 | 0 0 |  |  | 0 |  | 0 0 | on case3 => sub { my $INPUT = shift; return qq{case 3}}, # ... ... ... ... ... ... ... ...
38 | 0 0 |  |  | 0 |  | 0 0 | on case4 => sub { my $INPUT = shift; return qq{case 4}}, # ... ... ... ... ... ... ...
39 | 1 1 1 |  |  | 1 |  | 10 1 2 | on case5 => sub { my $INPUT = shift; return qw/val0 val1 val2/ }; # <~ if dispatch returns a LIST
40 |
41 |
42 | 1 |  |  |  |  | 7 | is $val0, q{val0}, q{multi return val0 worked as expected};
43 | 1 |  |  |  |  | 202 | is $val1, q{val1}, q{multi return val1 worked as expected};
44 | 1 |  |  |  |  | 202 | is $val2, q{val2}, q{multi return val2 worked as expected};