Alien-SVN

 view release on metacpan or  search on metacpan

src/subversion/subversion/bindings/swig/perl/native/Core.pm  view on Meta::CPAN

    my $self = new(@_);
    $self->default;
    return $self;
}

sub default {
    my $self = shift;
    push @POOLSTACK, $SVN::_Core::current_pool
        unless $$SVN::_Core::current_pool == 0;
    $SVN::_Core::current_pool = $$self;
}

sub clear {
    my $self = shift;
    apr_pool_clear($$self);
}

my $globaldestroy;

END {
    $globaldestroy = 1;
}

my %WRAPPOOL;

# Create a cloned _p_apr_pool_t pointing to the same apr_pool_t
# but on different address. this allows pools that are from C
# to have proper lifetime.
sub _wrap {
    my ($class, $rawpool) = @_;
    my $pool = \$rawpool;
    bless $pool, '_p_apr_pool_t';
    my $npool = \$pool;
    bless $npool, $class;
    $WRAPPOOL{$npool} = 1;
    $npool;
}

use Scalar::Util 'reftype';

sub DESTROY {
    return if $globaldestroy;
    my $self = shift;
    # for some reason, REF becomes SCALAR in perl -c or after apr_terminate
    return if reftype($self) eq 'SCALAR';
    if ($$self eq $SVN::_Core::current_pool) {
        $SVN::_Core::current_pool = pop @POOLSTACK;
    }
    if (exists $WRAPPOOL{$self}) {
        delete $WRAPPOOL{$self};
    }
    else {
        apr_pool_destroy($$self)
    }
}

package _p_svn_error_t;
use SVN::Base qw(Core svn_error_t_);

