| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
2
|
|
|
|
|
|
|
# $Id: ExportList.pm,v 1.1 2003/11/29 14:35:24 nothingmuch Exp $ |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Object::Meta::Plugin::ExportList; # an object representing the skin of a plugin - what can be plugged and unseamed at the top level. |
|
5
|
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
19
|
use strict; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
105
|
|
|
7
|
4
|
|
|
4
|
|
15
|
use warnings; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
1753
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# this is a simple string based Object::Meta::Plugin::Export list. That is, all the methods are strings, and not code refs, |
|
10
|
|
|
|
|
|
|
# which gives a somewhat more controlled environment. |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# you could laxen these limits by writing your own ExportList, which will use code refs, and thus allow a plugin to nibble methods from other classes without base classing. |
|
13
|
|
|
|
|
|
|
# you'd also have to subclass Object::Meta::Plugin::Host to handle coderefs. Perhaps a dualvalue system could be useful. |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = 0.01; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
|
18
|
31
|
|
|
31
|
1
|
45
|
my $pkg = shift; |
|
19
|
31
|
|
|
|
|
35
|
my $plugin = shift; |
|
20
|
|
|
|
|
|
|
|
|
21
|
31
|
|
|
|
|
48
|
my @methods = @_; |
|
22
|
|
|
|
|
|
|
|
|
23
|
31
|
50
|
|
|
|
68
|
if (@_){ |
|
24
|
0
|
|
|
|
|
0
|
my %list = map { $_, undef } $plugin->exports(); # used to cross out what's not exported |
|
|
0
|
|
|
|
|
0
|
|
|
25
|
0
|
|
|
|
|
0
|
bless [ $plugin, [ grep { exists $list{$_} } @methods ] ], $pkg; # filter the method list to be only what works |
|
|
0
|
|
|
|
|
0
|
|
|
26
|
|
|
|
|
|
|
} else { |
|
27
|
31
|
|
|
|
|
135
|
bless [ $plugin, [ $plugin->exports() ] ], $pkg; # everythin unless otherwise stated |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub plugin { |
|
32
|
202
|
|
|
202
|
1
|
254
|
my $self = shift; |
|
33
|
202
|
|
|
|
|
918
|
$self->[0]; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub exists { # $$$ |
|
37
|
23
|
|
|
23
|
1
|
233
|
my $self = shift; |
|
38
|
|
|
|
|
|
|
|
|
39
|
23
|
50
|
|
|
|
56
|
if (wantarray){ # return a grepped list |
|
40
|
0
|
|
|
|
|
0
|
my @methods = @_; |
|
41
|
|
|
|
|
|
|
} else { # return a true or false |
|
42
|
23
|
|
|
|
|
81
|
my $method = shift; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub list { # list all under plugin |
|
47
|
31
|
|
|
31
|
1
|
38
|
my $self = shift; |
|
48
|
|
|
|
|
|
|
|
|
49
|
31
|
|
|
|
|
32
|
return @{ $self->[1] }; |
|
|
31
|
|
|
|
|
114
|
|
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub merge { # or another exoprt list into this one |
|
53
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
54
|
0
|
|
|
|
|
|
my $x = shift; |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my %uniq; |
|
57
|
0
|
|
|
|
|
|
@{ $self->[1] } = grep { not $uniq{$_}++ } @{ $self->[1] }, $x->list(); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$self; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub unmerge { # and (not|complement) another export list into this one |
|
63
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
64
|
0
|
|
|
|
|
|
my $x = shift; |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my %seen = map { $_, undef } $x->list(); |
|
|
0
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
@{ $self->[1] } = grep { not exists $seen{$_} } @{ $self->[1] }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; # Keep your mother happy. |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |