File Coverage

blib/lib/interface.pm
Criterion Covered Total %
statement 8 29 27.5
branch 0 12 0.0
condition 0 3 0.0
subroutine 3 3 100.0
pod n/a
total 11 47 23.4


line stmt bran cond sub pod time code
1             package interface;
2              
3             #
4             # given the name of package that specifies an interface, verify that we do
5             # indeed implement everything required by that interface.
6             #
7              
8 1     1   26809 use 5.006;
  1         4  
  1         344  
9              
10             # we just aren't the kind of module you'd bring home to meet the parents
11              
12             # use strict;
13             # use warnings;
14              
15             our $VERSION = '0.03';
16              
17             # per-package locks to avoid reentry when we make them finish loading
18              
19             my @checkqueue;
20              
21             sub import {
22              
23 1     1   8 my $callerpackage = caller;
24              
25 1         6 shift; my @interfaces = @_;
  1         2  
26              
27 1         53 foreach my $i (@interfaces) {
28              
29 0           push @checkqueue, [$callerpackage, $i];
30              
31             }
32              
33             }
34              
35              
36             sub CHECK {
37              
38 1     1   7434 for my $thingie (@checkqueue) {
39              
40 0         0 my $callerpackage = $thingie->[0];
41 0         0 my $implements = $thingie->[1];
42              
43 0         0 my $gripes;
44             my $newgripes;
45            
46 0         0 do {
47 0         0 eval "package $callerpackage; use $implements;";
48 0 0       0 die "$callerpackage: interface $implements could not be loaded: $@" if($@);
49             };
50            
51 0         0 foreach my $i (grep { defined &{$implements.'::'.$_} } keys %{$implements.'::'}) {
  0         0  
  0         0  
  0         0  
52            
53             # since they implement all required methods, nothing in $i will ever be called.
54             # however, we need this so that $callerpackage->isa($i) is true.
55            
56             # warn "can: implements: $implements method: $i callerpackage: $callerpackage result: " . $callerpackage->can($i);
57              
58             # unless(defined &{$callerpackage.'::'.$i}) {
59 0 0       0 unless(UNIVERSAL::can($callerpackage, $i)) {
60 0 0       0 $gripes .= ', ' if $gripes;
61 0         0 $gripes .= "$i from $implements";
62             }
63            
64 0 0 0     0 $gripes .= ", and " if $gripes and $newgripes;
65 0 0       0 $gripes .= $newgripes if $newgripes;
66 0         0 $newgripes = undef;
67              
68             }
69            
70 0 0       0 if($gripes) {
71            
72 0         0 die "$callerpackage is missing methods: $gripes";
73            
74             }
75            
76 0         0 push @{$callerpackage.'::ISA'}, $implements;
  0         0  
77              
78             }
79            
80             }
81              
82             1;
83              
84             __END__