package PhotoPub::Global;
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw($error &init &register_init &finit);

use strict;
use vars qw($error);

my %routines=();

my @initstages=('startup','config');
my @finitstages=('shutdown','cleanup');

sub register_init {
  my ($stage,$sub)=@_;
  $routines{$stage}=[] unless defined $routines{$stage};
  push(@{$routines{$stage}},$sub);
}

sub run {
  foreach my $stage (@_) {
    foreach my $routine (@{$routines{$stage}}) {
      &$routine();
    }
  }
}

sub init {
  &run(@initstages);
}

sub finit {
  &run(@finitstages);
}

1;
