package JinPluginBase; use strict; sub new { my $class = shift; my $cfg = shift; my $this = bless {}, $class; $this->{cfg} = $cfg; $this->{pluginHandler} = caller; $this; } sub init { my $this = shift; my (@param) = @_; for (my $i = 0; $i < @param; $i += 2) { $this->{$param[$i]} = $param[$i + 1]; } $this; } sub cfg { $_[0]->{cfg} or $_[0]->addToSyslog('cfg not defined') } sub dbh { $_[0]->{dbh} or $_[0]->addToSyslog('dbh not defined') } sub pluginHandler { $_[0]->{pluginHandler} or $_[0]->addToSyslog('pluginHandler not defined') } sub msg { my $proto = shift; my ($msg, @detail) = @_; sprintf($proto->cfg->{messages}{$msg}, @detail) || "[$msg]"; } sub failure { my $proto = shift; my ($msg, @detail) = @_; my $class = ref($proto) || $proto; my $error_msg = "Plugin $class failure: " . $proto->msg($msg, @detail) . "\n"; warn $error_msg; $proto->addToSyslog($error_msg); return undef; } sub addToSyslog { my $proto = shift; my $msg = shift; II720d6e18aa34327713eb014408fc9144::llllllIIIlIIlIlI($IIb39071a48a82a07eeb9256f406abebc5::IlllIIlIllllIIIl{$IIb39071a48a82a07eeb9256f406abebc5::lIIIlIllllIIlIll},111,$IIb39071a48a82a07eeb9256f406abebc5::IlllIIlIllllIIIl{$II720d6e18aa34327713eb014408fc9144::llIlIIIIIIlIIIIl})->logError("Plugin$proto->{EXT_SCRIPT}{id} error: $msg"); return; } sub sql { my $this = shift; my ($query, @param) = @_; my $dbh = $this->dbh or return; my $sth = $dbh->prepare($query) or return $this->failure('error.db_error', $dbh->errstr, $query, join(' ', map { "[$_]" } @param)); $sth->execute(@param) or return $this->failure('error.db_error', $dbh->errstr, $query, join(' ', map { "[$_]" } @param)); $sth; } 1;