line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ========================================== |
2
|
|
|
|
|
|
|
# Copyright (C) 2004 kyle dawkins |
3
|
|
|
|
|
|
|
# kyle-at-centralparksoftware.com |
4
|
|
|
|
|
|
|
# ObjectivePerl is free software; you can |
5
|
|
|
|
|
|
|
# redistribute and/or modify it under the |
6
|
|
|
|
|
|
|
# same terms as perl itself. |
7
|
|
|
|
|
|
|
# ========================================== |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package ObjectivePerl::Runtime; |
10
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
11
|
1
|
|
|
1
|
|
817
|
use Data::Dumper; |
|
1
|
|
|
|
|
6702
|
|
|
1
|
|
|
|
|
729
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $_runtime; # we will use a singleton runtime to track classes etc. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub runtime { |
16
|
0
|
|
|
0
|
0
|
|
my $className = shift; |
17
|
0
|
0
|
|
|
|
|
unless ($_runtime) { |
18
|
0
|
|
|
|
|
|
$_runtime = bless {}, $className; |
19
|
0
|
|
|
|
|
|
$_runtime->init(); |
20
|
|
|
|
|
|
|
} |
21
|
0
|
|
|
|
|
|
return $_runtime; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub init { |
25
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub debug { |
29
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
30
|
0
|
|
|
|
|
|
return $self->{_debug}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub setDebug { |
34
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
35
|
0
|
|
|
|
|
|
$self->{_debug} = shift; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub camelBonesCompatibility { |
39
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
40
|
0
|
|
|
|
|
|
return $self->{_camelBonesCompatibility}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub setCamelBonesCompatibility { |
44
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
45
|
0
|
|
|
|
|
|
$self->{_camelBonesCompatibility} = shift; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub ObjpMsgSend { |
49
|
0
|
|
|
0
|
0
|
|
my $className = shift; |
50
|
|
|
|
|
|
|
# For some reason, CamelBones yacks if you don't assign the return |
51
|
|
|
|
|
|
|
# value to a variable at some point (maybe can't fish things off the stack?) |
52
|
|
|
|
|
|
|
# so we would have to do this even without the debug line |
53
|
0
|
|
|
|
|
|
my $returnValue = $className->runtime()->objp_msgSend(@_); |
54
|
0
|
0
|
|
|
|
|
if ($className->runtime()->debug() & $ObjectivePerl::DEBUG_MESSAGING) { |
55
|
0
|
|
|
|
|
|
print "Return value: ".Data::Dumper->Dump([$returnValue], [qw($value)])."\n"; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
|
return $returnValue; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub objp_msgSend { |
61
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
62
|
0
|
|
0
|
|
|
|
my $receiver = shift || ""; |
63
|
0
|
|
0
|
|
|
|
my $message = shift || ""; |
64
|
0
|
|
0
|
|
|
|
my $selectors = shift || []; # an array of key value pairs |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
if ($self->debug() & $ObjectivePerl::DEBUG_MESSAGING) { print "Trying to invoke $message on $receiver\n" }; |
|
0
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
return undef unless $receiver; |
68
|
0
|
0
|
|
|
|
|
return undef unless $message; |
69
|
|
|
|
|
|
|
# the first argument is the entry for $message |
70
|
0
|
|
0
|
|
|
|
my $messageSignature = messageSignatureFromMessageAndSelectors($message, $selectors) || ""; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my $argumentList = []; |
73
|
0
|
|
|
|
|
|
foreach my $selector (@$selectors) { |
74
|
0
|
|
|
|
|
|
push (@$argumentList, $selector->{value}); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# send the message |
78
|
0
|
0
|
|
|
|
|
if (UNIVERSAL::can($receiver, $messageSignature)) { |
79
|
0
|
0
|
|
|
|
|
if ($self->debug() & $ObjectivePerl::DEBUG_MESSAGING) { print "Invoking $messageSignature on object $receiver\n"; } |
|
0
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
return $receiver->$messageSignature(@$argumentList); |
81
|
|
|
|
|
|
|
} else { |
82
|
0
|
|
|
|
|
|
my $messageSignatureWithNoUnderscores = lcfirst(join("", map {ucfirst($_)} split(/_/, $messageSignature))); |
|
0
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
if (UNIVERSAL::can($receiver, $messageSignatureWithNoUnderscores)) { |
84
|
0
|
0
|
|
|
|
|
if ($self->debug() & $ObjectivePerl::DEBUG_MESSAGING) { print "Invoking $messageSignatureWithNoUnderscores on object $receiver\n"; } |
|
0
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return $receiver->$messageSignatureWithNoUnderscores(@$argumentList); |
86
|
|
|
|
|
|
|
} |
87
|
0
|
|
|
|
|
|
my $messageSignatureWithTrailingUnderscores = $messageSignatureWithNoUnderscores.("_" x scalar(@$argumentList)); |
88
|
0
|
0
|
|
|
|
|
if (UNIVERSAL::can($receiver, $messageSignatureWithTrailingUnderscores)) { |
89
|
0
|
0
|
|
|
|
|
if ($self->debug() & $ObjectivePerl::DEBUG_MESSAGING) { print "Invoking $messageSignatureWithTrailingUnderscores on object $receiver\n"; } |
|
0
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return $receiver->$messageSignatureWithTrailingUnderscores(@$argumentList); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
# TODO: Handle unknown static methods... this will only work with instance methods |
94
|
0
|
0
|
|
|
|
|
if (UNIVERSAL::can($receiver, "handleUnknownSelector")) { |
95
|
0
|
0
|
|
|
|
|
if ($self->debug() & $ObjectivePerl::DEBUG_MESSAGING) { print "Invoking handleUnknownSelector on object $receiver\n"; } |
|
0
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
return $receiver->handleUnknownSelector($message, $selectors); |
97
|
|
|
|
|
|
|
} else { |
98
|
|
|
|
|
|
|
# can't find the method anywhere, so just send it to the object and see what happens |
99
|
0
|
|
|
|
|
|
return $receiver->$messageSignature(@$argumentList); |
100
|
|
|
|
|
|
|
} |
101
|
0
|
|
|
|
|
|
return undef; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub messageSignatureFromMessageAndSelectors { |
105
|
0
|
|
|
0
|
0
|
|
my $message = shift; |
106
|
0
|
|
|
|
|
|
my $arguments = shift; |
107
|
0
|
|
|
|
|
|
my $messageSignature = $message; |
108
|
0
|
0
|
|
|
|
|
if ($arguments) { |
109
|
0
|
|
|
|
|
|
foreach my $argument (@$arguments) { |
110
|
0
|
0
|
|
|
|
|
next if ($argument->{key} eq $message); |
111
|
0
|
0
|
|
|
|
|
if ($argument->{key} eq "_") { |
112
|
0
|
|
|
|
|
|
$messageSignature .= "_"; |
113
|
|
|
|
|
|
|
} else { |
114
|
0
|
|
|
|
|
|
$messageSignature .= "_".$argument->{key}; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
0
|
|
|
|
|
|
return $messageSignature; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |