Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Štvrtok, 23. január 2025

Súbor: [Platon] / scripts / perl / accounting / modules / config.pm (stiahnutie)

Revízia 1.1, Tue Mar 15 23:17:56 2005 UTC (19 years, 10 months ago) by rajo

Modules for accounting scripts.

#
# modules/config.pm
#
# Developed by Lubomir Host 'rajo' <rajo AT platon.sk>
# Copyright (c) 2005 Platon SDG, http://platon.sk/
# Licensed under terms of GNU General Public License.
# All rights reserved.
#
# Changelog:
# 2005-03-14 - created
#

# $Platon$

package config;

use strict;
use Carp;
use Cwd;
use File::Basename qw( basename fileparse );
use vars qw($VERSION $DEBUG @ISA @EXPORT $AUTOLOAD);

@ISA     = qw(Exporter);
@EXPORT  = qw( run runcount );
$VERSION  = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/);
$DEBUG    = 0 unless defined $DEBUG;

use vars qw (
    $hostname $language
    $site_title $site_root $fastcgi_name $runlimit
    $site_base $site_base_uri $admin_base_uri

    $data_source $db_host $database $db_user $db_password
);

# db config {{{
$data_source        = 'mysql';
$db_host            = 'localhost';
$database            = 'system';
$db_user            = 'syswatcher';
$db_password        = '';
# }}}

BEGIN
{ # {{{
    $site_title    = 'Network statistics';
    $site_root = getcwd();

    $hostname = `hostname -f`;
    $hostname =~ s/\s//g;

    # get name of FastCGI script
    my ($name, $path, $suffix) = fileparse($0, '.fcgi', '.cgi');
    #$fastcgi_name = $name eq '' ? 'index' : $name; # default index
    $fastcgi_name = $name . $suffix;

    $language = $fastcgi_name eq 'index' ? 'en' : $fastcgi_name;

    if ($hostname =~ m/Idea/i) {
        $site_base        = 'rajo.platon.sk/'; # protocol http:// or https:// is determined automatically
        $site_base_uri    = '/';
        $admin_base_uri    = '/admin/';
    }
    else {
        $site_base        = "$hostname/~rajo/";
        $site_base_uri    = '/~rajo/';
        $admin_base_uri    = '/~rajo/admin/';
    }

    $runlimit = 1000;

} # }}}

sub new
{ #{{{
    my $this  = shift;
    my $class = ref($this) || $this;
    my $self  = {
        runcount        => 0,
        runlimit        => $runlimit,
        hostname        => $hostname,
        site_title        => $site_title,
        site_root        => $site_root,
        site_base        => $site_base,
        site_base_uri    => $site_base_uri,
        admin_base_uri    => $admin_base_uri,
        fastcgi_name    => $fastcgi_name,
        language        => $language,

        data_source         => $data_source,
        database         => $database,
        db_host            => $db_host,
        db_user             => $db_user,
        db_password         => $db_password,
    };

    bless $self, $class;

    return $self;
} # }}}

# 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;



1;

__END__

=head1 NAME

config - <<<description of module>>>

=head1 SYNOPSIS

  use config;

  my $xxx = new config;

=head1 DESCRIPTION

The config module allows you ...
<<<your description here>>>

=head2 EXPORT

<<here describe exported methods>>>

=head1 SEE ALSO

=head1 AUTHORS

Lubomir Host 'rajo', <rajo AT platon.sk>

=cut

# vim: ts=4
# vim600: fdm=marker fdl=0 fdc=3


Platon Group <platon@platon.sk> http://platon.sk/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok