I've been playing around with an OO interface to some of the
SVN::Client perl module. Basically it takes the functions that take a
context argument and turns them into methods on a SVN::Client object.
This is VERY lightly tested, and probably has issues since my Perl
experience doesn't generally involve going in and messing with the
symbol table (which this does).
That said, the few things I've tried to seem to work, and I'm curious
if people thing this would be a good direction to move in.
-garrett
Index: Client.pm
===================================================================
--- Client.pm (revision 8018)
+++ Client.pm (working copy)
@@ -1,6 +1,46 @@
package SVN::Client;
use SVN::Base qw(Client svn_client_);
+sub new {
+ my ($class, %args) = @_;
+
+ my $ctx = SVN::_Client::new_svn_client_ctx_t ();
+
+ if ($args{auth}) {
+ $ctx->auth_baton ($args{auth});
+ } else {
+ my $auth
+ = SVN::Core::auth_open
([SVN::Client::get_simple_provider(),
+
SVN::Client::get_username_provider()]);
+ $ctx->auth_baton ($auth);
+ }
+
+ bless { ctx => $ctx }, $class;
+}
+
+sub auth {
+ my ($self, $arg) = @_;
+
+ $self->{ctx}->auth = $arg if $arg;
+
+ return $self->{ctx}->auth;
+}
+
+# XXX left off import for the time being, and most of these have not
been
+# tested at all...
+for (qw(checkout update switch add mkdir delete commit status log
blame diff
+ merge cleanup relocate revert resolved copy move propset
revprop_set
+ propget revprop_get proplist revprop_list export ls cat)) {
+ my $name = $_;
+
+ my $real_func = \&{"SVN::Client::$name"};
+
+ *{"SVN::Client::$name"} = sub {
+ my $self = shift;
+ $real_func->(@_, $self->{ctx});
+ }
+}
+
=head1 NAME
SVN::Client - Subversion client functions
@@ -9,27 +49,26 @@
require SVN::Core;
require SVN::Client;
- my $ctx = SVN::_Client::new_svn_client_ctx_t ();
- $ctx->auth_baton (SVN::Core::auth_open
- ([SVN::Client::get_simple_provider(),
- SVN::Client::get_username_provider()]));
+ my $auth
+ = SVN::Core::auth_open ([SVN::Client::get_simple_provider(),
+
SVN::Client::get_username_provider()]);
- SVN::Client::cat (\*STDOUT,
- 'http://svn.collab.net/repos/svn/trunk/README',
- 'HEAD', $ctx);
+ my $client = SVN::Client->new (auth => $auth);
+ $client->cat (\*STDOUT,
+ 'http://svn.collab.net/repos/svn/trunk/README',
+ 'HEAD');
+
=head1 DESCRIPTION
SVN::Client wraps the highest level of functions provided by
-subversion to accomplish specific tasks. Consult the svn_client.h
-section in the Subversion API. the svn_client_ctx_t object could be
-obtained as showed above in SYNOPSIS.
+subversion to accomplish specific tasks in an object oriented API.
Consult
+the svn_client.h section in the Subversion API. Any function that
takes a
+svn_client_ctx_t argument can be called as a method on the SVN::Client
+object, with arguments similar to the C API other than the
svn_client_ctx_t
+and pool, which are handled automatically.
-The author does not have much incentive to support SVN::Client, since
-the behavior is really just like what you can get from the
-command-line client - svn.
-
=cut
package _p_svn_client_commit_info_t;
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Dec 17 04:00:04 2003