Chapter 7. Embedding

Please notice that using wxPerl inside an embedded program did not work until after version 0.20.

Using wxPerl inside a wxWidgets program

Running wxPerl code inside a wxWidgets program has some caveats. There are two senarios:

  1. a single long-running Perl interpreter
  2. multiple short-lived Perl interpreters
  3. multiple simultaneous Perl interpreters

Single long-running Perl interpreter

This section applies when the lifespan of the interpreter is the same as the application lifetime. There is no (known) caveat for this situation.

Multiple short-lived Perl interpreters

In this case a perl interpreter is continually constructed, used to run some code and then destroyed. The typuical structure of Perl code should be:

package MyFrame;

# ...

package MyApp;

# ...

package main;

my $app = MyApp->new;
$app->MainLoop;

This code can't rely on the usual rule that the main loop exits when no more windows are open, because the main application window will always be open! The code must manually keep track of when to exit.

For a single-window application this could be implemented as:

EVT_CLOSE( $frame,
           sub {
               my( $self, $event ) = @_;

               $Wx::wxTheApp->ExitMainLoop;
               $event->Skip;
           }
          );
  

.

Multiple simultaneous Perl interpreters

This is not supported, sorry.