Subject: FVWM: Module.pm to write module in perl.. documentation?

From: "Riswick, J.G.A. van" <[email-masked]>
Date: Fri, 24 May 2002 01:36:45 +0200

HI

In my fvwm setup I use a perl script that interacts with fvwm
using FvwmCommand. For instance, when the root menu pops up, 
I use a perl script to insert some items dynamically, like an 
entry 'Close connection' that kills wvdial when it is running. Now, 
sometimes, especially when a lot of applications are running,
this makes popping up the root menu rather slow. 

So I was wondering if it is any faster when I'd convert 
the perl script into a fvwm module. 
I stumbeled upon Module.pm. Is this meant to write fvwm 
modules in perl? Unfortunately, I can't find the documentation
for this interface. Where can I find this?

best regards

jos
--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Mikhael Goikhman <[email-masked]>
Date: Fri, 24 May 2002 20:11:32 +0000

> the perl script into a fvwm module. 

It depends on the implementation. You may do it in many ways. Using
PipeRead, FvwmCommand, using FvwmPerl (3 ways: eval, load and preprocess).
Even if you decide to create your own module you may do it differently.

(1) A module that creates a menu after receiving a request message.
(2) A module that watches a network and updates a menu when needed.

In (1) you don't spend time on watching network, but spend time when
opening a menu. In (2) you open a menu immediately, but the module works.

Anyway, if you have a persistent module you don't spend time to create
processes and initiate pipes on every menu change, this is done once.

> for this interface. Where can I find this?

Documentation will be available once the perl library API is finalized.
For example, I want to add the colorset structure and more.

Currently see the source of FvwmPerl and 4 example modules in perl at:
  ftp://ftp.fvwm.org/pub/fvwm/devel/sources/tests/perl/

--------------------------------------------------------------
Here is an implementation of your module using the method (1).

#!/usr/bin/perl -w
#
# Usage: run this module from StartFunction, then at any time execute:
#   SendToModule /path/to/MyMenuCreator create-menu

use lib `fvwm-config -p | tr -d '\n'`;
use FVWM::Module;

my $module = new FVWM::Module(
	Mask => M_STRING,
#	SyncMask => M_STRING,     # needed to process message synchronously
#	Name => "MyMenuCreator",  # needed for *MyMenuCreator: config value
#	EnableOptions => { q => sub { die "-q is not implemented yet" } },
);

$module->addHandler(M_STRING, sub {
	my $menuName = "MyRootMenu";
	$module->sendText("DestroyMenu $menuName");
	$module->sendText("AddToMenu   $menuName bla-bla Title");
	$module->sendText("+ 'Close connection' Exec killall wvdial")
		if grep "ppp0", `cat /proc/net/dev`;
});
$module->eventLoop;

--------------------------------------------------------------
Here is an implementation of your module using the method (2).

#!/usr/bin/perl -w

use lib `fvwm-config -p | tr -d '\n'`;
use FVWM::Module;

my $module = new FVWM::Module;

local $SIG{ALRM} = \&checkNetwork;
alarm(10);  # check every 10 seconds

sub checkNetwork {
	if (grep "ppp0", `cat /proc/net/dev`) {
		my $menuName = "MyRootMenu";
		$module->sendText("Beep");
	}
	alarm(10);
}
$module->eventLoop;

Regards,
Mikhael.