1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
my $plugincode=load_code(); my $dataobj=get_data_object(); $plugincount++; $pugincode=<<EOC; { package PLUGIN::PLUGINS::$pugincount; use base 'PLUGIN::BASE'; use strict; use warnings; $plugincode; 1;} EOC my $pluginobj; if(eval(plugincode)) { $pluginobj=eval("PLUGIN::PLUGINS::$pugincount->new($dataobj)") if(!$pluginobj) { # create error } } else { # copmile error } #... $pluginobj->mach_was();
1 2
my $id=$obj->handler_add('aktion',sub{ ... },@options); $obj->handler_del($id);
$obj->handler_exec('aktion',@data) if($obj->handler_exists('aktion'));
1
2
3
4
5
6
7
8
9
10
11
12
while ( $tmpl_line =~ /\[OS_TMPLPLUGIN:(\w+):(\w+):(.*?)\]/g ) {
my ($tpath,$tfunc,$tfval,$tpvalue) = ($1,$2,$3,'') ;
if ( -e "pfad/Tmpl/$tpath/$tfunc.pm" ) {
eval "require Tmpl::$tpath\::$tfunc" ;
die "Fehler bei Einbindung Template-Plugin : Tmpl::$tpath\::$tfunc : $@\n" if ($@) ;
my $tplg = $tfunc->new(\%CONFIG,\%PARA,$tfval);
$tpvalue = $tplg->out ;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
sub AUTOLOAD {
my ($self,$arg1) = @_ ;
my @func = split(/\:\:/,$AUTOLOAD) ;
my $f = $func[-1] ;
my $fb = $f . "_beforeEvent" ;
my $fa = $f . "_afterEvent" ;
my $fo = $f . "_overEvent" ;
print "FUNC : @func ($func[-1]) \n" ;
print "Obj : " , $self->{'modclass'} , " ( $self->{'modobj'} ) \n" ;
print "AUTOL : $AUTOLOAD | @_ \n\n" ;
###
#Ausgabe vorher
if ( $self->{'plugclass'}->can($fb) ) {
print "Methode $self -> $fb vorhanden\n" ;
$self->{'plugclass'}->($f . "_beforeEvent")($arg1) ;
}
###
#Eigentliche Funktion
if ( $self->{'plugclass'}->can($fo) ) {
print "Ausgabe OVERfunktion\n" ;
$self->{'plugclass'}->$fo($arg1) ;
} elsif ( $self->{'modobj'} && $func[-1] ) {
print "Ausgabe Standardfunktion\n" ;
$self->{'modobj'}->$f($arg1) ;
}
###
#Ausgabe nachher
if ( $self->{'plugclass'}->can($fa) ) {
print "Methode $self -> $fa vorhanden\n" ;
$self->{'plugclass'}->$fa($arg1) ;
}
print "\n-----------\n\n" ;
}
sub DESTROY {}
1 ;
Aufruf wäre so
my $pobj = Plugin->new('TestClass','TestClassPlug') ;
$pobj->t1('T1T1T1') ;
$pobj->t2('T2T2T2') ;