File Coverage: t/04-return-values.t

# File Coverage

File: | t/04-return-values.t
Coverage: | 63.6%

line | stmt | bran | cond | sub | pod | time | code
--- | --- | --- | --- | --- | --- | --- | ---
1 | 1 1 1 |  |  | 1 |  | 3176 1 25 | use strict;
2 | 1 1 1 |  |  | 1 |  | 3 1 32 | use warnings;
3 | 1 1 1 |  |  | 1 |  | 233 1 70 | use Dispatch::Fu;
4 | 1 1 1 |  |  | 1 |  | 390 94310 6 | use Test::More tests => 3;
5 |
6 | 1 |  |  |  |  | 69257 | my $INPUT = [qw/1 2 3 4 5/];
7 |
8 |  |  |  |  |  |  | my ($val0, $val1, $val2) = dispatch {
9 | 1 |  |  | 1 |  | 1 | my $input_ref = shift; # <~ input reference
10 | 1 | 50 |  |  |  | 8 | return ( scalar @$input_ref > 5 ) # <~ return a string that must be
11 |  |  |  |  |  |  | ? q{case5} # defined below using the 'on'
12 |  |  |  |  |  |  | : sprintf qq{case%d}, scalar @$input_ref; # keyword, this i
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 |  | 12 1 4 | on case5 => sub { my $INPUT = shift; return qw/val0 val1 val2/ }; # <~ if dispatch returns a LIST
20 |
21 |
22 | 1 |  |  |  |  | 10 | is $val0, q{val0}, q{multi return val0 worked as expected};
23 | 1 |  |  |  |  | 401 | is $val1, q{val1}, q{multi return val1 worked as expected};
24 | 1 |  |  |  |  | 357 | is $val2, q{val2}, q{multi return val2 worked as expected};