Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Piatok, 21. január 2022

Súbor: [Platon] / iotta / Iotta / Chain.pm (stiahnutie)

Revízia 1.2, Sun Mar 23 11:29:54 2003 UTC (18 years, 10 months ago) by yenar


Zmeny od 1.1: +13 -2 [lines]

automatically require module when instantiating it [Iotta/Chain.pm]

package Iotta::Chain;
use strict;
use Iotta;
our @ISA = ("Iotta");
sub read {
}

sub write {
}

sub setup {
}

sub run {
    my $self = shift;
    my $meta = shift;
    my $mod = ${$self->mods}[0];
    $mod->run ($meta, 0);
}

sub mod_add {
    my $self = shift;
    my $mod = shift;
    $mod->chain ($self);
    my $lmod = pop @{$self->mods};
    if ($lmod) {
        $lmod->next ($mod);
        push @{$self->mods}, $lmod;
    }
    push @{$self->mods}, $mod;
}

sub mod_inst {
    my $self = shift;
    my $modn = shift;
    my $req = $modn;
    $req =~ s/::/\//g;
    print STDERR "instantiating $modn\n";
    require "$req.pm";# unless $req =~ /^[ \t]*#.*$/;
    my $mod = $modn->new || die "could not instantiate $modn";
    return $mod;
}

sub mod_creat {
    my $s = shift;
    my $modn = shift;
    my $modt;
    my $cfg = $s->cfg;
    my %opts;
    for (keys (%$cfg)) {
        if (/^mod\/$modn\//) {
            my $opt = $_;
            $opt =~ s/^mod\/.*?\///;
            $opts{$opt} = $$cfg{$_};
        }
    }
    my $modt = $$cfg{"mod/$modn"};
    #print "trying to instantiate $modt (config)\n";
    #print "trying to instantiate $modn ($modt)\n";
    my $mod = $s->mod_inst ($modt);
    $mod->chain ($s);
    $mod->setup(\%opts);
    return $mod;
}

sub finish {
    my $self = shift;
    for (@{$self->mods}) {
        $_->finish;
    }
}

sub initialize {
    my $self = shift;
    my @initval;
    $self->SUPER::initialize (@_);
    @{$self->{mods}}=();
    $self->{data}="";
    $self->{cfg}=0;
}

1;

Platon Group <platon@platon.sk> http://platon.sk/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok