services: services/perl/lib/AppSwitch/Services Daemon.pm
Status: Pre-Alpha
Brought to you by:
jgsmith
|
From: <app...@li...> - 2001-07-29 18:17:23
|
jgsmith 01/07/29 11:17:23
Added: perl/lib/AppSwitch/Services Daemon.pm
Log:
Initial commit
Revision Changes Path
1.1 services/perl/lib/AppSwitch/Services/Daemon.pm
Index: Daemon.pm
===================================================================
package AppSwitch::Services::Daemon;
use strict;
use XMLRPC::Transport::HTTP;
our $VERSION = q(0.01);
sub register {
my($self, $handler) = @_;
$self -> {handler} -> {handlers} -> {$handler -> service} = $handler;
}
sub query_handler { $_[0] -> {handler} -> {handlers} -> {$_[1]} }
sub run {
my($self) = @_;
$self -> {daemon} = XMLRPC::Transport::HTTP::Daemon
-> new (%{$self -> {config} || {}})
-> dispatch_to($self -> {handler})
-> handle();
}
sub new {
my($class) = shift;
$class = ref $class || $class;
my $self = bless { config => { @_ },
handler => bless { } =>
q(AppSwitch::Services::Daemon::Handler),
} => $class;
return $self;
}
sub initialize {
my($self, $m) = shift;
foreach(@_) {
$m = m{::} ? $_ : "AppSwitch::${_}::Service";
eval { require $m; };
$m -> initialize($self) unless $@;
}
}
package AppSwitch::Services::Daemon::Handler;
sub AUTOLOAD {
my($self) = shift;
# SOAP::Lite likes the methods to be object methods for some odd reason
(my $m = our $AUTOLOAD) =~ s{^.*::}{};
return undef unless $m =~ m{(.+)\.(.+)};
my($service, $method) = (lc($1), lc($2));
return undef unless defined $self -> {handlers} -> {$service};
*$m = sub { shift -> {handlers} -> {$service} -> dispatch($method, @_) };
goto &$m;
}
1;
__END__
=head1 NAME
AppSwitch::Services::Daemon
=head1 SYNOPSIS
my $daemon = new AppSwitch::Services::Daemon [Configuration...];
initialize $daemon q(Echo Authentication My::Authorization);
my $echo_handler = $daemon -> query_handler("echo");
$daemon -> run();
=head1 DESCRIPTION
The service daemon runs the XML-RPC server providing the actual services.
Setup is quite simple, with an arbitrary number of services supported.
The actual XMLRPC::Transport::HTTP daemon is configured by the
information passed when creating the AppSwitch::Services::Daemon
object.
=head1 AUTHOR
James Smith <jg...@ja...>
=head1 SEE ALSO
L<XMLRPC::Transport::HTTP>.
=head1 COPYRIGHT
Copyright (C) 2001 James Smith
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the Project nor the names of its contributors
may be used to endorse or promote products derived from this
software without specific prior written permission.
=cut
|