line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MRP::Interface; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
246
|
|
4
|
1
|
|
|
1
|
|
8
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
81
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
7
|
use MRP::Introspection; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use vars qw($AUTOLOAD %interfaces %implementers $VERSION); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
754
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = 1.0; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub AUTOLOAD { |
13
|
0
|
|
|
0
|
|
|
my ($name) = $AUTOLOAD =~ /([^:]+)$/; |
14
|
0
|
|
|
|
|
|
my $int = $interfaces{$name}; |
15
|
0
|
0
|
|
|
|
|
$int or confess "Use of undefined interface: $name"; |
16
|
0
|
|
|
|
|
|
return $int; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub create { |
20
|
0
|
|
|
0
|
1
|
|
my $thingy = shift; |
21
|
0
|
|
|
|
|
|
my %interface = @_; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
my ($name, $definition); |
24
|
0
|
|
|
|
|
|
while (($name, $definition) = each %interface) { |
25
|
0
|
0
|
|
|
|
|
if(exists $interfaces{$name}) { |
26
|
0
|
|
|
|
|
|
confess "interface $name has already been defined\n"; |
27
|
|
|
|
|
|
|
} else { |
28
|
0
|
|
|
|
|
|
my $description = $definition->{''}; delete $definition->{''}; |
|
0
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
$interfaces{$name} = bless {name=>$name, |
30
|
|
|
|
|
|
|
definition=>$definition, |
31
|
|
|
|
|
|
|
implementors=>{}, |
32
|
|
|
|
|
|
|
description=>$description, |
33
|
|
|
|
|
|
|
}, $thingy; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub implementedBy { |
39
|
0
|
|
|
0
|
1
|
|
my ($interface,$thingy) = (shift,shift); |
40
|
0
|
0
|
|
|
|
|
if(my $package = ref($thingy)) { |
41
|
0
|
|
|
|
|
|
foreach (keys %{$interface->{implementors}}) { |
|
0
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
return 1 if $thingy->isa($_); |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
|
return; |
45
|
|
|
|
|
|
|
} else { |
46
|
0
|
0
|
|
|
|
|
return if(not $thingy); |
47
|
0
|
0
|
|
|
|
|
my @errors = map { $thingy->can($_) |
|
0
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
? () : "$_"; |
49
|
0
|
|
|
|
|
|
} keys %{$interface->{definition}}; |
50
|
0
|
0
|
|
|
|
|
if(@errors) { |
51
|
0
|
|
|
|
|
|
confess |
52
|
|
|
|
|
|
|
"$thingy does not implement interface ", |
53
|
|
|
|
|
|
|
$interface->{name}, |
54
|
|
|
|
|
|
|
". The following ", scalar(@errors), " functions must be defined:\n ", |
55
|
0
|
|
|
|
|
|
join("", map { $_."\n\t".$interface->{definition}->{$_}."\n" } @errors), |
56
|
|
|
|
|
|
|
"\n"; |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
|
$interface->{implementors}->{$thingy} = 1; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub name { |
63
|
0
|
|
|
0
|
1
|
|
my $interface = shift; |
64
|
0
|
|
|
|
|
|
return $interface->{name}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub functions { |
68
|
0
|
|
|
0
|
1
|
|
my $interface = shift; |
69
|
0
|
|
|
|
|
|
return keys %{$interface->{definition}}; |
|
0
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
0
|
|
|
sub DESTROY {} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$VERSION; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |