Commit 77761cd6 authored by mkanat%bugzilla.org's avatar mkanat%bugzilla.org

Bug 396243: Allow extensions (aka plugins) to extend the WebService interface

This also includes the first checkin of the example plugin. Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=ghendricks, a=mkanat
parent 415e32d4
......@@ -4,4 +4,3 @@ data
localconfig
index.html
old-params.txt
extensions
......@@ -62,7 +62,7 @@ __END__
=head1 NAME
Bugzilla::Hook - Extendible extension hooks for Bugzilla code
Bugzilla::Hook - Extendable extension hooks for Bugzilla code
=head1 SYNOPSIS
......@@ -193,3 +193,36 @@ definitions. F<checksetup.pl> will automatically add these tables to the
database when run.
=back
=head2 webservice
This hook allows you to add your own modules to the WebService. (See
L<Bugzilla::WebService>.)
Params:
=over
=item C<dispatch>
A hashref that you can specify the names of your modules and what Perl
module handles the functions for that module. (This is actually sent to
L<SOAP::Lite/dispatch_with>. You can see how that's used in F<xmlrpc.cgi>.)
The Perl module name must start with C<extensions::yourextension::lib::>
(replace C<yourextension> with the name of your extension). The C<package>
declaration inside that module must also start with
C<extensions::yourextension::lib::> in that module's code.
Example:
$dispatch->{Example} = "extensions::example::lib::Example";
And then you'd have a module F<extensions/example/lib/Example.pm>
It's recommended that all the keys you put in C<dispatch> start with the
name of your extension, so that you don't conflict with the standard Bugzilla
WebService functions (and so that you also don't conflict with other
plugins).
=back
use strict;
use warnings;
use Bugzilla;
my $dispatch = Bugzilla->hook_args->{dispatch};
$dispatch->{Example} = "extensions::example::lib::WSExample";
package extensions::example::lib::WSExample;
use strict;
use warnings;
use base qw(Bugzilla::WebService);
# This can be called as Example.hello() from XML-RPC.
sub hello { return 'Hello!'; }
1;
......@@ -20,6 +20,7 @@ use lib qw(. lib);
use Bugzilla;
use Bugzilla::Constants;
use Bugzilla::Hook;
# Use an eval here so that runtests.pl accepts this script even if SOAP-Lite
# is not installed.
......@@ -29,11 +30,16 @@ $@ && ThrowCodeError('soap_not_installed');
Bugzilla->usage_mode(Bugzilla::Constants::USAGE_MODE_WEBSERVICE);
my %hook_dispatch;
Bugzilla::Hook::process('webservice', { dispatch => \%hook_dispatch });
local @INC = (bz_locations()->{extensionsdir}, @INC);
my $response = Bugzilla::WebService::XMLRPC::Transport::HTTP::CGI
->dispatch_with({'Bugzilla' => 'Bugzilla::WebService::Bugzilla',
'Bug' => 'Bugzilla::WebService::Bug',
'User' => 'Bugzilla::WebService::User',
'Product' => 'Bugzilla::WebService::Product',
%hook_dispatch
})
->on_action(\&Bugzilla::WebService::handle_login)
->handle;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment