On Tue, 22 Jun 2010 09:51:33 +0000, Jens Rehsack <rehs...@googlemail.com> wrote:
> Hi DBI Developers, > > I need a nudge to the right direction for my ideas how to get DBD::Sys > more extensible. My current way is, each plugin can define tables and > each table has to define it's column names and a way to retrieve the > data. > > This is simple, works fine as long the extensions are controller by > a group of maintainers but has one (from my point of view) nasty > limitation: > > Table PROCS - Unix implementation uses Proc::ProcessTable, Win32 > implementation will use Win32::Process::Info. Of coursem they will > reside in different plugins. When one fine day Proc::ProcessTable > will support Win32, too - I get a conflict. > > So I thought the best idea would be to separate the table definitions > from the data providers. And there I need a nudge how to do it the > "best" way for future extensibility. > > Of course, other hints how to improve some things are very welcome, > too :) > > Best, > Jens Just sharing some finds of recent history ... --8<--- a code snippet from (semi)portable code if ($^O eq "MSWin32") { eval { require Win32::Process::Info; Win32::Process::Info->import (); require Win32::Process::CommandLine; Win32::Process::CommandLine->import (); for (Win32::Process::Info->new ()->GetProcInfo ()) { (my $uid = $_->{OwnerSid} // 0) =~ s/.*-//; my $cli = ""; Win32::Process::CommandLine::GetPidCommandLine ($_->{ProcessId}, $cli); $cli ||= ""; $cli =~ s{^\S+\\}{}; $cli =~ s{\s+$}{}; push @ps, { cmd => $cli || $_->{Name} || "<dead>", # ExecutablePath pid => $_->{ProcessId}, ppid => 0, uid => $uid, gid => 0, pri => 0, nice => 0, start => fmt_stime ($_->{CreationDate}), run => fmt_time (int (($_->{KernelModeTime} // 0) + ($_->{UserModeTime} // 0) + .499)), status => $_->{_status}, }; } }; } else { require Proc::ProcessTable; sub prtime ($) { my ($f1, $f2, $p, $t) = ($^O eq "linux" ? ((1000000) x 2) : (1, 100), @_); use integer; eval { $t = $p->time / $f1 }; $t //= ($p->utime + $p->stime) / $f2; fmt_time ($t); } # prtime sub prstime ($) { fmt_stime ($_[0]->start); } # prstime my $pst = Proc::ProcessTable->new (); #print STDERR join ", ", $pst->fields, "\n"; for (@{$pst->table}) { my $cmd = defined $_->{gid} ? $_->cmndline : "<dead>"; my $pri = exists $_->{pri} ? $_->{pri} : exists $_->{priority} ? $_->{priority} : 0; my $nce = exists $_->{nice} ? $_->{nice} : 0; my $stt = exists $_->{state} ? $_->{state} : 0; push @ps, { cmd => $cmd, pid => $_->pid, ppid => $_->ppid, uid => $_->uid, gid => $_->gid, pri => $pri, nice => $nce, start => prstime $_, run => prtime $_, status => $stt, }; } } -->8--- Note that some Win32 methods can only be used with enough rights. Above snippet is what worked best for *me* on my systems (using Strawberry perl). -- H.Merijn Brand http://tux.nl Perl Monger http://amsterdam.pm.org/ using 5.00307 through 5.12 and porting perl5.13.x on HP-UX 10.20, 11.00, 11.11, 11.23, and 11.31, OpenSuSE 10.3, 11.0, and 11.1, AIX 5.2 and 5.3. http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/ http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/