Thread: services: services/perl/lib/AppSwitch/Base Client.pm
Status: Pre-Alpha
Brought to you by:
jgsmith
From: <app...@li...> - 2001-07-20 20:54:12
|
jgsmith 01/07/20 13:54:09 Added: perl/lib/AppSwitch/Base Client.pm Log: Initial checkin Revision Changes Path 1.1 services/perl/lib/AppSwitch/Base/Client.pm Index: Client.pm =================================================================== package AppSwitch::Base::Client; our $VERSION = 0.01; use Carp; use SOAP::Transport::UNIX; # $ Id: $ =head1 NAME AppSwitch::Base::Client =head1 SYNOPSIS package AppSwitch::MyService; use base q(AppSwitch::Base::Client); our $RPC_SERVICE = q(x-myservice); =head1 DESCRIPTION This base class contains most of the code common across service clients. =head1 METHODS The following methods are provided. =over 4 =item new This is a basic constructor for the client object. If overriding this method, use it to construct the object and then modify the resulting object. sub new { my $self = shift -> SUPER::new(@_); # process @_ here if needed return $self; } =cut sub new { my $class = shift; $class = ref $class || $class; my $self = bless { }, $class; return $self; } =item service This will return the service name of the client. If an argument is provided, it sets the service name of the client and returns the previous service name. Be careful with this as it changes how requests are sent to the service providers. The default value is defined by the C<RPC_SERVICE> package global. The <@ISA> array is searched if needed. =cut sub service { my $self = shift; if(@_) { my $o = $self -> service(); $self -> {_service} = $_[0]; return $o; } return $self -> {_service} if defined $self -> {_service}; my $class = ref $self || $self; return($self -> {_service} = ${$class . "::RPC_SERVICE"}) if(defined ${$class . "::RPC_SERVICE"}); croak "Service class undefined by $class" unless defined @{$class . "::ISA"}; my @classes = @{$class . "::ISA"}; while(@classes) { $class = shift @classes; return($self -> {_service} = ${$class . "::RPC_SERVICE"}) if(defined ${$class . "::RPC_SERVICE"}); push @classes, @{$class . "::ISA"} if defined @{$class . "::ISA"}; } $class = ref $self || $self; croak "Service class undefined by $class"; } =item request This actually does the request. The first argument is the method name without the service name. All subsequent arguments are considered part of a hash that is sent to the daemon as a C<struct>. The return value is the result of the request (if synchronous) or an object from which to fetch the result at a later time (if asynchronous). Note that asynchronous requests are not supported yet. =cut sub request { my($self) = shift; my $method = shift; my(%args) = @_; $method = $self -> service() . ".$method"; # now we need to dispatch via the SOAP/XML-RPC client object... which is global... our $_transport; if(!defined $_client) { $_client = SOAP::Lite -> proxy("unix:$ENV{APPSWITCH_SOCKET}") or croak "Unable to connect to AppSwitch daemon: $!"; } if(@_) { return $_client -> $method({ %args }) -> result; } else { return $_client -> $method() -> result; } } =item version This will return the version of the service provider. If multiple service providers are configured for a service, it will return the lowest version. =cut sub version { my($self) = shift; return $self -> request("version"); } =back =head1 AUTHOR James Smith <jg...@ja...> =head1 SEE ALSO L<AppSwitch::Daemon>, L<AppSwitch::Server> =head1 COPYRIGHT =cut 1; |
From: <app...@li...> - 2001-07-27 23:26:29
|
jgsmith 01/07/27 16:26:28 Modified: perl/lib/AppSwitch/Base Client.pm Log: Allow functional use of client interfaces Revision Changes Path 1.2 +19 -2 services/perl/lib/AppSwitch/Base/Client.pm Index: Client.pm =================================================================== RCS file: /cvsroot/appswitch/services/perl/lib/AppSwitch/Base/Client.pm,v retrieving revision 1.1 retrieving revision 1.2 diff -b -u -r1.1 -r1.2 --- Client.pm 2001/07/20 20:54:09 1.1 +++ Client.pm 2001/07/27 23:26:28 1.2 @@ -5,7 +5,7 @@ use Carp; use SOAP::Transport::UNIX; -# $ Id: $ +# $Id: Client.pm,v 1.2 2001/07/27 23:26:28 jgsmith Exp $ =head1 NAME @@ -146,8 +146,25 @@ } } +=item object_or_default +This will return all the arguments with the first argument guarenteed to be +a valid client object. +=cut + + + +sub object_or_default { + return @_ if ref $_[0] && $_[0] -> isa(AppSwitch::Base::Client); + my $caller = caller; + our $_clients; + $_clients{$caller} = $caller -> new() unless defined $_clients{$caller}; + return ($_clients{$caller}, @_); +} + + + =item version This will return the version of the service provider. If @@ -159,7 +176,7 @@ sub version { - my($self) = shift; + my($self) = object_or_default(@_); return $self -> request("version"); } |
From: <app...@li...> - 2001-07-29 18:25:35
|
jgsmith 01/07/29 11:25:35 Modified: perl/lib/AppSwitch/Base Client.pm Log: Changed to XML-RPC for now Revision Changes Path 1.4 +4 -7 services/perl/lib/AppSwitch/Base/Client.pm Index: Client.pm =================================================================== RCS file: /cvsroot/appswitch/services/perl/lib/AppSwitch/Base/Client.pm,v retrieving revision 1.3 retrieving revision 1.4 diff -b -u -r1.3 -r1.4 --- Client.pm 2001/07/29 05:12:31 1.3 +++ Client.pm 2001/07/29 18:25:35 1.4 @@ -3,10 +3,10 @@ our $VERSION = 0.01; use Carp; -use SOAP::Transport::UNIX; +use XMLRPC::Transport::UNIX; use strict; -# $Id: Client.pm,v 1.3 2001/07/29 05:12:31 jgsmith Exp $ +# $Id: Client.pm,v 1.4 2001/07/29 18:25:35 jgsmith Exp $ =head1 NAME @@ -125,18 +125,15 @@ sub request { - my($self) = shift; + my($self, $method, %args) = @_; - my $method = shift; - my(%args) = @_; - $method = $self -> service() . ".$method"; # now we need to dispatch via the SOAP/XML-RPC client object... which is global... our $_client; if(!defined $_client) { - $_client = SOAP::Lite -> proxy("unix:$ENV{APPSWITCH_SOCKET}") + $_client = XMLRPC::Lite -> proxy("unix:$ENV{APPSWITCH_SOCKET}") or croak "Unable to connect to AppSwitch daemon: $!"; } |