~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/bindings/swig/perl/native/Ra.pm

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:26:14 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205012614-qom4xfypgtsqc2xq
Tags: 1.2.3dfsg1-3ubuntu1
Merge with the final Debian release of 1.2.3dfsg1-3, bringing in
fixes to the clean target, better documentation of the libdb4.3
upgrade and build fixes to work with swig1.3_1.3.27.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
use strict;
 
2
use warnings;
 
3
 
 
4
package SVN::Ra;
 
5
use SVN::Base qw(Ra);
 
6
use File::Temp;
 
7
 
 
8
=head1 NAME
 
9
 
 
10
SVN::Ra - Subversion remote access functions
 
11
 
 
12
=head1 SYNOPSIS
 
13
 
 
14
    require SVN::Core;
 
15
    require SVN::Ra;
 
16
    my $ra = SVN::Ra->new ('file:///tmp/svmtest');
 
17
    print $ra->get_latest_revnum ();
 
18
 
 
19
 
 
20
=head1 DESCRIPTION
 
21
 
 
22
SVN::Ra wraps the object-oriented svn_ra_plugin_t functions.
 
23
 
 
24
=head1 SVN::Ra
 
25
 
 
26
=head2 CONSTRUCTOR - new (...)
 
27
 
 
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:
 
31
 
 
32
=over
 
33
 
 
34
=item url
 
35
 
 
36
=item auth
 
37
 
 
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.
 
41
 
 
42
=item pool
 
43
 
 
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.
 
46
 
 
47
=item config
 
48
 
 
49
The config hash that could be obtained by SVN::Core::config_get_config(undef).
 
50
 
 
51
=item callback
 
52
 
 
53
The ra_callback namespace to use. Default to SVN::Ra::Callback.
 
54
 
 
55
=back
 
56
 
 
57
=head2 METHODS
 
58
 
 
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.
 
62
 
 
63
=cut
 
64
 
 
65
require SVN::Client;
 
66
 
 
67
my $ralib = SVN::_Ra::svn_ra_init_ra_libs($SVN::Core::gpool);
 
68
 
 
69
# Ra methods that returns reporter
 
70
my %reporter = map { $_ => 1 } qw(do_diff do_switch do_status do_update);
 
71
our $AUTOLOAD;
 
72
 
 
73
sub AUTOLOAD {
 
74
    my $class = ref($_[0]);
 
75
    my $method = $AUTOLOAD;
 
76
    $method =~ s/.*:://;
 
77
    return unless $method =~ m/[^A-Z]/;
 
78
 
 
79
    my $self = shift;
 
80
    no strict 'refs';
 
81
 
 
82
    my $func = $self->{session}->can ($method)
 
83
        or die "no such method $method";
 
84
 
 
85
    my @ret = $func->($self->{session}, @_);
 
86
    return bless [@ret], 'SVN::Ra::Reporter' if $reporter{$method};
 
87
    return $#ret == 0 ? $ret[0] : @ret;
 
88
}
 
89
 
 
90
sub new {
 
91
    my $class = shift;
 
92
    my $self = bless {}, $class;
 
93
    %$self = $#_ ? @_ : (url => $_[0]);
 
94
 
 
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;
 
103
        }
 
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()]);
 
109
    }
 
110
 
 
111
    my $pool = $self->{pool} ||= SVN::Pool->new;
 
112
    my $callback = 'SVN::Ra::Callbacks';
 
113
 
 
114
    # custom callback namespace
 
115
    if ($self->{callback} && !ref($self->{callback})) {
 
116
        $callback = delete $self->{callback};
 
117
    }
 
118
    # instantiate callbacks
 
119
    $callback = (delete $self->{callback}) || $callback->new (auth => $self->{auth});
 
120
 
 
121
    $self->{session} = SVN::_Ra::svn_ra_open ($self->{url}, $callback, $self->{config} || {}, $pool);
 
122
    return $self;
 
123
}
 
124
 
 
125
sub DESTROY {
 
126
 
 
127
}
 
128
 
 
129
package _p_svn_ra_session_t;
 
130
use SVN::Base qw(Ra svn_ra_);
 
131
 
 
132
package SVN::Ra::Reporter;
 
133
use SVN::Base qw(Ra svn_ra_reporter2_);
 
134
 
 
135
=head1 SVN::Ra::Reporter
 
136
 
 
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.
 
141
 
 
142
=cut
 
143
 
 
144
our $AUTOLOAD;
 
145
sub AUTOLOAD {
 
146
    my $class = ref($_[0]);
 
147
    $AUTOLOAD =~ s/^${class}::(SUPER::)?//;
 
148
    return if $AUTOLOAD =~ m/^[A-Z]/;
 
149
 
 
150
    my $self = shift;
 
151
    no strict 'refs';
 
152
 
 
153
    my $method = $self->can("invoke_$AUTOLOAD")
 
154
        or die "no such method $AUTOLOAD";
 
155
 
 
156
    no warnings 'uninitialized';
 
157
    $method->(@$self, @_);
 
158
}
 
159
 
 
160
package SVN::Ra::Callbacks;
 
161
 
 
162
=head1 SVN::Ra::Callbacks
 
163
 
 
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.
 
167
 
 
168
=cut
 
169
 
 
170
require SVN::Core;
 
171
 
 
172
sub new {
 
173
    my $class = shift;
 
174
    my $self = bless {}, $class;
 
175
    %$self = @_;
 
176
    return $self;
 
177
}
 
178
 
 
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
 
186
    );
 
187
    return $fd;
 
188
}
 
189
 
 
190
sub get_wc_prop {
 
191
    return undef;
 
192
}
 
193
 
 
194
=head1 AUTHORS
 
195
 
 
196
Chia-liang Kao E<lt>clkao@clkao.orgE<gt>
 
197
 
 
198
=head1 COPYRIGHT
 
199
 
 
200
Copyright (c) 2003 CollabNet.  All rights reserved.
 
201
 
 
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.
 
207
 
 
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/.
 
211
 
 
212
=cut
 
213
 
 
214
1;