| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
########################################### |
|
2
|
|
|
|
|
|
|
# A Meta-Objects Protocol for Perl5 # |
|
3
|
|
|
|
|
|
|
########################################### |
|
4
|
|
|
|
|
|
|
# (c) Rodolphe Ortalo, 1997-1998 |
|
5
|
|
|
|
|
|
|
#Included in the ESOPE project of LAAS-CNRS |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#$Id: MOP.pm,v 1.3 1999/02/10 15:16:41 ortalo Exp $ |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package MOP::MOP; |
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
32
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
61
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$VERSION = '1.00'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
860
|
use Filter::Util::Call; |
|
|
1
|
|
|
|
|
1310
|
|
|
|
1
|
|
|
|
|
567
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
####################################### |
|
19
|
|
|
|
|
|
|
# FILTER TRANSFORMATION FUNCTION # |
|
20
|
|
|
|
|
|
|
# Warning: black magic occuring here! # |
|
21
|
|
|
|
|
|
|
####################################### |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# At import time, the importer SOURCE CODE is |
|
24
|
|
|
|
|
|
|
# MODIFIED to enable redirection of the reflective |
|
25
|
|
|
|
|
|
|
# methods. |
|
26
|
|
|
|
|
|
|
sub import |
|
27
|
|
|
|
|
|
|
{ |
|
28
|
4
|
|
|
4
|
|
7
|
my $type = shift; |
|
29
|
4
|
100
|
|
|
|
33
|
if (@_) { |
|
30
|
|
|
|
|
|
|
# We have some methods to make reflective |
|
31
|
2
|
|
|
|
|
6
|
my $pattern = join('|', @_); |
|
32
|
|
|
|
|
|
|
filter_add( |
|
33
|
|
|
|
|
|
|
sub { |
|
34
|
431
|
|
|
431
|
|
543
|
my ($status); |
|
35
|
431
|
100
|
|
|
|
5474
|
my $match = s/sub\s+($pattern)/sub $1_Refl/ |
|
36
|
|
|
|
|
|
|
if ($status = filter_read()) > 0; |
|
37
|
431
|
100
|
|
|
|
998
|
if ($match) { |
|
38
|
7
|
|
|
|
|
10
|
my $sub = $1; |
|
39
|
|
|
|
|
|
|
# Adds the stub now |
|
40
|
7
|
|
|
|
|
24
|
$_ = "sub $sub {" |
|
41
|
|
|
|
|
|
|
." unshift \@_,'".$sub."_Refl';" |
|
42
|
|
|
|
|
|
|
." MOP::MOP::REFLECT(\@_); }\n" |
|
43
|
|
|
|
|
|
|
.$_; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
431
|
|
|
|
|
9232
|
$status; |
|
46
|
2
|
|
|
|
|
13
|
} ); |
|
47
|
|
|
|
|
|
|
} else { |
|
48
|
|
|
|
|
|
|
# We have not been given anything: the user probably |
|
49
|
|
|
|
|
|
|
# simply wants to access to MOP functions. |
|
50
|
|
|
|
|
|
|
# So we don't install any filter. |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
########################## |
|
55
|
|
|
|
|
|
|
# LOCAL CONSTANT SYMBOLS # |
|
56
|
|
|
|
|
|
|
########################## |
|
57
|
|
|
|
|
|
|
my $DEBUG = 0; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
################### |
|
60
|
|
|
|
|
|
|
# LOCAL VARIABLES # |
|
61
|
|
|
|
|
|
|
################### |
|
62
|
|
|
|
|
|
|
# Base-Object -> Meta-Object registration procedures |
|
63
|
|
|
|
|
|
|
my %Meta_Thingy = (); |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
############################## |
|
66
|
|
|
|
|
|
|
# FURNISHED FUNCTIONS # |
|
67
|
|
|
|
|
|
|
############################## |
|
68
|
|
|
|
|
|
|
sub register_meta ($$) { |
|
69
|
8
|
|
|
8
|
1
|
13
|
my $meta = shift; |
|
70
|
8
|
|
|
|
|
9
|
my $base = shift; |
|
71
|
8
|
50
|
|
|
|
15
|
print STDERR "Associating Meta:$meta to Base:$base\n" if $DEBUG; |
|
72
|
8
|
|
|
|
|
19
|
$Meta_Thingy{$base} = $meta; |
|
73
|
8
|
|
|
|
|
17
|
return; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
sub find_meta ($) { |
|
76
|
3
|
|
|
3
|
1
|
4
|
my $base = shift; |
|
77
|
3
|
50
|
|
|
|
9
|
print STDERR "Looking for Meta of Base:$base\n" if $DEBUG; |
|
78
|
3
|
|
|
|
|
9
|
return $Meta_Thingy{$base}; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub REFLECT { |
|
82
|
45
|
|
|
45
|
0
|
56
|
my $b_reflect = $_[0]; # 'b' for 'base' |
|
83
|
45
|
|
|
|
|
42
|
my $b_that = $_[1]; |
|
84
|
45
|
|
|
|
|
82
|
my $m_that = $Meta_Thingy{$b_that}; # 'm' for 'meta' |
|
85
|
45
|
100
|
|
|
|
67
|
if ($m_that) { |
|
86
|
38
|
50
|
|
|
|
68
|
print STDERR "Meta-thingy of $b_that ($b_reflect) is $m_that\n" |
|
87
|
|
|
|
|
|
|
if $DEBUG; |
|
88
|
38
|
|
|
|
|
91
|
$m_that->meta_method_call(@_); |
|
89
|
|
|
|
|
|
|
} else { |
|
90
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; # We need to call a sub by its name |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
81
|
|
|
91
|
7
|
50
|
|
|
|
16
|
print STDERR "REFLECTed $b_that ($b_reflect) has no meta-thingy |
|
92
|
|
|
|
|
|
|
- normal call\n" if $DEBUG; |
|
93
|
7
|
|
|
|
|
25
|
shift; # Get rid of method name |
|
94
|
7
|
|
|
|
|
33
|
shift; # and of thing ref. |
|
95
|
7
|
|
|
|
|
28
|
$b_that->$b_reflect(@_); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
#################################### |
|
100
|
|
|
|
|
|
|
1; # Final true ending (Perl module) |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |