File Coverage: t/01-example.t

# File Coverage

File: | t/01-example.t
Coverage: | 61.9%

line | stmt | bran | cond | sub | pod | time | code
--- | --- | --- | --- | --- | --- | --- | ---
1 | 1 1 1 |  |  | 1 |  | 4120 1 24 | use strict;
2 | 1 1 1 |  |  | 1 |  | 3 1 55 | use warnings;
3 | 1 1 1 |  |  | 1 |  | 339 3 92 | use Dispatch::Fu; # 'dispatch', 'cases', 'xdefault', and 'on' are exported by default, just for show here
4 | 1 1 1 |  |  | 1 |  | 569 106901 9 | use Test::More tests => 1;
5 |
6 | 1 |  |  |  |  | 91612 | my $INPUT = [qw/1 2 3 4 5/];
7 |
8 |  |  |  |  |  |  | my $results = dispatch { # <~ start of 'dispatch' construct
9 | 1 |  |  | 1 |  | 1 | my $input_ref = shift; # <~ input reference
10 | 1 | 50 |  |  |  | 7 | return ( scalar @$input_ref > 5 ) # <~ return a string that must be
11 |  |  |  |  |  |  | ? q{case5} # defined below using the 'on' keyword
12 |  |  |  |  |  |  | : sprintf qq{case%d}, scalar @$input_ref;
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 |  | 10 2 2 | on case5 => sub { my $INPUT = shift; return qq{case 5}}; # <~ if dispatch returns 'case5', run this CODE
20 |
21 | 1 |  |  |  |  | 9 | is $results, q{case 5}, q{POD example works};