| 1 | package RPC::Simple::Agent; | ||||||||||
| 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::Factory ; | ||||||||
|
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 | # Preloaded methods go here. | ||||||||||
| 15 | |||||||||||
| 16 | # connection is opened, ask for a remote object | ||||||||||
| 17 | sub new | ||||||||||
| 18 | 1 | ▶ | { | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 19 | 1 | my $type = shift ; | |||||||||
| 20 | 1 | my $factoryObj = shift ; # factory | |||||||||
| 21 | 1 | my $clientRef = shift; | |||||||||
| 22 | 1 | my $index = shift ; | |||||||||
| 23 | 1 | my $remoteClass = shift ; # may be undef | |||||||||
| 24 | |||||||||||
| 25 | 1 | my $self={} ; | |||||||||
| 26 | 1 | $self->{'idx'} = $index ; | |||||||||
| 27 | |||||||||||
| 28 | 1 | $self->{requestId} = 0 ; | |||||||||
| 29 | |||||||||||
| 30 | 1 | $self->{'factory'} = $factoryObj ; | |||||||||
| 31 | 1 | $self->{remoteHostName} = $factoryObj->getRemoteHostName() ; | |||||||||
| 32 | |||||||||||
| 33 | 1 | ▶ | unless (defined $remoteClass) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | { | ||||||||||
| 35 | 0 | $remoteClass = ref($clientRef) ; | |||||||||
| 36 | 0 | $remoteClass =~ s/(\w+)$/Real$1/ ; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 1 | print "Creating $type for $remoteClass\n"; | |||||||||
| 40 | |||||||||||
| 41 | 1 | $self->{'clientObj'}= $clientRef ; | |||||||||
| 42 | |||||||||||
| 43 | # store call-back info | ||||||||||
| 44 | 1 | ▶ | $self->{callback}{$self->{requestId}} = sub{ $self->remoteCreated(@_)} ; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 45 | 1 | my $id = $self->{requestId}++ ; | |||||||||
| 46 | |||||||||||
| 47 | 1 | $factoryObj->writeSockBuffer($index, 'new', $id , [ @_ ], $remoteClass ) ; | |||||||||
| 48 | |||||||||||
| 49 | 1 | $self->{remoteClass} = $remoteClass ; | |||||||||
| 50 | 1 | bless $self, $type ; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | sub destroy | ||||||||||
| 54 | 0 | ▶ | { | ||||||||
|
Subroutine
destroy: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 55 | 0 | my $self = shift ; | |||||||||
| 56 | 0 | print "RPC::Simple::Agent destroyed\n"; | |||||||||
| 57 | 0 | $self->{factory}->destroyRemoteObject($self->{'idx'}); | |||||||||
| 58 | |||||||||||
| 59 | # We need to undef the factory and clientObj references | ||||||||||
| 60 | # because they create a circular reference and we can not | ||||||||||
| 61 | # destroy the factory or the clientObj | ||||||||||
| 62 | 0 | undef $self->{factory}; | |||||||||
| 63 | 0 | undef $self->{clientObj}; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | sub delegate | ||||||||||
| 67 | 1 | ▶ | { | ||||||||
|
Subroutine
delegate: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||
| 68 | # delegate to remote | ||||||||||
| 69 | 1 | my $self = shift ; | |||||||||
| 70 | 1 | my $method = shift ; | |||||||||
| 71 | 1 | my $id ; | |||||||||
| 72 | |||||||||||
| 73 | 1 | ▶ | if (ref($_[0]) eq 'CODE') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | { | ||||||||||
| 75 | # callback required | ||||||||||
| 76 | 0 | $self->{callback}{$self->{requestId}} = shift ; # store call-back info | |||||||||
| 77 | 0 | $id = $self->{requestId}++ ; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 1 | $self->{'factory'}->writeSockBuffer($self->{'idx'},$method, $id,[ @_]) ; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | sub remoteCreated | ||||||||||
| 84 | 1 | ▶ | { | ||||||||
|
Subroutine
remoteCreated: called CC=2 SCAR=7.5
Pod
documented
| |||||||||||
| 85 | 1 | my $self = shift ; | |||||||||
| 86 | 1 | my $result = shift ; | |||||||||
| 87 | 1 | my $failStr = shift ; | |||||||||
| 88 | |||||||||||
| 89 | 1 | ▶ | if ($result) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | { | ||||||||||
| 91 | 1 | print "Remote class $self->{remoteClass} created\n"; | |||||||||
| 92 | 1 | return ; | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | 0 | print "Failed to create remote class $self->{remoteClass}\n",$failStr; | |||||||||
| 96 | 0 | undef $self->{clientObj} ; | |||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | sub callMethod | ||||||||||
| 100 | 0 | ▶ | { | ||||||||
|
Subroutine
callMethod: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 101 | 0 | my $self = shift ; | |||||||||
| 102 | 0 | my $method = shift ; | |||||||||
| 103 | 0 | my $args = shift ; | |||||||||
| 104 | 0 | $self->{clientObj} -> $method (@$args) ; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | sub getRemoteHostName | ||||||||||
| 108 | 1 | ▶ | { | ||||||||
|
Subroutine
getRemoteHostName: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 109 | 1 | my $self = shift ; | |||||||||
| 110 | 1 | return $self->{'remoteHostName'} ; | |||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | sub treatCallBack | ||||||||||
| 114 | 1 | ▶ | { | ||||||||
|
Subroutine
treatCallBack: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 115 | 1 | my $self = shift ; | |||||||||
| 116 | 1 | my $reqId = shift ; | |||||||||
| 117 | 1 | my $args = shift ; | |||||||||
| 118 | |||||||||||
| 119 | 1 | my $cbRef = $self->{callback}{$reqId} ; | |||||||||
| 120 | |||||||||||
| 121 | 1 | &$cbRef(@$args); | |||||||||
| 122 | |||||||||||
| 123 | 1 | delete $self->{callback}{$reqId} ; | |||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | |||||||||||
| 127 | # Autoload methods go after =cut, and are processed by the autosplit program. | ||||||||||
| 128 | |||||||||||
| 129 | 1 | 1; | |||||||||
| 130 | |||||||||||
| 131 | __END__ | ||||||||||