###
### Copyright 2000-2007 University of Illinois Board of Trustees
### All rights reserved.
###
### PSGConf::Action::RunCommand - command action type for psgconf
###
### Campus Information Technologies and Educational Services
### University of Illinois at Urbana-Champaign
###
package PSGConf::Action::RunCommand;
use strict;
use PSGConf::Action;
use PSGConf::Action::RestartDaemon;
use PSGConf::Util;
our @ISA = qw(PSGConf::Action);
###############################################################################
### constructor
###############################################################################
sub new
{
my ($class, %opts) = @_;
my ($self) = \%opts;
$self->{check_func} = \&PSGConf::Action::RestartDaemon::_check_file
if (!exists($self->{check_func}));
return PSGConf::Action::new($class, %$self);
}
###############################################################################
### check method
###############################################################################
sub check
{
my ($self, $psgconf) = @_;
my ($ret);
$ret = (defined($self->{check_func})
? $self->{check_func}->($self, $psgconf)
: 1);
return $ret
if ($ret != 1);
$self->{changed} = 1;
return 1;
}
###############################################################################
### diff method
###############################################################################
sub diff
{
my ($self) = @_;
print "###############################################################################\n";
print "### DIFF FOR $self->{name}\n";
print "###############################################################################\n";
print "+ RUN COMMAND: $self->{command}\n";
print "\n";
}
###############################################################################
### do() method
###############################################################################
sub do
{
my ($self) = @_;
return ( ! &PSGConf::Util::RunCommand($self->{command}))? 1: 0;
}
###############################################################################
### documentation
###############################################################################
1;
__END__
=head1 NAME
PSGConf::Action::RunCommand - command-execution action class for PSGConf
=head1 SYNOPSIS
use PSGConf::Action::RunCommand;
$psgconf->register_actions(
PSGConf::Action::RunCommand->new(
'name' => 'message about command',
'command' => 'command ...',
'check_func' => \&_subref
),
...
);
=head1 DESCRIPTION
The B<PSGConf::Action::RunCommand> module provides a B<PSGConf> action
class for executing a command.
The B<PSGConf::Action::RunCommand> class is derived from the
B<PSGConf::Action> class, but it defines/overrides the
following methods:
=over 4
=item check()
If the I<check_func> attribute is set, calls the subroutine it
references to determine whether the command needs to be executed.
Otherwise, the default is to assume that the command does need to be
executed.
=item diff()
Prints a message indicating that the command will be executed.
=item do()
Actually executes the command.
=back
In addition to the attributes supported by the B<PSGConf::Action>
class, the B<PSGConf::Action::RunCommand> class supports the following
attributes:
=over 4
=item I<check_func>
A reference to the subroutine that determines whether the command needs
to be executed. The subroutine will be passed a reference to the
B<PSGConf::Action::RunCommand> object and a reference to the B<PSGConf>
object. It can return anything that the check() method can return.
=item I<command>
The command to be executed.
=back
Note that the I<name> attribute will only be used to print the
"checking" message when the check() method is called.
=head1 SEE ALSO
L<perl>
L<PSGConf>
L<PSGConf::Action>
L<PSGConf::Action::RestartDaemon>
L<PSGConf::Util>
=cut
syntax highlighted by Code2HTML, v. 0.9.1