NAME

Perlbug::Base - Module for bringing together Config, Log, Do(wrapper functions), Database, all Objects etc.

DESCRIPTION

Perlbug application interface, expected to be subclassed by actual interfaces, and/or used as configuration manager/reader.

see Perlbug::Interface::Cmd, Perlbug::Interface::Web etc.

SYNOPSIS

my $o_base = Perlbug::Base->new;

print "System maintainer contact: ".$o_base->system('maintainer');

print "Total bugs: ".$o_base->object('bug')->ids;

my $o_user = $o_base->object('user')->read('richard');

print 'User('.$o_user->attr('name').') data: '.$o_user->format('l');

METHODS

new

Create new Perlbug object, (see also Description above):

my $o_base = Perlbug::Base->new();

Loading casualties from the log:

	[0]  INIT (18214) scr(/usr/local/httpd/htdocs/perlbug/admin/perlbug.cgi), debug(01xX) Perlbug::Log=HASH(0x860ef1c)
	[1]  Connect host(localhost), db(perlbug), user(perlbug), pass(sqlpassword)
	[2]  Connected to perlbug: 42 tables
	[3]  Perlbug 2.52 loaded 21 objects(@objects)

		Startup:  0 wallclock secs ( 0.10 usr +  0.00 sys =  0.10 CPU)
        Loaded :  0 wallclock secs ( 0.27 usr +  0.00 sys =  0.27 CPU)
        Runtime:  0 wallclock secs ( 0.06 usr +  0.00 sys =  0.06 CPU)
        Alltook:  0 wallclock secs ( 0.43 usr +  0.00 sys =  0.43 CPU)
				  including 44 SQL statements  
init

Initialize Base object

my $self = $o_base->init;
db

get database object

log

get log object

debug

Debug method, logs to "log_file", with configurable levels of tracking:

Controlled by $ENV{'Perlbug_DEBUG'} or $o_base->current('debug')

Note that current('debug') will always override any local setting, being as it purports to be the application debug level, unless it is set to an empty string => ' '

	0 = login, object, function (basic)		
	1 = decisions							(sets x) 
	2 = data feedback from within methods 	(sets i, x, X)
	3 = more than you want					(sets C, I, s, S, O, X)

	m = method names
	M = Method names (fully qualified)
	s = sql statements (num rows affected)
	S = SQL returns values (dump)
	x = execute statements (not SELECTs)
	X = EXecute returned n-results

	Where a capital letter is given:
		the data is Dumper'd if it's a reference, the result of a sql query, or an object

    $pb->debug("duff usage");              			# undefined second arg (treated as level 0)
    $pb->debug(0, 	"always tracked");        		# debug off
    $pb->debug(1, 	"tracked if $debug =~ /[01]/");	# debug on = decisions
    $pb->debug(2, 	"tracked if $debug =~ /[012]/");# debug on = talkative  
_debug

Quiet form of debug(), just calls the file method, and will never carp, so the user generally won't see the contents of the message

error

Handles error messages, is currently fatal(croak)

$o_base->error($msg);
logg

Files args to log file

$o_base->logg('Done something');
cgi

Get and set CGI->new object

object

Return appropriate (cached) object:

my $o_bug = $o_obj->object('Bug'); 

my $o_usr = $o_obj->object('User'); 

For a relationship, the correct syntax would, (though deprecated, unsupported and generally disparaged :), be of the form source->target eg;

my $o_bug_patch = $o_obj->object('bug->patch', '', 'to');

A relationship is taken care of by a special method: see Perlbug::Object::relation()

All Object know what relationships they have: see Perlbug::Object::relations()

etc.

cachable

Return cachable status for application

my $i_ok = $o_base->cachable(); # 1 or 0
version

Get Perlbug::Version

my $vers = $o_base->version;
isatest

Get and set isa test status

my $i_isatest = $o_base->isatest( [01] );
url

Store and return the given url.

my $url = $o_base->url( $url );
quote

Quote arg for insertion into db (dbh wrapper)

my $quoted = $o_base->quote($arg);
href

Cheat Wrapper for Object::href

do

Wrap a Perlbug::Do command

my @res = $pb->do('b', [<bugid1>, <bugid2>], $body);
dodgy_addresses

Returns quoted, OR-d dodgy addresses prepared for a pattern match ...|...|...

my $regex = $o_obj->dodgy_addresses('from'); # $rex = 'perlbug\@perl\.com|perl5\-porters\@perl\.org|...'
things

Return list of names of things in application

my @objnames = $o_pb->things('mail');

my @flags = $o_pb->things('flag');
flags

