[perl-Glib-Object-Introspection] Allow users to correct sub names
- From: Torsten Schönfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Glib-Object-Introspection] Allow users to correct sub names
- Date: Sat, 17 Apr 2010 18:08:53 +0000 (UTC)
commit f63cd2c86b381f15f239055fc99ffafc5fc7700b
Author: Torsten Schönfeld <kaffeetisch gmx de>
Date: Sat Apr 17 20:05:10 2010 +0200
Allow users to correct sub names
Let users pass in a hash specifying corrections for automatically chosen sub
names. To make this possible, unify the treatment of global and namespaced
functions by using the empty string for the namespace of global functions.
GObjectIntrospection.xs | 7 +++++--
lib/Glib/Object/Introspection.pm | 29 ++++++++++++++++-------------
2 files changed, 21 insertions(+), 15 deletions(-)
---
diff --git a/GObjectIntrospection.xs b/GObjectIntrospection.xs
index 8ceda9e..c2a3a49 100644
--- a/GObjectIntrospection.xs
+++ b/GObjectIntrospection.xs
@@ -1249,8 +1249,11 @@ register_types (class, namespace, version, package)
g_base_info_unref ((GIBaseInfo *) info);
}
- EXTEND (SP, 2);
- PUSHs (sv_2mortal (newRV_noinc ((SV *) global_functions)));
+ /* Use the empty string as the key to indicate "no namespace". */
+ gperl_hv_take_sv (namespaced_functions, "", 0,
+ newRV_noinc ((SV *) global_functions));
+
+ EXTEND (SP, 1);
PUSHs (sv_2mortal (newRV_noinc ((SV *) namespaced_functions)));
void
diff --git a/lib/Glib/Object/Introspection.pm b/lib/Glib/Object/Introspection.pm
index a36d8a1..5d8df41 100644
--- a/lib/Glib/Object/Introspection.pm
+++ b/lib/Glib/Object/Introspection.pm
@@ -30,24 +30,27 @@ sub setup {
my $basename = $params{basename};
my $version = $params{version};
my $package = $params{package};
+ my $name_corrections = $params{name_corrections} || {};
- my ($global_functions, $namespaced_functions) =
+ my $functions =
__PACKAGE__->register_types($basename, $version, $package);
no strict 'refs';
- foreach my $name (@{$global_functions}) {
- # warn "${package}::$name => $name\n";
- *{$package . '::' . $name} = sub {
- __PACKAGE__->invoke($basename, undef, $name, @_);
- };
- }
-
- foreach my $namespace (keys %{$namespaced_functions}) {
- foreach my $name (@{$namespaced_functions->{$namespace}}) {
- # warn "${package}::${namespace}::$name => $name\n";
- *{$package . '::' . $namespace . '::' . $name} = sub {
- __PACKAGE__->invoke($basename, $namespace, $name, @_);
+ foreach my $namespace (keys %{$functions}) {
+ my $is_namespaced = $namespace ne "";
+ foreach my $name (@{$functions->{$namespace}}) {
+ my $auto_name = $is_namespaced
+ ? $package . '::' . $namespace . '::' . $name
+ : $package . '::' . $name;
+ my $corrected_name = exists $name_corrections->{$auto_name}
+ ? $name_corrections->{$auto_name}
+ : $auto_name;
+ *{$corrected_name} = sub {
+ __PACKAGE__->invoke($basename,
+ $is_namespaced ? $namespace : undef,
+ $name,
+ @_);
};
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]