sub strerror {
    return SVN::Error::strerror($_[$[]->apr_err());
}

sub handle_error {
    return SVN::Error::handle_error(@_);
}

sub expanded_message {
    return SVN::Error::expanded_message(@_);
}

sub handle_warning {
    # need to swap parameter order.
    return SVN::Error::handle_warning($_[$[+1],$_[$[]);
}

foreach my $function (qw(compose clear quick_wrap)) {
    no strict 'refs';
    my $real_function = \&{"SVN::_Core::svn_error_$function"};
    *{"_p_svn_error_t::$function"} = sub {
        return $real_function->(@_);
    }
}

package SVN::Error;
use SVN::Base qw(Core svn_error_);
use SVN::Base qw(Core SVN_ERR_);
use Carp;
our @CARP_NOT = qw(SVN::Base SVN::Client SVN::Core SVN::Delta
                   SVN::Delta::Editor SVN::Error SVN::Fs SVN::Node
                   SVN::Pool SVN::Ra SVN::Ra::Callbacks SVN::Ra::Reporter
                   SVN::Repos SVN::Stream SVN::TxDelta SVN::Wc);

=head2 svn_error_t - SVN::Error

By default the perl bindings handle exceptions for you.  The default handler
automatically croaks with an appropriate error message.  This is likely
sufficient for simple scripts, but more complex usage may demand handling of
errors.

You can override the default exception handler by changing the
$SVN::Error::handler variable.  This variable holds a reference to a perl sub
that should be called whenever an error is returned by a svn function.  This
sub will be passed a svn_error_t object.   Its return value is ignored.

If you set the $SVN::Error::handler to undef then each call will return an
svn_error_t object as its first return in the case of an error, followed by the
normal return values.  If there is no error then a svn_error_t will not be
returned and only the normal return values will be returned.  When using this
mode you should be careful only to call functions in array context.  For
example: my ($ci) = $ctx-E<gt>mkdir('http://svn/foo');  In this case $ci will
be an svn_error_t object if an error occurs and a svn_client_commit_info object
otherwise.  If you leave the parenthesis off around $ci (scalar context) it
will be the commit_info object, which in the case of an error will be undef.

If you plan on using explicit exception handling, understanding the exception
handling system the C API uses is helpful.  You can find information on it in
the HACKING file and the API documentation.  Looking at the implementation of
SVN::Error::croak_on_error and SVN::Error::expanded_message may be helpful as
well.

=over 4

=item $svn_error_t-E<gt>apr_err()

APR error value, possibly SVN_ custom error.

=item $svn_error_t-E<gt>message()

Details from producer of error.

=item $svn_error_t-E<gt>child()

svn_error_t object of the error that's wrapped.

src/subversion/subversion/bindings/swig/perl/native/Core.pm  view on Meta::CPAN


Add new_err to the end of $chain's chain of errors.

The $new_err chain will be copied into $chain's pool and destroyed, so $new_err
itself becomes invalid after this function.

=item SVN::Error::clear($svn_error_t); or $svn_error_t-E<gt>clear();

Free the memory used by $svn_error_t, as well as all ancestors and descendants
of $svn_error_t.

You must call this on every svn_error_t object you get or you will leak memory.

=cut

# Permit users to determine if they want automatic croaking or not.
our $handler = \&croak_on_error;

# Import functions that don't follow the normal naming scheme.
foreach my $function (qw(handle_error handle_warning strerror)) {
    no strict 'refs';
    my $real_function = \&{"SVN::_Core::svn_$function"};
    *{"SVN::Error::$function"} = sub {
        return $real_function->(@_);
    }
}

=item SVN::Error::expanded_message($svn_error_t) or $svn_error_t-E<gt>expanded_message()

Returns the error message by tracing through the svn_error_t object and its
children and concatenating the error messages.  This is how the internal
exception handlers get their error messages.

=cut

sub expanded_message {
    my $svn_error = shift;
    unless (is_error($svn_error)) {
        return undef;
    }

    my $error_message = $svn_error->strerror();
    while ($svn_error) {
        my $msg = $svn_error->message();
        $error_message .= ": $msg" if $msg;
        $svn_error = $svn_error->child();
    }
    return $error_message;
}


=item SVN::Error::is_error($value)

Returns true if value is of type svn_error.  Returns false if value is
anything else or undefined.  This is useful for seeing if a call has returned
an error.

=cut

sub is_error {
     return (ref($_[$[]) eq '_p_svn_error_t');
}

=item SVN::Error::croak_on_error

Default error handler.  It takes an svn_error_t and extracts the error messages
from it and croaks with those messages.

It can be used in two ways.  The first is detailed above as setting it as the
automatic exception handler via setting $SVN::Error::handler.

The second is if you have $SVN::Error::handler set to undef as a wrapper for
calls you want to croak on when there is an error, but you don't want to write
an explicit error handler. For example:

my $result_rev=SVN::Error::croak_on_error($ctx-E<gt>checkout($url,$path,'HEAD',1));

If there is no error then croak_on_error will return the arguments passed to it
unchanged.

=cut

sub croak_on_error {
    unless (is_error($_[$[])) {
      return @_;
    }
    my $svn_error = shift;

    my $error_message = $svn_error->expanded_message();

    $svn_error->clear();

    croak($error_message);
}

=item SVN::Error::confess_on_error

The same as croak_on_error except it will give a more detailed stack backtrace,
including internal calls within the implementation of the perl bindings.
This is useful when you are doing development work on the bindings themselves.

=cut

sub confess_on_error {
    unless (is_error($_[$[])) {
        return @_;
    }
    my $svn_error = shift;

    my $error_message = $svn_error->expanded_message();

    $svn_error->clear();

    confess($error_message);
}

=item SVN::Error::ignore_error

This is useful for wrapping around calls which you wish to ignore any potential
error.  It checks to see if the first parameter is an error and if it is it
clears it.  It then returns all the other parameters.

=back

=cut

sub ignore_error {
    if (is_error($_[$[])) {
        my $svn_error = shift;
        $svn_error->clear();
    }

    return @_;
}

package _p_svn_log_changed_path_t;
use SVN::Base qw(Core svn_log_changed_path_t_);

=head2 svn_log_changed_path_t

=over 4

=item $lcp-E<gt>action()

'A'dd, 'D'elete, 'R'eplace, 'M'odify

=item $lcp-E<gt>copyfrom_path()

Source path of copy, or C<undef> if there isn't any previous revision
history.

=item $lcp-E<gt>copyfrom_rev()

Source revision of copy, or C<$SVN::Core::INVALID_REVNUM> if there is
no previous history.

=back

=cut

package _p_svn_log_changed_path2_t;
use SVN::Base qw(Core svn_log_changed_path2_t_);

=head2 svn_log_changed_path2_t

An object to represent a path that changed for a log entry.

=over 4

=item $lcp-E<gt>action()

'A'dd, 'D'elete, 'R'eplace, 'M'odify

=item $lcp-E<gt>copyfrom_path()

Source path of copy, or C<undef> if there isn't any previous revision
history.

=item $lcp-E<gt>copyfrom_rev()

Source revision of copy, or C<$SVN::Core::INVALID_REVNUM> if there is
no previous history.

=item $lcp-E<gt>node_kind()

The type of the node, a C<$SVN::Node> enum; may be C<$SVN::Node::unknown>.

=item $lcp-E<gt>text_modified()



( run in 0.550 second using v1.01-cache-2.11-cpan-99c4e6809bf )