Here's a patch (compiles but untested, I wasn't able to get Inline::Python
to install) that let's you set a PREFIX for Python code the way you would
for C/C++ code:
use Inline Python => DATA => PREFIX => 'my_';
print "9 + 16 = ", add(9, 16), "\n";
__END__
__Python__
def my_add(x,y):
return x + y
And also a patch that let's you apply a PREFIX to all your inlined code,
so:
use Inline Config => PREFIX => 'my_';
Though that really just passes the PREFIX on to Inline::C or Inline::Java
or Inline::Python and lets those modules handle it or croak, so maybe
there's a better way to implement it.
--- Inline-Python-0.11/Python.pm Mon Jan 29 09:29:37 2001
+++ Inline/Python.pm Fri Feb 9 04:03:45 2001
@@ -77,6 +77,11 @@
elsif ($key eq 'PRIVATE_PREFIXES') {
add_list($o->{Python}, $key, $value, []);
}
+ elsif ($key eq 'PREFIX') {
+ croak "Invalid value for 'PREFIX' option"
+ unless $value =~ /^[_a-zA-Z][_a-zA-Z0-9]*\z/;
+ $o->{Python}{PREFIX} = $value;
+ }
else {
croak "$key is not a valid config option for Python\n";
}
@@ -274,10 +279,14 @@
END
- for my $method ( @{$o->{Python}{namespace}{classes}{$class}}) {
+ my $prefix = qr/^\Q$o->{Python}{PREFIX}/;
+
+ for ( @{$o->{Python}{namespace}{classes}{$class}}) {
+ my $method = $_;
+ $method =~ s/$prefix//;
next if $method eq '__init__';
$s .= "sub $method {Inline::Python::_eval_python_method";
- $s .= "(__PACKAGE__,\"$method\",\@_)} ";
+ $s .= "(__PACKAGE__,\"$_\",\@_)} ";
}
eval $s;
--- Inline-0.31/Inline.pm Fri Feb 9 03:12:04 2001
+++ Inline.pm Fri Feb 9 04:07:43 2001
@@ -38,6 +38,7 @@
PRINT_VERSION => 0,
REPORTBUG => 0,
SITE_INSTALL => 0,
+ PREFIX => '',
};
#==============================================================================
@@ -305,6 +306,10 @@
if (ref $value and
ref $value ne 'ARRAY');
$value = [$value] unless ref $value;
+ }
+ elsif ($key eq 'PREFIX') {
+ $value = '' unless defined $value;
+ push @others, $key, $value;
}
$o->{config}{$key} = $value;
}
--- Inline-0.31/Inline.pod Fri Jan 19 01:21:16 2001
+++ Inline.pod Fri Feb 9 04:07:06 2001
@@ -308,6 +308,12 @@
Modules specified using the config form of C<WITH> will B<not> be automatically
required. You must C<use> them yourself.
+=head2 PREFIX
+
+Specifies a prefix that will be automatically stripped from functions when they are
+bound to Perl. So if the C or Python function is C<my_max()> and the prefix value is
+C<my_>, then this will get bound to the Perl subroutine C<max()>.
+
+ use Inline C => DATA => PREFIX => 'ZLIB_';
+
=head2 NOWARN
use Inline C => DATA => NOWARN => 1;
--
Tim Gim Yee
[EMAIL PROTECTED]