| Perlbug documentation | view source | Contained in the Perlbug distribution. |
Perlbug::Base - Module for bringing together Config, Log, Do(wrapper functions), Database, all Objects etc.
Perlbug application interface, expected to be subclassed by actual interfaces, and/or used as configuration manager/reader.
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');
Create new Perlbug object, (see also Description above):
my $o_base = Perlbug::Base->new();
Loading casualties from the log via tell_time():
[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
Initialize Base object
my $self = $o_base->init;
Return Config object
my $o_conf = $o_base->conf;
Get and set CGI->new object
get database object
get log object
Debug method, logs to log_file, with configurable levels of tracking:
Controlled by $ENV{'Perlbug_DEBUG'} or $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, interface, function (basic) (if debug =~ /\w+/) 1 = decisions (sets 01) 2 = data feedback from within methods (sets 012msX) 3 = more than you want (sets 0123mMsSxX) 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
Quiet form of debug(), just calls the file method, and will never carp or confess, so the user generally won't see the contents of the message
Files args to log file
$o_base->logg('Done something');
Returns randomised recognisableid . processid . rand(time)
my $it = get_rand_msgid();
An alternative might be:
my $msgid = "<19870502_$$.$time.$count@rfi.net>";
Returns a given Mail::Internet object s(p)liced up into useful bits.
my ($o_hdr, $header, $body) = $self->splice($o_int); # todo ---sig
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.
Get Perlbug::Version
my $vers = $o_base->version;
Get and set isa test status
my $i_isatest = $o_base->isatest( [01] );
Return summary of open/closed bugs
print $o_web->summary();
Simple wrapper
print "framed<hr>" if $o_base->isframed;
Store and return the given url, with appropriate underscore '_'.
my $url = $o_base->myurl( $url );
Cheat Wrapper for Object::href
Returns quotemeta'd, OR-d dodgy addresses prepared for a pattern match ...|...|...
my $regex = $o_obj->dodgy_addresses('from');
# $regex = 'perlbug\@perl\.com|perl5\-porters\@perl\.org|...'
Return list of names of objects in application, by type
my @objnames = $o_pb->objects('mail');
my @flags = $o_pb->objects('flag');
Returns array of options for given type.
my @list = $pb->flags('group');
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', 'closed'], # ... # ... );
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'
Returns help message for perlbug database.
my $help = $pb->help;
Returns spec message for perlbug database.
print $pb->spec;
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);
Returns current admin userid (post check_user), checks whether system is restricted or not.
print 'current user: '.$pb->isadmin; # name | ''
Returns current admin userid (post check_user), if base->isadmin eq base->system(bugmaster)
print 'is bugmaster: '.$pb->isbugmaster; # name | ''
Returns array of appropriate switches based on isadmin or arg.
my @switches = $o_pb->switches([admin|user]); # exlusive
Create new file with this data:
$o_file = $self->create("$dir/$file.tmp", $data);
Set priority nicer by given integer, or by 12.
Sets the given user to the runner of this script.
First we look in site, then docs...
my @data = $o_base->read('header'); # or footer or mailhelp
Return appropriate dir/file.ext for given target string
my $filename = $o_base->target2file('header'); # -> '~/text/header'
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([], [force]); # all (sql, objects, time)
my $o_obj = $o_obj->clean_cache('sql', [force]); # just sql
my $o_obj = $o_obj->clean_cache('object', [force]); # just objects
Returns a simple list of items (column values?), from a sql query.
Optional second parameter overrides sql statement/result cacheing.
my @list = $pb->get_list('SELECT COUNT(bugid) FROM db_table', ['refresh']);
Returns a list of hash references, from a sql query.
Optional second parameter overrides sql statement/result cacheing.
my @hash_refs = $pb->get_data('SELECT * FROM db_table', ['refresh']);
Returns statement handle from sql query.
my $sth = $pb->exec($sql);
Track bugids from this session
my @extant = $o_base->extant($bugid);
Does this bugid exist in the db?
Notify all relevant parties of incoming item
my $i_ok = $o_base->notify('bug', '19870502.007');
Setup Mail::Internet object from given args, body is default unless given.
my $o_int = $o_base->setup_int(\%header, [$body]); # 'to' => 'to@x.net'
or
my $o_int = $o_base->setup_int($db_header, [$body]); # could be folded
Notify db_bug_address addresses of changes, given current/original status of bug.
my $i_ok = $o_base->notify_cc($bugid, $orig);
Track some function or modification to the db.
$sth = $self->track($obj, $id, $entry);
Email address checker (RFC822) courtesy Tom Christiansen/Jeffrey Friedl.
print (($o_email->ck822($addr)) ? "yup($addr)\n" : "nope($addr)\n");
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'...)
Creates something of the form: <a href="http://bugs.per.org/perlbug.cgi?req=webhelp\#item_note"Note</a>>
my $help = $self->help_ref('note', ['Note HELP']);
Clean up previous logs activity whenever run, and report briefly on how long this process took.
Exits when done.
Put runtime info in log file, if $Perlbug::DEBUG
my $feedback = $o_base->tell_time(Benchmark->new);
Returns hash of data extracted from given string.
Matches are 'nearest wins' after 4 places ie; clos=closed.
NB. Will catch userids when i_int=userid, userid->name, name->fullname
my %cmds = $o_obj->parse_str('5.0.5_444_aix_irix_<bugid>_etc' | (qw(patchid bugid etc));
%cmds = (
'bugids' => \@bugids,
'change' => {
'ids' => [qw(3)],
'names' => [qw(553)],
},
'osname' => {
'ids' => [qw(12 14)],
'names' => [qw(aix macos irix)],
},
'unknown' => {
'ids' => [qw(0123456789)],
'names' => [qw(etc)],
},
);
Scan for perl relevant data putting found or default switches in $h_data.
Looking for both group=docs and '\brunning\s*under\ssome\s*perl' style markers.
my $h_data = $o_mail->scan($body);
Migrate to return parse_str() style hashref
Return addresses based on context
my @addrs = $o_email->bugid_2_addresses($bugid);
Compare two arrays: returns 1 if identical, 0 if not.
my $identical = compare(\@arry1, \@arry2); # tomc
Richard Foley perlbug@rfi.net 1999 2000 2001
| Perlbug documentation | view source | Contained in the Perlbug distribution. |