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   51309 use warnings;
  2         5  
  2         59  
4 2     2   11 use strict;
  2         4  
  2         150  
5              
6             our $VERSION = '0.01';
7              
8 2         24 use Sub::Exporter -setup => {
9             exports => [
10             qw(
11             class_case
12             dispatch
13             )
14             ],
15 2     2   14599 };
  2         31497  
16              
17 2     2   748 use Scalar::Util qw(blessed);
  2         5  
  2         564  
18              
19             sub class_case {
20 2     2 1 62 my @prototable = @_;
21             sub {
22 16     16   77 my ($x) = @_;
23 16         62 my $blessed = blessed $x;
24 16         36 my $ref = ref $x;
25 16         23 my $DOES;
26 16         62 my @table = @prototable;
27 16         71 while (my ($key, $value) = splice @table, 0, 2) {
28 62 100 100     994 return $value if
    100          
    100          
    50          
    100          
29             !defined $key ? !defined $x :
30             $key eq '*' ? 1 :
31             $key eq ':str' ? !$ref :
32             $key eq $ref ? 1 :
33             $blessed && ($DOES ||= $x->can('DOES') || 'isa', $x->$DOES($key))
34             ;
35             }
36             ()
37 2         10 }
38 2         15 }
39              
40             sub dispatch {
41 1     1 1 4 my $chk = &class_case;
42 12   50 12   21254 sub { ($chk->($_[0]) || return)->($_[0]) }
43 1         5 }
44              
45             'ok'
46              
47             __END__