File Coverage

blib/lib/Dispatch/Class.pm
Criterion Covered Total %
statement 25 25 100.0
branch 9 10 90.0
condition 4 5 80.0
subroutine 8 8 100.0
pod 2 2 100.0
total 48 50 96.0


line stmt bran cond sub pod time code
1             package Dispatch::Class;
2              
3 2     2   187094 use warnings;
  2         4  
  2         146  
4 2     2   15 use strict;
  2         4  
  2         113  
5              
6             our $VERSION = '0.04';
7              
8 2     2   11 use Scalar::Util qw(blessed);
  2         3  
  2         115  
9              
10 2     2   1332 use parent 'Exporter::Tiny';
  2         13688  
  2         12  
11             our @EXPORT_OK = qw(
12             class_case
13             dispatch
14             );
15              
16             sub class_case {
17 2     2 1 153291 my @prototable = @_;
18             sub {
19 16     16   54 my ($x) = @_;
20 16         21 my $blessed = blessed $x;
21 16         25 my $ref = ref $x;
22 16         15 my $DOES;
23 16         51 my @table = @prototable;
24 16         42 while (my ($key, $value) = splice @table, 0, 2) {
25 62 100 100     406 return $value if
    100          
    100          
    50          
    100          
26             !defined $key ? !defined $x :
27             $key eq '*' ? 1 :
28             $key eq ':str' ? !$ref :
29             $key eq $ref ? 1 :
30             $blessed && ($DOES ||= $x->can('DOES') || 'isa', $x->$DOES($key))
31             ;
32             }
33             ()
34 2         21 }
35 2         9 }
36              
37             sub dispatch {
38 1     1 1 2 my $chk = &class_case;
39 12   50 12   5605 sub { ($chk->($_[0]) || return)->($_[0]) }
40 1         4 }
41              
42             'ok'
43              
44             __END__