Gimp
view release on metacpan or search on metacpan
lib/Gimp/Extension.pm view on Meta::CPAN
my ($listen_socket, $handler, $on_accept) = @_;
Glib::IO->add_watch(fileno($listen_socket), 'in', sub {
my ($fd, $condition, $fh) = @_;
my $h = $fh->accept;
$on_accept->($h) if $on_accept;
$h->autoflush;
Glib::IO->add_watch(fileno($h), 'in', sub {
my ($fd, $condition, $h) = @_;
undef $h if not $handler->(@_);
$h ? &Glib::SOURCE_CONTINUE : &Glib::SOURCE_REMOVE;
}, $h);
&Glib::SOURCE_CONTINUE;
}, $listen_socket);
}
sub register_temp ($$$$$$$&) { push @temp_procs, [ @_ ]; }
sub podregister_temp {
my ($tfunction, $tcallback) = @_;
my $pod = Gimp::Pod->new;
my ($t) = grep { /^$tfunction\s*-/ } $pod->sections($TP);
croak "No POD found for temporary procedure '$tfunction'" unless $t;
my ($tblurb) = $t =~ m#$tfunction\s*-\s*(.*)#;
my $thelp = $pod->section($TP, $t);
my $tmenupath = $pod->section($TP, $t, 'SYNOPSIS');
my $timagetypes = $pod->section($TP, $t, 'IMAGE TYPES');
my $tparams = $pod->section($TP, $t, 'PARAMETERS');
my $tretvals = $pod->section($TP, $t, 'RETURN VALUES');
($tfunction, $tmenupath, $timagetypes, $tparams, $tretvals) = (fixup_args(
$tfunction, ('fake') x 5, $tmenupath, $timagetypes,
($tparams || '#'), ($tretvals || '#'), 1
))[0, 6..9];
push @temp_procs, [
$tfunction, $tblurb, $thelp, $tmenupath, $timagetypes,
$tparams, $tretvals, $tcallback,
];
}
1;
__END__
=head1 NAME
Gimp::Extension - Easy framework for Gimp-Perl extensions
=head1 SYNOPSIS
use Gimp;
use Gimp::Fu; # necessary for variable insertion and param constants
use Gimp::Extension;
podregister {
# your code
};
exit main;
__END__
=head1 NAME
function_name - Short description of the function
=head1 SYNOPSIS
<Image>/Filters/Menu/Location...
=head1 DESCRIPTION
Longer description of the function...
=head1 DESCRIPTION
This module provides all the infrastructure you need to write Gimp-Perl
extensions.
Your main interface for using C<Gimp::Extension> is the C<podregister>
function. This works in exactly the same way as L<Gimp::Fu/PODREGISTER>,
including declaring/receiving your variables for you.
Before control is passed to your function, these procedures are called:
Gimp::gtk_init; # sets up Gtk2, ready for event loop
Gimp->extension_ack; # GIMP hangs till this is called
Gimp->extension_enable; # adds an event handler in Glib mainloop for
# GIMP messages
Your function will then either proceed as if it were a plugin, or call
the Glib/Gtk2 mainloop:
Gtk2->main;
Values returned by your function will still be returned to a caller,
as with a plugin.
One benefit of being an extension vs a plugin is that you can keep
running, installing temporary procedures which are called by the user.
When they are called, the perl function you have registered will be
called, possibly accessing your persistent data or at least benefiting
from the fact that you have already started up.
Another benefit is that you can respond to events outside of GIMP,
such as network connections (this is how the Perl-Server is implemented).
Additionally, if no parameters are specified, then the extension will
be started as soon as GIMP starts up. Make sure you specify menupath
<None>, so no parameters will be added for you.
If you need to clean up on exit, just register a callback with
C<Gimp::on_quit>. This is how C<Perl-Server> removes its Unix-domain
socket on exit.
=head1 FUNCTIONS AVAILABLE TO EXTENSIONS
These are all exported by default.
=head2 podregister
As discussed above.
=head2 add_listener
This is a convenience wrapper around C<Glib::IO-E<gt>add_watch>. It
takes parameters:
=over 4
( run in 0.558 second using v1.01-cache-2.11-cpan-39bf76dae61 )