1package SVN::Base; 2 3=head1 NAME 4 5SVN::Base - Base class for importing symbols for svn modules 6 7=head1 SYNOPSIS 8 9 # Load the svn_ra_* functions into the SVN::Ra namespace. 10 package SVN::Ra; 11 use SVN::Base qw(Ra svn_ra_); 12 13 # Load svn_config_t structure accessors in the magic namcespace 14 # provided by swig, so we could use it returned by other functions 15 package _p_svn_config_t; 16 use SVN::Base qw(Core svn_config_); 17 18=head1 DESCRIPTION 19 20SVN::Base is a module importing the subversion perl bindings raw 21symbols created by swig, into proper namespace and make them easier to 22use. 23 24It will also find the accessors for members of a C struct, create an 25simpler accessor function like C<$data-E<gt>field()> and 26C<$data-E<gt>field($new_value)>. 27 28Once you understand the convention of subversion functions in perl 29bindings, you could look at the subversion api and write them in perl. 30The API is available in the source header files or online at 31L<https://subversion.apache.org/docs/api/latest/>. 32 33=head1 INTERNALS 34 35The perl bindings of swig wraps raw functions into different perl 36modules, for example, SVN::_Core, SVN::_Repos. Upon import, SVN::Base 37bootstrap the requested module if it's not yet loaded, and iterate 38over the symbols provided in that module, it them puts the function 39with prefix trimmed in the namespace of the caller for this import. 40 41The 3rd through the last parameter is a list of symbol endings that 42you wish for SVN::Base not to import into your namespace. This is useful 43for cases where you may want to import certain symbols differently than 44normally. 45 46=head1 CAVEATS 47 48SVN::Base consider a function as structure member accessor if it is 49postfixed ``_get'' or ``_set''. Real functions with this postfixes 50will need extra handling. 51 52=cut 53 54sub import { 55 my (undef, $pkg, $prefix, @ignore) = @_; 56 no warnings 'uninitialized'; 57 unless (${"SVN::_${pkg}::ISA"}[0] eq 'DynaLoader') { 58 @{"SVN::_${pkg}::ISA"} = qw(DynaLoader); 59 eval qq' 60package SVN::_$pkg; 61require DynaLoader; 62bootstrap SVN::_$pkg; 631; 64 ' or die $@; 65 }; 66 67 my $caller = caller(0); 68 69 my $prefix_re = qr/(?i:$prefix)/; 70 my $ignore_re = join('|', @ignore); 71 for (keys %{"SVN::_${pkg}::"}) { 72 my $name = $_; 73 next unless s/^$prefix_re//; 74 next if $ignore_re && m/$ignore_re/; 75 76 # insert the accessor 77 if (m/(.*)_get$/) { 78 my $member = $1; 79 *{"${caller}::$1"} = sub { 80 &{"SVN::_${pkg}::${prefix}${member}_". 81 (@_ > 1 ? 'set' : 'get')}(@_) 82 } 83 } 84 elsif (m/(.*)_set$/) { 85 } 86 else { 87 *{"${caller}::$_"} = ${"SVN::_${pkg}::"}{$name}; 88 } 89 } 90 91} 92 93=head1 AUTHORS 94 95Chia-liang Kao E<lt>clkao@clkao.orgE<gt> 96 97=head1 COPYRIGHT 98 99 Licensed to the Apache Software Foundation (ASF) under one 100 or more contributor license agreements. See the NOTICE file 101 distributed with this work for additional information 102 regarding copyright ownership. The ASF licenses this file 103 to you under the Apache License, Version 2.0 (the 104 "License"); you may not use this file except in compliance 105 with the License. You may obtain a copy of the License at 106 107 http://www.apache.org/licenses/LICENSE-2.0 108 109 Unless required by applicable law or agreed to in writing, 110 software distributed under the License is distributed on an 111 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 112 KIND, either express or implied. See the License for the 113 specific language governing permissions and limitations 114 under the License. 115 116=cut 117 1181; 119