| 1 | package RPC::Simple::ObjectHandler; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use vars qw($VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use RPC::Simple::CallHandler ; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | # Items to export into callers namespace by default. Note: do not export | ||||||||||
| 9 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||
| 10 | # Do not simply export all your public functions/methods/constants. | ||||||||||
| 11 | |||||||||||
| 12 | 1 | ( $VERSION ) = '$Revision: 1.7 $ ' =~ /\$Revision:\s+([^\s]+)/; | |||||||||
| 13 | |||||||||||
| 14 | sub new | ||||||||||
| 15 | 0 | ▶ | { | ||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 16 | 0 | my $type = shift ; | |||||||||
| 17 | 0 | my $self = {} ; | |||||||||
| 18 | 0 | bless $self,$type ; | |||||||||
| 19 | |||||||||||
| 20 | 0 | $self->{server} = shift ; | |||||||||
| 21 | 0 | my $objName = shift ; | |||||||||
| 22 | 0 | $self->{handle} = shift ; | |||||||||
| 23 | 0 | my $args = shift ; | |||||||||
| 24 | 0 | my $reqId = shift ; | |||||||||
| 25 | |||||||||||
| 26 | 0 | my $result = 1 ; | |||||||||
| 27 | |||||||||||
| 28 | #We can remove the .pm off the object name if | ||||||||||
| 29 | #it exists. This will allow us to be called | ||||||||||
| 30 | #as an object name and even a fully qualified | ||||||||||
| 31 | #object name ie.(Object.pm, Ojbect, Some::Object) | ||||||||||
| 32 | 0 | $objName =~ s/\.\w*$// ; | |||||||||
| 33 | 0 | eval "require $objName; $objName->import()" ; | |||||||||
| 34 | |||||||||||
| 35 | 0 | ▶ | if ($@) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | { | ||||||||||
| 37 | 0 | print "Can't load $objName: $@\n" ; | |||||||||
| 38 | 0 | $result = 0 ; | |||||||||
| 39 | } | ||||||||||
| 40 | else | ||||||||||
| 41 | { | ||||||||||
| 42 | 0 | ▶ | print "Creating object controller for $objName\n" if $main::verbose ; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 0 | eval { $self->{objRef} = $objName -> new ($self, @$args) }; | |||||||||
| 44 | |||||||||||
| 45 | 0 | ▶ | if ($@) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | { | ||||||||||
| 47 | 0 | print "Can't create $objName: $@\n" ; | |||||||||
| 48 | 0 | $result = 0 ; | |||||||||
| 49 | } | ||||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 0 | $self->{slaveClass} = $objName ; | |||||||||
| 53 | |||||||||||
| 54 | 0 | $self->callbackDone($reqId,$result,$@) ; | |||||||||
| 55 | 0 | return $self ; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | sub destroy | ||||||||||
| 59 | 0 | ▶ | { | ||||||||
|
Subroutine
destroy: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 60 | 0 | my $self=shift; | |||||||||
| 61 | 0 | delete $self->{objRef} ; | |||||||||
| 62 | |||||||||||
| 63 | 0 | ▶ | if (defined $self->{requestTab}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | { | ||||||||||
| 65 | 0 | foreach (values %{$self->{requestTab}}) | |||||||||
| 66 | { | ||||||||||
| 67 | 0 | $_->destroy ; | |||||||||
| 68 | } | ||||||||||
| 69 | } | ||||||||||
| 70 | 0 | print "ObjectHandler for $self->{slaveClass} destroyed\n"; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | sub remoteCall | ||||||||||
| 74 | 0 | ▶ | { | ||||||||
|
Subroutine
remoteCall: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 75 | 0 | my $self = shift ; | |||||||||
| 76 | 0 | my $reqId = shift ; # optionnal | |||||||||
| 77 | 0 | my $method = shift ; | |||||||||
| 78 | 0 | my $args = shift ; | |||||||||
| 79 | |||||||||||
| 80 | 0 | ▶ | if (defined $reqId) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | { | ||||||||||
| 82 | # call back required | ||||||||||
| 83 | $self->{requestTab}{$reqId} = | ||||||||||
| 84 | RPC::Simple::CallHandler -> | ||||||||||
| 85 | 0 | new ($self,$self->{objRef}, $reqId, $method, $args) ; | |||||||||
| 86 | } | ||||||||||
| 87 | else | ||||||||||
| 88 | { | ||||||||||
| 89 | 0 | $self->{objRef} -> $method (@$args); | |||||||||
| 90 | } | ||||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | sub close | ||||||||||
| 94 | 0 | ▶ | { | ||||||||
|
Subroutine
close: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 95 | 0 | my $self = shift ; | |||||||||
| 96 | |||||||||||
| 97 | 0 | print "Closing ",ref($self),"\n" ; | |||||||||
| 98 | |||||||||||
| 99 | 0 | map( undef $self->{requestTab}{$_} , keys %{$self->{requestTab}}) ; | |||||||||
| 100 | 0 | $self->{objRef} -> close ; | |||||||||
| 101 | 0 | undef $self ; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | sub delegate | ||||||||||
| 105 | 0 | ▶ | { | ||||||||
|
Subroutine
delegate: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 106 | 0 | my $self = shift ; | |||||||||
| 107 | 0 | my $method = shift ; | |||||||||
| 108 | 0 | my $args = \@_ ; | |||||||||
| 109 | |||||||||||
| 110 | 0 | ▶ | print "delegate called by real object for $method\n" if $main::verbose ; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | 0 | $self->{server}-> writeSock($self->{handle},$method,undef,$args) ; | |||||||||
| 112 | } | ||||||||||
| 113 | |||||||||||
| 114 | sub callbackDone | ||||||||||
| 115 | 0 | ▶ | { | ||||||||
|
Subroutine
callbackDone: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 116 | 0 | my $self = shift ; | |||||||||
| 117 | 0 | my $reqId = shift ; | |||||||||
| 118 | |||||||||||
| 119 | 0 | ▶ | print "callbackDone called\n" if $main::verbose ; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 120 | 0 | $self->{server}->writeSock($self->{handle},undef,$reqId,[@_]) ; | |||||||||
| 121 | } | ||||||||||
| 122 | |||||||||||
| 123 | # Preloaded methods go here. | ||||||||||
| 124 | |||||||||||
| 125 | # Autoload methods go after =cut, and are processed by the autosplit program. | ||||||||||
| 126 | |||||||||||
| 127 | 1 | 1; | |||||||||
| 128 | __END__ | ||||||||||