From 1958690969446048e65032df5a2287db2d84255e Mon Sep 17 00:00:00 2001 From: Anthony Molinaro Date: Thu, 1 Jul 2010 20:40:42 +0000 Subject: [PATCH] pass arguments through to Listeners for processing with Getopt::Long git-svn-id: https://lwes.svn.sourceforge.net/svnroot/lwes/lwes-perl/trunk@512 a2f82657-cdd2-4550-bd36-68a8e7111808 --- ChangeLog | 4 +++ LWES/Listeners/EventPrintingListener.pm | 10 ++++++ Makefile.PL | 2 +- lwes-perl-event-listener | 26 +++++++++++--- lwes-perl-journal-listener | 61 ++++++++++++++++++++++++++++++++- 5 files changed, 96 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index d8b804e..2e35640 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Version 0.4.0 (molinaro) + * Pass @ARGV as a reference to listener, so it can pull options from + command line + Version 0.3.1 (molinaro) * Header fields now consistent with 2 listener scripts * Journal listener now has stats diff --git a/LWES/Listeners/EventPrintingListener.pm b/LWES/Listeners/EventPrintingListener.pm index 36b8b42..f23ff52 100644 --- a/LWES/Listeners/EventPrintingListener.pm +++ b/LWES/Listeners/EventPrintingListener.pm @@ -7,6 +7,16 @@ use LWES::Listener; @LWES::Listeners::EventPrintingListener::ISA = qw(LWES::Listener); +sub initialize { +# possible contents of function +# my $self = shift; +# my $args = shift; +# if (defined ($args)) { +# my @ARGV = @{$args}; +# use Getopt::Long to parse additional command line options +# } +} + sub processEvent { my $self = shift; my $event = shift; diff --git a/Makefile.PL b/Makefile.PL index cf79186..6242d42 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -6,7 +6,7 @@ my $lwes_cflags = `$pkg_cfg pkg-config lwes-0 --cflags`; WriteMakefile( 'NAME' => 'LWES', - 'VERSION' => '0.3.1', + 'VERSION' => '0.4.0', 'EXE_FILES' => [ "lwes-perl-event-listener", "lwes-perl-journal-listener" ], 'PREREQ_PM' => { diff --git a/lwes-perl-event-listener b/lwes-perl-event-listener index e47b271..2cdb267 100644 --- a/lwes-perl-event-listener +++ b/lwes-perl-event-listener @@ -22,6 +22,8 @@ my $help_opt = 0; my $man_opt = 0; my $verbose_opt = 0; +Getopt::Long::Configure ("pass_through"); + GetOptions ( 'help' => \$help_opt, @@ -45,7 +47,7 @@ unless (defined($listener)) } # determine the callback which will process each event -my $processEventFunc = getProcessEventFunc ($listener, @ARGV); +my $processEventFunc = getProcessEventFunc ($listener, \@ARGV); unless (defined $rootdir) { @@ -206,14 +208,21 @@ follows (saved as Foo.pm) package Foo; use strict; + use warnings; + use Getopt::Long; @Foo::ISA = qw(LWES::Listener); sub initialize { my $self = shift; - - print "Bar : initialize with @_\n"; + my $args = shift; + if (defined ($args)) + { + my @ARGV = @{$args}; + # parse additional options + GetOptions ( ... ); + } } sub processEvent @@ -240,14 +249,21 @@ file should look like package LWES::Listeners::Bar; use strict; + use warnings; + use Getopt::Long; @LWES::Listeners::Bar::ISA = qw(LWES::Listener); sub initialize { my $self = shift; - - print "Bar : initialize with @_\n"; + my $args = shift; + if (defined ($args)) + { + my @ARGV = @{$args}; + # parse additional options + GetOptions ( ... ); + } } sub processEvent diff --git a/lwes-perl-journal-listener b/lwes-perl-journal-listener index 9827df9..a094e8f 100755 --- a/lwes-perl-journal-listener +++ b/lwes-perl-journal-listener @@ -14,6 +14,8 @@ my $man_opt = 0; my $verbose_opt = 0; my $stats_opt = 0; +Getopt::Long::Configure ("pass_through"); + GetOptions ( 'help' => \$help_opt, @@ -39,7 +41,7 @@ else } # determine the callback which will process each event -my $processEventFunc = getProcessEventFunc ($listener_or_code, @ARGV); +my $processEventFunc = getProcessEventFunc ($listener_or_code, \@ARGV); foreach my $journal (@ARGV) { @@ -99,3 +101,60 @@ foreach my $journal (@ARGV) } 0; + +__END__ + +=head1 NAME + +lwes-perl-journal-listener - listens for events from a journal + +=head1 SYNOPSIS + +lwes-perl-journal-listener [options] [ [] | ] + +Options: + --stats Print information about each file processed + -help Brief help message + -man Full Documentation + + is the name of a perl module which extends the base +listener LWES::Listener and provides an initialize and processEvent +method. The are passed directly to the listener constructor. + +code is perl code which is embedded in a function which takes one +argument, a reference to a perl hash which contains the contents +of the event called $event + +=head1 OPTIONS + +=over 8 + +=item B<--stats> + +Print information about how many events were processed and how long it took +to process. + +=item B<-help> + +Print help information + +=item B<-man> + +Print more verbose help information + +=back + +=head1 DESCRIPTION + +The lwes-perl-journal-listener is a tool for inspecting LWES events that +are in journal files created by the lwes-journaller. + +There are several ways to use the tool. To just print out events as they +are seen it can be invoked as + +% lwes-perl-journal-listener + +Alternatively you can provide a LWES::Listener module as outlined in +the lwes-perl-event-listener man page. + +=cut -- 2.11.4.GIT