| 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 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 1 | ▶ | use Data::Dumper; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | 1 | my $_runtime; # we will use a singleton runtime to track classes etc. | |||||||||||
| 14 | |||||||||||||
| 15 | 0 | ▶ | sub runtime { | ||||||||||
|
Subroutine
runtime: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 16 | 0 | my $className = shift; | |||||||||||
| 17 | 0 | ▶ | unless ($_runtime) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 18 | 0 | $_runtime = bless {}, $className; | |||||||||||
| 19 | 0 | $_runtime->init(); | |||||||||||
| 20 | } | ||||||||||||
| 21 | 0 | return $_runtime; | |||||||||||
| 22 | } | ||||||||||||
| 23 | |||||||||||||
| 24 | 0 | ▶ | sub init { | ||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 25 | 0 | my $self = shift; | |||||||||||
| 26 | } | ||||||||||||
| 27 | |||||||||||||
| 28 | 0 | ▶ | sub debug { | ||||||||||
|
Subroutine
debug: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 29 | 0 | my $self = shift; | |||||||||||
| 30 | 0 | return $self->{_debug}; | |||||||||||
| 31 | } | ||||||||||||
| 32 | |||||||||||||
| 33 | 0 | ▶ | sub setDebug { | ||||||||||
|
Subroutine
setDebug: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 34 | 0 | my $self = shift; | |||||||||||
| 35 | 0 | $self->{_debug} = shift; | |||||||||||
| 36 | } | ||||||||||||
| 37 | |||||||||||||
| 38 | 0 | ▶ | sub camelBonesCompatibility { | ||||||||||
|
Subroutine
camelBonesCompatibility: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 39 | 0 | my $self = shift; | |||||||||||
| 40 | 0 | return $self->{_camelBonesCompatibility}; | |||||||||||
| 41 | } | ||||||||||||
| 42 | |||||||||||||
| 43 | 0 | ▶ | sub setCamelBonesCompatibility { | ||||||||||
|
Subroutine
setCamelBonesCompatibility: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 44 | 0 | my $self = shift; | |||||||||||
| 45 | 0 | $self->{_camelBonesCompatibility} = shift; | |||||||||||
| 46 | } | ||||||||||||
| 47 | |||||||||||||
| 48 | 0 | ▶ | sub ObjpMsgSend { | ||||||||||
|
Subroutine
ObjpMsgSend: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 49 | 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 | ▶ | if ($className->runtime()->debug() & $ObjectivePerl::DEBUG_MESSAGING) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | 0 | print "Return value: ".Data::Dumper->Dump([$returnValue], [qw($value)])."\n"; | |||||||||||
| 56 | } | ||||||||||||
| 57 | 0 | return $returnValue; | |||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | 0 | ▶ | sub objp_msgSend { | ||||||||||
|
Subroutine
objp_msgSend: not called CC=17 SCAR=57.2
Pod
undocumented
| |||||||||||||
| 61 | 0 | my $self = shift; | |||||||||||
| 62 | 0 | ▶ | my $receiver = shift || ""; | ||||||||||
|
Condition0%0/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 63 | 0 | ▶ | my $message = shift || ""; | ||||||||||
|
Condition0%0/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 64 | 0 | ▶ | my $selectors = shift || []; # an array of key value pairs | ||||||||||
|
Condition0%0/2
shift() || []
MC/DC0%0/1
shift() || []
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 65 | |||||||||||||
| 66 | 0 | ▶ | if ($self->debug() & $ObjectivePerl::DEBUG_MESSAGING) { print "Trying to invoke $message on $receiver\n" }; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 67 | 0 | ▶ | return undef unless $receiver; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 68 | 0 | ▶ | return undef unless $message; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 69 | # the first argument is the entry for $message | ||||||||||||
| 70 | 0 | ▶ | my $messageSignature = messageSignatureFromMessageAndSelectors($message, $selectors) || ""; | ||||||||||
|
Condition0%0/2
messageSignatureFromMessageAndSelectors($message, $selectors) || ''
MC/DC0%0/1
messageSignatureFromMessageAndSelectors($message, $selectors) || ''
messageSignatureFromMessageAndSelectors($message, $selectors)
Truth table0%0/2
A
A= 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 | ▶ | if (UNIVERSAL::can($receiver, $messageSignature)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 79 | 0 | ▶ | if ($self->debug() & $ObjectivePerl::DEBUG_MESSAGING) { print "Invoking $messageSignature on object $receiver\n"; } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 80 | 0 | return $receiver->$messageSignature(@$argumentList); | |||||||||||
| 81 | } else { | ||||||||||||
| 82 | 0 | my $messageSignatureWithNoUnderscores = lcfirst(join("", map {ucfirst($_)} split(/_/, $messageSignature))); | |||||||||||
| 83 | 0 | ▶ | if (UNIVERSAL::can($receiver, $messageSignatureWithNoUnderscores)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 84 | 0 | ▶ | if ($self->debug() & $ObjectivePerl::DEBUG_MESSAGING) { print "Invoking $messageSignatureWithNoUnderscores on object $receiver\n"; } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 85 | 0 | return $receiver->$messageSignatureWithNoUnderscores(@$argumentList); | |||||||||||
| 86 | } | ||||||||||||
| 87 | 0 | my $messageSignatureWithTrailingUnderscores = $messageSignatureWithNoUnderscores.("_" x scalar(@$argumentList)); | |||||||||||
| 88 | 0 | ▶ | if (UNIVERSAL::can($receiver, $messageSignatureWithTrailingUnderscores)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 89 | 0 | ▶ | if ($self->debug() & $ObjectivePerl::DEBUG_MESSAGING) { print "Invoking $messageSignatureWithTrailingUnderscores on object $receiver\n"; } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 90 | 0 | return $receiver->$messageSignatureWithTrailingUnderscores(@$argumentList); | |||||||||||
| 91 | } | ||||||||||||
| 92 | } | ||||||||||||
| 93 | # TODO: Handle unknown static methods... this will only work with instance methods | ||||||||||||
| 94 | 0 | ▶ | if (UNIVERSAL::can($receiver, "handleUnknownSelector")) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 95 | 0 | ▶ | if ($self->debug() & $ObjectivePerl::DEBUG_MESSAGING) { print "Invoking handleUnknownSelector on object $receiver\n"; } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | 0 | ▶ | sub messageSignatureFromMessageAndSelectors { | ||||||||||
|
Subroutine
messageSignatureFromMessageAndSelectors: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||
| 105 | 0 | my $message = shift; | |||||||||||
| 106 | 0 | my $arguments = shift; | |||||||||||
| 107 | 0 | my $messageSignature = $message; | |||||||||||
| 108 | 0 | ▶ | if ($arguments) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 109 | 0 | foreach my $argument (@$arguments) { | |||||||||||
| 110 | 0 | ▶ | next if ($argument->{key} eq $message); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 111 | 0 | ▶ | if ($argument->{key} eq "_") { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 112 | 0 | $messageSignature .= "_"; | |||||||||||
| 113 | } else { | ||||||||||||
| 114 | 0 | $messageSignature .= "_".$argument->{key}; | |||||||||||
| 115 | } | ||||||||||||
| 116 | } | ||||||||||||
| 117 | } | ||||||||||||
| 118 | 0 | return $messageSignature; | |||||||||||
| 119 | } | ||||||||||||
| 120 | |||||||||||||
| 121 | 1 | 1; | |||||||||||