ObjectivePerl/Runtime.pm

filter: Statementstmt 11.4% 8 / 70 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 18.1% 2 / 11 Podpod 0.0% 0 / 9 totaltotal 7.4% 10 / 134 CC 23 SCAR 51.0
CC
23
Cov
7%
objp_msgSend
306.0
messageSignatureFromMessageAndSelectors
30.0
runtime
6.0
CRAP 163.3
↑ Summary ObjectivePerl/Parser.pm »
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
BranchTrueFalseTotal
unless ($_runtime) 0 0 0
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
BranchTrueFalseTotal
if ($className->runtime->debug & $ObjectivePerl::DEBUG_MESSAGING) 0 0 0
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() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
63 0 ▶ my $message = shift || "";
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
64 0 ▶ my $selectors = shift || []; # an array of key value pairs
Condition0%0/2
shift() || []
l!l
00
MC/DC0%0/1
shift() || []
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
65  
66 0 ▶ if ($self->debug() & $ObjectivePerl::DEBUG_MESSAGING) { print "Trying to invoke $message on $receiver\n" };
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug & $ObjectivePerl::DEBUG_MESSAGING) 0 0 0
67 0 ▶ return undef unless $receiver;
Branch: 1 branch
BranchTrueFalseTotal
unless $receiver 0 0 0
68 0 ▶ return undef unless $message;
Branch: 1 branch
BranchTrueFalseTotal
unless $message 0 0 0
69 # the first argument is the entry for $message
70 0 ▶ my $messageSignature = messageSignatureFromMessageAndSelectors($message, $selectors) || "";
Condition0%0/2
messageSignatureFromMessageAndSelectors($message, $selectors) || ''
l!l
00
MC/DC0%0/1
messageSignatureFromMessageAndSelectors($message, $selectors) || ''
messageSignatureFromMessageAndSelectors($message, $selectors)
Truth table0%0/2
A
A= messageSignatureFromMessageAndSelectors($message, $selectors)
Aresult
11
00
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
BranchTrueFalseTotal
if (UNIVERSAL::can($receiver, $messageSignature)) { } 0 0 0
79 0 ▶ if ($self->debug() & $ObjectivePerl::DEBUG_MESSAGING) { print "Invoking $messageSignature on object $receiver\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug & $ObjectivePerl::DEBUG_MESSAGING) 0 0 0
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
BranchTrueFalseTotal
if (UNIVERSAL::can($receiver, $messageSignatureWithNoUnderscores)) 0 0 0
84 0 ▶ if ($self->debug() & $ObjectivePerl::DEBUG_MESSAGING) { print "Invoking $messageSignatureWithNoUnderscores on object $receiver\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug & $ObjectivePerl::DEBUG_MESSAGING) 0 0 0
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
BranchTrueFalseTotal
if (UNIVERSAL::can($receiver, $messageSignatureWithTrailingUnderscores)) 0 0 0
89 0 ▶ if ($self->debug() & $ObjectivePerl::DEBUG_MESSAGING) { print "Invoking $messageSignatureWithTrailingUnderscores on object $receiver\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug & $ObjectivePerl::DEBUG_MESSAGING) 0 0 0
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
BranchTrueFalseTotal
if (UNIVERSAL::can($receiver, 'handleUnknownSelector')) { } 0 0 0
95 0 ▶ if ($self->debug() & $ObjectivePerl::DEBUG_MESSAGING) { print "Invoking handleUnknownSelector on object $receiver\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug & $ObjectivePerl::DEBUG_MESSAGING) 0 0 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 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
BranchTrueFalseTotal
if ($arguments) 0 0 0
109 0 foreach my $argument (@$arguments) {
110 0 ▶ next if ($argument->{key} eq $message);
Branch: 1 branch
BranchTrueFalseTotal
if $argument->{"key"} eq $message 0 0 0
111 0 ▶ if ($argument->{key} eq "_") {
Branch: 1 branch
BranchTrueFalseTotal
if ($argument->{'key'} eq '_') { } 0 0 0
112 0 $messageSignature .= "_";
113 } else {
114 0 $messageSignature .= "_".$argument->{key};
115 }
116 }
117 }
118 0 return $messageSignature;
119 }
120  
121 1 1;
↑ Summary ObjectivePerl/Parser.pm »