Returns array of options for given type.

my @list = $pb->flags('group');
all_flags

Return all flags available in db keyed by type/ident.

    my %flags = $pb->all_flags;

	%flags = ( # now looks like this:
		'group'	=> ['core', 'docs', 'install'], 	# ...
		'status'	=> ['open', 'onhold', 'onhold'], 	# ...
		# ...
	);
date_hash

Returns convenient date hash structure with sql query for values

my %dates = $o_base->date_hash;


# 'this week' => 'TO_DAYS(SYSDATE()) - TO_DAYS(created) <= 7'
active_admins

Returns active admins from db.

my @active = $pb->active_admins;
active_admin_addresses

Returns active admin addresses from db.

my @addrs = $pb->active_admin_addresses;
help

Returns help message for perlbug database.

my $help = $pb->help;
spec

Returns spec message for perlbug database.

my $spec = $pb->spec();

# rjsf: migrate to using v$Perlbug::VERSION.$etc.pod2html(Perlbug.pm) > spec.html

check_user

Checks given user is registered in the database as an admin.

Sets userid in admin and thereby status for later reference.

$pb->check_user($user_name);
isadmin

Stores and returns current admin userid (post check_user), checks whether system is restricted or not.

next unless $pb->isadmin;
ok

Checks bugid is in valid format (looks like a bugid) (uses get_id):

&do_this($id) if $pb->ok($id);
get_id

Determine if the string contains a valid bug ID

_switches

Stores and returns ref to list of switches given by calling script. Only these will be parsed within the command hash in process_commands.

my $switches = $pb->_switches(qw(e t T s S h l)); #sample
create_file

Create new file with this data:

$ok = $self->create("$dir/$file.tmp", $data);
prioritise

Set priority nicer by given integer, or by 12.

set_user

Sets the given user to the runner of this script.

read

First we look in site, then docs...

my @data = $o_base->read('header'); # or footer or mailhelp	
target2file

Return appropriate dir/file.ext for given target string

my $filename = $o_base->target2file('header'); # -> '~/text/header'
clean_cache

Application objects/methods may call this to clean the sql and/or object cache, particularly useful when objects or their relationships are being created or deleted:

It will not do so while application cacheing is on unless used with the 'force' command.

See also cachable()

Returns self

my $o_obj = $o_obj->clean_cache('sql', [force]); # 

my $o_obj = $o_obj->clean_cache('object', [force]); #
get_list

Returns a simple list of items (column values?), from a sql query.

my @list = $pb->get_list('SELECT COUNT(bugid) FROM db_table');
get_data

Returns a list of hash references, from a sql query.

my @hash_refs = $pb->get_data('SELECT * FROM db_table');
exec

Returns statement handle from sql query.

my $sth = $pb->exec($sql);
exists

Does this bugid exist in the db?

notify_cc

Notify db_bug_address addresses of changes, given current/original status of bug.

my $i_ok = $o_base->notify_cc($bugid, $orig);
track

Track some function or modification to the db.

$i_tracked = $self->track($type, $id, $entry);
ck822

Email address checker (RFC822) courtesy Tom Christiansen/Jeffrey Friedl.

print (($o_email->ck822($addr)) ? "yup($addr)\n" : "nope($addr)\n");
htpasswd

Modify, add, delete, comment out entries in .htpasswd

$i_ok = $o_web->htpasswd($userid, $pass);   # entry ok?

@entries = $o_web->htpasswd;                # returns list of entries ('userid:passwd', 'user2:pass2'...)
clean_up

Clean up previous logs activity whenever run, and report briefly on how long this process took.

Exits when done.

tell_time

Put runtime info in log file

my $o_base = $o_base->tell_time(Benchmark->new);
parse_str

Returns hash of data extracted from given string:

my %cmds = $o_obj->parse_str('5.0.5_444_aix_irix_<bugid>_etc' | (qw(patchid bugid etc));

%cmds = ( 'bugids' => \@bugids, 'change' => [qw(444)], 'osname' => [qw(aix irix)], 'version' => [qw(5.0.0.5)], 'unknown' => [qw(etc)], );

bugid_2_addresses

Return addresses based on context

my @addrs = $o_email->bugid_2_addresses($bugid);
dump

Wraps Dumper() and dumps given args

print $o_base->dump($h_data);
html_dump

Encodes and dumps given args

print $o_base->html_dump($h_data);
compare

Compare two arrays: returns 1 if identical, 0 if not.

my $identical = compare(\@arry1, \@arry2); # tomc
DESTROY

Clean up

AUTHOR

Richard Foley perlbug@rfi.net 1999 2000 2001