#!/usr/local/bin/perl # RCS: $Id: QuExample.pm,v 1.3 2000/09/30 17:42:18 grimaldo Rel $ #------------------------------------------------------------------------ # QuExample.pm (c)1996,1999 D. Emilio Grimaldo Tunon #------------------------------------------------------------------------ # AUTHOR: D. Emilio Grimaldo T. grimaldo@panama.iaehv.nl # DESCRIPTION: # A simple example of plug-in handlers for Quotes. This makes # it easy to roll your own handlers for third party information # providers. Just make sure you've got the RegExp Wizard's # book. # Any user-defined handler must be a proper module AND it # must contain two methods: 'SetRequest' and 'Decode' preceeded # by the name of the module (as in the 'package' directive). # The following Quotes' methods may be useful here: # &main::Status() Print an informative message # &main::DbgStatus() Same as Status if --debug set # &main::Squeal() Same as Status but prepended with # "WARN #errno" # &main::Qwack() Same as Squeal but exits with an # error code # $plain = &main::QuRemoveHtmlTags() # $urlenc= &main::QuUrl('url', 'urltext') # # METHODS: # QuExampleSetRequest(\$host, \$file) # QuExampleSetOptions() # QuExampleDecode(\@html_data) require 5.001; package QuExample; use Exporter; @ISA = qw(Exporter); @EXPORT = qw(QuExampleSetRequest QuExampleSetOptions QuExampleDecode); use strict; # ********* CONFIGURATION SECTION ********* # ********* ********************* ********* # ********** LOCAL DATA SECTION ********** my $VERSION; my $hostname; # ********* ********************* ********* BEGIN { # This is always invoked when the module is loaded. $VERSION = '$Revision: 1.3 $'; $VERSION =~ m/Revision: (\d+\.\d+\.*\d*\.*\d*)/; $VERSION = $1; $hostname = `hostname`; chomp($hostname); } # QuExampleSetRequest # Here we set the request parameters to be used by Quotes in # generating a valid URL. This is always invoked first ( # PARAMETERS # rHost OUT ScalarRef Host/IP number to connect to (without http://) # rFile OUT ScalarRef File name (rest of the URL) sub QuExampleSetRequest { my $rHost = shift; my $rFile = shift; $$rHost = $hostname; if ($hostname eq 'panama.iaehv.nl') { $$rFile = '~www/motd/etech.txt'; } else { $$rHost = 'www.coralys.com'; $$rFile = 'news.shtml'; } # $$rFile = '~grimaldo/prodinfo.txt'; # We can invoke Quote's API using the 'main' package domain. &main::Status("QuExampleSetRequest: $$rHost:$$rFile"); return 1; } # QuExampleSetOptions # This is the second method called. If there are any arguments # left in @ARGV then it gets invoked. This function must use # &main::GetOptions() to get the remaining options from @ARGV # if we are really interested in them, otherwise do nothing. sub QuExampleSetOptions { print "There are $#ARGV arguments left\n"; } # QuExampleDecode # Called by Quotes once the data has been retrieved, it is then # passed to this method as a reference to an array. The arrays # contains each and every line of the headers+body of the retrieved # document in whatever format it comes (HTML, plain text...) # with trailing CR/LF stripped # PARAMETERS # rHeaders IN ArrayRef All HTTP headers # rBody IN ArrayRef Body of the retrieved document sub QuExampleDecode { my $rHeaders = shift; my $rBody = shift; my $i; print "QuExampleDecode\n"; foreach $i (0.. $#$rHeaders) { print " HEADER: $$rHeaders[$i]\n"; } foreach $i (0.. $#$rBody) { $$rBody[$i] = &main::QuRemoveHtmlTags($$rBody[$i]); print " BODY: $$rBody[$i]\n"; } } END { # This is always invoked when the module is ended. print "QuExample module ended\n"; } 1;