##
############################################################################################
# Name the package.
package ExNet::General;
# Append to the @INC array.
use lib qw( @INC H:/SITES/emcb/lib/perl5 );
# Load other needed modules.
#use Archive::Tar;
#use Cwd;
use Digest::MD5 qw( md5 );
use strict;
use warnings;
# Setup the OO interface
#our $tar = Archive::Tar->new();
# Require the Exporter.
require Exporter;
# Set @ISA and the subs loaded by default.
our @ISA = qw( Exporter );
our @EXPORT_OK = qw( printNav returnRef getURLS_File returnPasswd errorDie errorWarn );
our $VERSION = '0.1a';
# Need to add these functions: OpenLog CreateLog FlushLog;
# OpenLog: Open a log for writing.
# CreateLog: Create a new log.
# FlushLog: Empty the log and tar' it up.
# General module for ExNet trivial functions like returning a MD5
# sum of a string, Creating new logs, Flushing logs to an archive
# and so on... Just general stuff.
# PRIVATE_ENV:
# This environment hash is private to this package, and only
# methods belonging to this package can access it.
our %PRIVATE_ENV = (
'EXNET_SERVER_ROOT' => 'H:/SITES/emcb',
'EXNET_DOCUMENT_ROOT' => 'sites/exnet.emcb.co.uk/public_html',
'EXNET_CGI_ROOT' => 'sites/exnet.emcb.co.uk/cgi-local',
'EXNET_CGI_ENGINE' => 'sites/exnet.emcb.co.uk/cgi-local/exnet.pl',
'EXNET_LOG_ROOT' => 'sites/exnet.emcb.co.uk',
'EXNET_ERRORLOG_NAME' => 'exnet.general.error_log',
);
# GLOBAL_ENV:
# This environment is public and can be accessed via a referrence.
our %GLOBAL_ENV = (
'EXNET_SERVER_NAME' => 'EMCBi ExtraNet Server',
'EXNET_URLS_FILE' => 'sites/exnet.emcb.co.uk/urls.txt',
'EXNET_HTTP_HEADER' => 'text/html',
'EXNET_FONT_FAMILY' => 'Verdana,Arial,Helvetica,Geneva',
'EXNET_TEXT_COLOUR' => '#000000',
'EXNET_NLINK_COLOUR' => '#000099',
'EXNET_HLINK_COLOUR' => '#0066FF',
);
# Setup the local referrences to the PRIVATE/GLOBAL_ENV hashes.
# Parse the @urls and @titles in referrences.
our $PENV = \%PRIVATE_ENV;
our $GENV = \%GLOBAL_ENV;
# ---------------------------------------------------------------------------------------- #
# Begin Exported Methods #
# ---------------------------------------------------------------------------------------- #
#->new
# ExNet::General constructor
sub new
{
my $class = shift;
my $self = {};
my %OPTIONS = @ARG;
bless( $self, $class );
return $self;
}
#->returnRef
# ExNet::General hash-referrence returner
sub returnRef
{
my $packname = $_[0];
if( !$packname )
{
return 0;
}
if( $packname == "GLOBAL" )
{
return $ExNet::General::GENV;
}
else
{
return 0;
}
}
#->getURLS_File
# ExNet::General Parse the URLS file
sub getURLS_File
{
my( $names,$links ) = @_;
if( $names==0 || "" or $links==0 || "" )
{
errorDie("You did not specify a referrence to the names/links array. See \'perldoc ExNet::General\' for help.
\n");
}
else
{
my $HOME = $PENV->{'EXNET_SERVER_ROOT'},"/";
open( URLSFILE, $PENV->{'EXNET_URLS_FILE'} ) || errorDie("Could not open the URLS_File: $!
\n";
my $line = 0;
my( $title,$url,@titles,@urls );
URLS: while( )
{
next URLS if /^#/;
( $title,$url ) = split(/|/);
$names->[$line] = $title;
$titles->[$line] = $url;
}
}
}
#->printNav
# ExNet::General Print Out The Navigation Bar
sub printNav
{
my( $names,$links ) = @_;
if( $names==0 || "" or $links==0 || "" )
{
errorDie("You did not specify a referrence to the names/links array. See \'perldoc ExNet::General\' for help.
\n");
}
else
{
if( $names->[-1] == $links->[-1] and my( $count ) == $names->[-1] )
{
my( $i );
print "\n\n
{'EXNET_FONT_FAMILY'},"\" size=\"2\">\n";
for( $i=0; $i<=$count; $i++ )
{
print "[[$i],"\" class=\"NavBar\" onMouseover=\"setStatBar(\'",$names->[$i],"\'); return true;\">",$names->[$i],"] \n";
}
print " {'EXNET_FONT_FAMILY'},"\" size=\"2\" color=\"#FFFFFF\">
EMCBi ExtraNet Server » PAGE
\n";
}
else
{
errorDie("There are not an equal amount of array keys. See \'perldoc ExNet::General\' for help.
\n");
}
}
}
#->returnPasswd
# ExNet::General MD5 Checksum Generator
sub returnPasswd
{
my( $password ) = @_;
if( $password==0 || "" )
{
errorDie("You did not parse a string to function function: returnPasswd(); See \'perldoc ExNet::General\' for help.
\n");
}
else
{
$password = md5( $password );
return $password;
}
}
#->errorWarn
# ExNet::General Warn() Handler
sub errorWarn
{
my( $error ) = $_[0];
print $error;
}
#->errorDie
# ExNet::General Die() Handler
sub errorDie
{
my( $error ) = $_[0];
print $error;
exit(0);
}
1;
__END__
# ---------------------------------------------------------------------------------------- #
# END Exported Methods - Begin POD #
# ---------------------------------------------------------------------------------------- #
=head1 TITLE
ExNet::General
=head1 NAME
ExNet::General - General functions for the ExtraNet Server
=head1 SYNOPSIS
use ExNet::General;
$gen = new ExNet::General;
$gen->returnPasswd( "foobar" );
=head1 DESCRIPTION
This module implements the General functions.
At the moment these methods are supported:
=item C
Returns a new General object
=item C
Returns a referrence to the GLOBAL_ENV hash, allowing the user to view/edit it's values.
It's second argument must be the string GLOBAL.
=item C
Opens and parses the urls.txt file for use in the printNav method. Two array referrences
must be parsed to this hook. In the order of @names and @links.
=item C
Print's out the navigatiomn bar for the EMCB ExtraNet Server.
=item C
Returns the MD5 sum of a string parsed to this hook.
=item C
A method similar to Carp::warn; but without the kick-backs.
=item C
A method similar to main::die; but supplies it's own error messages instean of using
$errno.
=back
=head1 CHANGES
This module is still in alpha release.
=head1 EXAMPLE
This example will load the module, parse the urls.txt file and print out the EMCB ExtraNet
Server - Navigation toolbar.
#! /usr/local/bin/perl
use ExNet::General;
use strict;
my $general = new ExNet::General;
my $options = $general->returnRef( "GLOBAL" );
$options->{'EXNET_URLS_FILE'} = 'localpath/to/file/urls.txt';
my( @names,@links );
$general->getURLS_File( \@names,\@links );
printNav( \@names,\@links );
=head1 AUTHOR INFORMATION
(C)Copyright 1999 - 2002, Elfyn McBratney. All Rights reserved.
This library is free software; you can redistribute and/or modify it under the
same terms as perl itself.
Address bug reports and comments to: elfyn@exposure.org.uk. When sending bug reports,
please provide the version of General.pm, the version of Perl, the name and version of your
Web server, and the name and version of the operating system you are using. If the
problem is even remotely browser dependent, please provide information about the affected
browers as well.
=cut