#!@PERL@
#######################################################################
#
# Example LCFG Component in Perl
#
# @LCFG_AUTHOR@
# Version @LCFG_VERSION@ : @LCFG_DATE@
#
#@MSG@
#
#######################################################################

package LCFG::Component::PerlEx;
use strict;
use warnings;

use base qw(LCFG::Component);

use LCFG::Template qw($PERLTMPL);

##########################################################################
sub Configure {
##########################################################################

    my ( $self, $res, @args ) = @_;

########################################################################
# We illustrate two different cases here. Normally, you wouldn't
# use both together:
########################################################################

    my $server = $res->{server}{VALUE};

########################################################################
# (1) Firstly, we recreate a configuration file when we get a reconfigure
# call. Normally, this would be used if you have no daemon, or if
# your daemon is a separate program.
########################################################################

    my $template   = $res->{template}{VALUE};
    my $configfile = $res->{configfile}{VALUE};

    my $status = LCFG::Template::Substitute
        ( $template, $configfile, $PERLTMPL, $res );

    if ( ! defined $status ) {
        $self->LogMessage($@);
        $self->Fail( "failed to create config file (see logfile)");
    }

    if ( $status == 1 ) {
        $self->LogMessage("configuration changed");
    }

    # At this point, we should check if the daemon is running, and
    # if so notify it of any changes (if necessary)

    return;
}

##########################################################################
sub Start {
##########################################################################

    my ( $self, $res, @args ) = @_;

########################################################################
# If you want to run an external daemon program, you should start
# it here and record the PID somewhere so you can stop it later
########################################################################

########################################################################
# If you don't have a daemon, you don't need a Start() routine
# at all.
########################################################################

    return;
}

##########################################################################
sub Stop {
##########################################################################

    my ( $self, $res, @args ) = @_;

########################################################################
# If you want to run an external daemon program, you should have
# saved the PID in the Start() routine, so you can kill it here.
# You probably want to wait here until you are satisfied that the
# daemon really has stopped.
########################################################################

########################################################################
# If you don't have a daemon, you don't need a Stop() routine
# at all.
########################################################################

    return;
}

##########################################################################
# Dispatch methods
##########################################################################

LCFG::Component::PerlEx->new()->Dispatch();
