#!/usr/bin/perl -w # # modules/globals.pm # # Developed by Lubomir Host 'rajo' # Copyright (c) 2004 Platon SDG, http://platon.sk/ # Licensed under terms of GNU General Public License. # All rights reserved. # # Changelog: # 08/02/2004 - created # # $Platon$ package globals; use strict; use Carp; use Cwd; use File::Basename qw( basename fileparse ); use vars qw($VERSION @ISA @EXPORT $AUTOLOAD); @ISA = qw(Exporter); @EXPORT = qw( ); $VERSION = '0.1'; use vars qw ( $site_root $hostname $fastcgi_name $data_source $database $db_host $db_user $db_password $runlimit ); # Database setup $data_source = 'mysql'; $database = 'finance'; $db_host = 'localhost'; $db_user = 'finance'; $db_password = ''; # FastCGI setup $runlimit = 1000; BEGIN { # {{{ $site_root = getcwd(); $hostname = `hostname`; # get name of FastCGI script my ($name, $path, $suffix) = fileparse($0, '.fcgi', '.cgi'); $fastcgi_name = $name eq '' ? 'index' : $name; # default index } # }}} sub new { # {{{ my $this = shift; my $class = ref($this) || $this; my $self = { runcount => 0, runlimit => $runlimit, hostname => $hostname, site_root => $site_root, fastcgi_name => $fastcgi_name, data_source => $data_source, database => $database, db_host => $db_host, db_user => $db_user, db_password => $db_password, }; bless $self, $class; return $self; } # }}} new # check, if $runcount < $runlimit sub run() { # {{{ my $self = shift; return 1 if ($self->runcount < $self->runlimit); } # }}} run # return value of $self->{runcount} and increase value sub runcount() { # {{{ my $self = shift; return $self->{runcount}++; } # }}} runcount sub AUTOLOAD() { # {{{ my $self = shift; my $type = ref($self) || croak "$self is not object"; my $name = $AUTOLOAD; $name =~ s/.*://; unless (exists $self->{$name}) { croak "Can't access array '$name' in object class '$type'"; } if (@_) { return $self->{$name} = shift; } else { return $self->{$name}; } } # }}} sub DESTROY() { # {{{ my $self = shift; undef $self; } # }}} 1; __END__ =head1 NAME globals - <<>> =head1 SYNOPSIS use globals; my $xxx = new globals; =head1 DESCRIPTION The globals module allows you ... <<>> =head2 EXPORT <>> =head1 SEE ALSO =head1 AUTHORS Lubomir Host 'rajo', =cut # vim: ts=4 # vim600: fdm=marker fdl=0 fdc=3