Install subversion 1.4.6 + its perl bindings (for git-svn)
[git/jnareb-git.git] / lib / perl5 / site_perl / 5.8.8 / msys / SVN / Ra.pm
blob959f3da539ab65e98226bcb28bcd2f43c66822a5
1 use strict;
2 use warnings;
4 package SVN::Ra;
5 use SVN::Base qw(Ra);
6 use File::Temp;
8 =head1 NAME
10 SVN::Ra - Subversion remote access functions
12 =head1 SYNOPSIS
14 require SVN::Core;
15 require SVN::Ra;
16 my $ra = SVN::Ra->new ('file:///tmp/svmtest');
17 print $ra->get_latest_revnum ();
20 =head1 DESCRIPTION
22 SVN::Ra wraps the object-oriented svn_ra_plugin_t functions.
24 =head1 SVN::Ra
26 =head2 CONSTRUCTOR - new (...)
28 The method creates an RA object and calls C<open> for it. It takes a
29 hash array as parameter. if there's only one argument supplied, it's
30 used as the url. valid keys are:
32 =over
34 =item url
36 =item auth
38 An auth_baton could be given to the SVN::RA object. Default to a
39 auth_provider with a username_provider. See L<SVN::Client> for how to
40 create auth_baton.
42 =item pool
44 The pool for the ra session to use, and also the member functions will
45 be called with this pool. Default to a newly created root pool.
47 =item config
49 The config hash that could be obtained by SVN::Core::config_get_config(undef).
51 =item callback
53 The ra_callback namespace to use. Default to SVN::Ra::Callback.
55 =back
57 =head2 METHODS
59 Please consult the svn_ra.h section in the Subversion API. Member
60 functions of svn_ra_plugin_t could be called as methods of SVN::Ra
61 objects, with the session_baton and pool omitted.
63 =cut
65 require SVN::Client;
67 my $ralib = SVN::_Ra::svn_ra_init_ra_libs($SVN::Core::gpool);
69 # Ra methods that returns reporter
70 my %reporter = map { $_ => 1 } qw(do_diff do_switch do_status do_update);
71 our $AUTOLOAD;
73 sub AUTOLOAD {
74 my $class = ref($_[0]);
75 my $method = $AUTOLOAD;
76 $method =~ s/.*:://;
77 return unless $method =~ m/[^A-Z]/;
79 my $self = shift;
80 no strict 'refs';
82 my $func = $self->{session}->can ($method)
83 or die "no such method $method";
85 my @ret = $func->($self->{session}, @_);
86 return bless [@ret], 'SVN::Ra::Reporter' if $reporter{$method};
87 return $#ret == 0 ? $ret[0] : @ret;
90 sub new {
91 my $class = shift;
92 my $self = bless {}, $class;
93 %$self = $#_ ? @_ : (url => $_[0]);
95 if (defined($self->{auth})) {
96 if (ref($self->{auth}) ne '_p_svn_auth_baton_t') {
97 # If the auth is already set to a auth_baton ignore it
98 # otherwise make an auth_baton and store the callbacks
99 my ($auth_baton,$auth_callbacks) =
100 SVN::Core::auth_open_helper($self->{auth});
101 $self->{auth} = $auth_baton;
102 $self->{auth_provider_callbacks} = $auth_callbacks;
104 } else {
105 # no callback to worry about with a username provider so just call
106 # auth_open directly
107 $self->{auth} = SVN::Core::auth_open(
108 [SVN::Client::get_username_provider()]);
111 my $pool = $self->{pool} ||= SVN::Pool->new;
112 my $callback = 'SVN::Ra::Callbacks';
114 # custom callback namespace
115 if ($self->{callback} && !ref($self->{callback})) {
116 $callback = delete $self->{callback};
118 # instantiate callbacks
119 $callback = (delete $self->{callback}) || $callback->new (auth => $self->{auth});
121 $self->{session} = SVN::_Ra::svn_ra_open ($self->{url}, $callback, $self->{config} || {}, $pool);
122 return $self;
125 sub DESTROY {
129 package _p_svn_ra_session_t;
130 use SVN::Base qw(Ra svn_ra_);
132 package SVN::Ra::Reporter;
133 use SVN::Base qw(Ra svn_ra_reporter2_);
135 =head1 SVN::Ra::Reporter
137 the SVN::Ra methods: do_diff, do_status, do_switch, do_update, returns
138 a SVN::Ra::Reporter object as a wrapper of svn_ra_reporter_t. You can
139 use the member functions of it as methods of SVN::Ra::Reporter, with
140 the reporter_baton omitted.
142 =cut
144 our $AUTOLOAD;
145 sub AUTOLOAD {
146 my $class = ref($_[0]);
147 $AUTOLOAD =~ s/^${class}::(SUPER::)?//;
148 return if $AUTOLOAD =~ m/^[A-Z]/;
150 my $self = shift;
151 no strict 'refs';
153 my $method = $self->can("invoke_$AUTOLOAD")
154 or die "no such method $AUTOLOAD";
156 no warnings 'uninitialized';
157 $method->(@$self, @_);
160 package SVN::Ra::Callbacks;
162 =head1 SVN::Ra::Callbacks
164 This is the wrapper class for svn_ra_callback_t. To supply custom
165 callback to SVN::Ra, subclass this class and override the member
166 functions.
168 =cut
170 require SVN::Core;
172 sub new {
173 my $class = shift;
174 my $self = bless {}, $class;
175 %$self = @_;
176 return $self;
179 sub open_tmp_file {
180 local $^W; # silence the warning for unopened temp file
181 my ($self, $pool) = @_;
182 my ($fd, $name) = SVN::Core::io_open_unique_file(
183 ( File::Temp::tempfile(
184 'XXXXXXXX', OPEN => 0, DIR => File::Spec->tmpdir
185 ))[1], 'tmp', 1, $pool
187 return $fd;
190 sub get_wc_prop {
191 return undef;
194 =head1 AUTHORS
196 Chia-liang Kao E<lt>clkao@clkao.orgE<gt>
198 =head1 COPYRIGHT
200 Copyright (c) 2003 CollabNet. All rights reserved.
202 This software is licensed as described in the file COPYING, which you
203 should have received as part of this distribution. The terms are also
204 available at http://subversion.tigris.org/license-1.html. If newer
205 versions of this license are posted there, you may use a newer version
206 instead, at your option.
208 This software consists of voluntary contributions made by many
209 individuals. For exact contribution history, see the revision history
210 and logs, available at http://subversion.tigris.org/.
212 =cut