[gimp-perl] Move auto-add of params to Gimp::Pod::fixup_args.
- From: Ed J <edj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp-perl] Move auto-add of params to Gimp::Pod::fixup_args.
- Date: Tue, 20 May 2014 03:56:44 +0000 (UTC)
commit c658592fe33d307ea64129c990f60cdb8c72a8b9
Author: Ed J <edj src gnome org>
Date: Tue May 20 04:56:31 2014 +0100
Move auto-add of params to Gimp::Pod::fixup_args.
Gimp/Fu.pm | 50 ++------------------------------------------------
Gimp/Pod.pm | 43 ++++++++++++++++++++++++++++++++++++++++++-
t/extension.t | 4 ++--
3 files changed, 46 insertions(+), 51 deletions(-)
---
diff --git a/Gimp/Fu.pm b/Gimp/Fu.pm
index dd35038..c04efd6 100644
--- a/Gimp/Fu.pm
+++ b/Gimp/Fu.pm
@@ -96,21 +96,10 @@ my %pf2info = map {
my $v = $pfname2info{$_}; ($v->[0] => [ @$v[1..3] ])
} keys %pfname2info;
-my @image_params = ([PF_IMAGE, "image", "Input image"],
- [PF_DRAWABLE, "drawable", "Input drawable", '%a']);
-my @load_params = ([PF_STRING, "filename", "Filename"],
- [PF_STRING, "raw_filename", "User-given filename"]);
-my @save_params = (@image_params, @load_params);
-my $image_retval = [PF_IMAGE, "image", "Output image"];
-my %IND2SECT = (
- 2 => 'DESCRIPTION', 3 => 'AUTHOR', 4 => 'LICENSE',
- 5 => 'DATE', 6 => 'SYNOPSIS', 7 => 'IMAGE TYPES',
-);
-
my $podreg_re = qr/(\bpodregister\s*{)/;
FILTER {
return unless /$podreg_re/;
- my $myline = make_arg_line(insert_params(fixup_args(('') x 9, 1)));
+ my $myline = make_arg_line(fixup_args(('') x 9, 1));
s/$podreg_re/$1\n$myline/;
warn __PACKAGE__."::FILTER: found: '$1'" if $Gimp::verbose >= 2;
};
@@ -287,46 +276,11 @@ Gimp::on_query {
}
};
-sub insert_params {
- my @p = @_;
- die __<<EOF unless $p[6] =~ /^<(?:Image|Load|Save|Toolbox|None)>/;
-Menupath must start with <Image>, <Load>, <Save>, <Toolbox>, or <None>!
-(got '$p[6]')
-EOF
- if ($p[6] =~ /^<Image>\//) {
- if ($p[7]) {
- unshift @{$p[8]}, @image_params;
- } else {
- # undef or ''
- unshift @{$p[9]}, $image_retval
- if ! {$p[9]} or $p[9]->[0]->[0] != PF_IMAGE;
- }
- } elsif ($p[6] =~ /^<Load>\//) {
- my ($start, $label, $fileext, $prefix) = split '/', $p[6];
- $prefix = '' unless $prefix;
- Gimp::on_query { Gimp->register_load_handler($p[0], $fileext, $prefix); };
- $p[6] = join '/', $start, $label;
- unshift @{$p[8]}, @load_params;
- unshift @{$p[9]}, $image_retval;
- } elsif ($p[6] =~ /^<Save>\/(.*)/) {
- my ($start, $label, $fileext, $prefix) = split '/', $p[6];
- $prefix = '' unless $prefix;
- Gimp::on_query { Gimp->register_save_handler($p[0], $fileext, $prefix); };
- $p[6] = join '/', $start, $label;
- unshift @{$p[8]}, @save_params;
- } elsif ($p[6] =~ m#^<Toolbox>/Xtns/#) {
- undef $p[7];
- } elsif ($p[6] =~ /^<None>/) {
- undef $p[6]; undef $p[7];
- }
- @p;
-}
-
sub podregister (&) { unshift @_, ('') x 9; goto ®ister; }
sub register($$$$$$$$$;@) {
no strict 'refs';
my ($function, $blurb, $help, $author, $copyright, $date, $menupath,
- $imagetypes, $params, $results, $code) = insert_params(fixup_args(@_));
+ $imagetypes, $params, $results, $code) = fixup_args(@_);
$function="perl_fu_".$function unless $function =~ /^(?:perl_fu_|extension_|plug_in_|file_)/ || $function
=~ s/^\+//;
$function=~/^[0-9a-z_]+(-ALT)?$/ or carp(__"$function: function name contains unusual characters, good
style is to use only 0-9, a-z and _");
diff --git a/Gimp/Pod.pm b/Gimp/Pod.pm
index 6b9489b..226d52a 100644
--- a/Gimp/Pod.pm
+++ b/Gimp/Pod.pm
@@ -69,6 +69,47 @@ sub section {
$text;
}
+sub lazy_image_params { ([&Gimp::PDB_IMAGE, "image", "Input image"],
+ [&Gimp::PDB_DRAWABLE, "drawable", "Input drawable", '%a']); }
+sub lazy_load_params { ([&Gimp::PDB_STRING, "filename", "Filename"],
+ [&Gimp::PDB_STRING, "raw_filename", "User-given filename"]); }
+sub lazy_save_params { (&lazy_image_params, &lazy_load_params); }
+sub lazy_image_retval { [&Gimp::PDB_IMAGE, "image", "Output image"]; }
+sub insert_params {
+ my @p = @_;
+ die __<<EOF unless $p[6] =~ /^<(?:Image|Load|Save|Toolbox|None)>/;
+Menupath must start with <Image>, <Load>, <Save>, <Toolbox>, or <None>!
+(got '$p[6]')
+EOF
+ if ($p[6] =~ /^<Image>\//) {
+ if ($p[7]) {
+ unshift @{$p[8]}, &lazy_image_params;
+ } else {
+ # undef or ''
+ unshift @{$p[9]}, &lazy_image_retval
+ if ! {$p[9]} or $p[9]->[0]->[0] != &Gimp::PDB_IMAGE;
+ }
+ } elsif ($p[6] =~ /^<Load>\//) {
+ my ($start, $label, $fileext, $prefix) = split '/', $p[6];
+ $prefix = '' unless $prefix;
+ Gimp::on_query { Gimp->register_load_handler($p[0], $fileext, $prefix); };
+ $p[6] = join '/', $start, $label;
+ unshift @{$p[8]}, &lazy_load_params;
+ unshift @{$p[9]}, &lazy_image_retval;
+ } elsif ($p[6] =~ /^<Save>\/(.*)/) {
+ my ($start, $label, $fileext, $prefix) = split '/', $p[6];
+ $prefix = '' unless $prefix;
+ Gimp::on_query { Gimp->register_save_handler($p[0], $fileext, $prefix); };
+ $p[6] = join '/', $start, $label;
+ unshift @{$p[8]}, &lazy_save_params;
+ } elsif ($p[6] =~ m#^<Toolbox>/Xtns/#) {
+ undef $p[7];
+ } elsif ($p[6] =~ /^<None>/) {
+ undef $p[6]; undef $p[7];
+ }
+ @p;
+}
+
my %IND2SECT = (
2 => 'DESCRIPTION', 3 => 'AUTHOR', 4 => 'LICENSE',
5 => 'DATE', 6 => 'SYNOPSIS', 7 => 'IMAGE TYPES',
@@ -102,7 +143,7 @@ sub fixup_args {
carp __"$p[0]: argument name '$val->[1]' contains illegal characters, only 0-9, a-z and _ allowed"
unless $val->[1]=~/^[0-9a-z_]+$/;
}
- @p;
+ insert_params(@p);
}
sub make_arg_line {
diff --git a/t/extension.t b/t/extension.t
index 92f4686..6643866 100644
--- a/t/extension.t
+++ b/t/extension.t
@@ -16,7 +16,7 @@ use Gimp;
use Gimp::Extension;
podregister {
- $num + 1;
+ (0, $num + 1);
};
exit main;
@@ -58,7 +58,7 @@ EOF
}
use Gimp "net_init=spawn/";
-is(Gimp::Plugin->extension_test(Gimp::RUN_NONINTERACTIVE, 7), 8, 'return val');
+is((Gimp::Plugin->extension_test(7))[1], 8, 'return val');
Gimp::Net::server_quit;
Gimp::Net::server_wait;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]