###
### Copyright 2000-2007 University of Illinois Board of Trustees
### All rights reserved.
###
### PSGConf::Action::Remove - remove action type for psgconf
###
### Campus Information Technologies and Educational Services
### University of Illinois at Urbana-Champaign
###
package PSGConf::Action::Remove;
use strict;
use File::Path;
use PSGConf::Action;
our @ISA = qw(PSGConf::Action);
###############################################################################
### check method
###############################################################################
sub check
{
my ($self) = @_;
if (-e $self->{name} || -l $self->{name})
{
$self->{changed} = 1;
return 1;
}
return 0;
}
###############################################################################
### diff method
###############################################################################
sub diff
{
my ($self) = @_;
print "###############################################################################\n";
print "### DIFF FOR $self->{name}\n";
print "###############################################################################\n";
print "- REMOVE: $self->{name}\n\n";
}
###############################################################################
### do() method
###############################################################################
sub do
{
my ($self, $psgconf) = @_;
if (!$self->{backup})
{
rmtree($self->{name});
}
elsif (! $psgconf->save_file($self->{name}, $self->{backup}))
{
return -1;
}
return 1;
}
###############################################################################
### documentation
###############################################################################
1;
__END__
=head1 NAME
PSGConf::Action::Remove - file-removal action class for PSGConf
=head1 SYNOPSIS
use PSGConf::Action::Remove;
$psgconf->register_actions(
PSGConf::Action::Remove->new(
'name' => '/path/to/file',
...
),
...
);
=head1 DESCRIPTION
The B<PSGConf::Action::Remove> module provides a B<PSGConf> action class
for removing an entry from the filesystem (regular file, directory,
symlink, etc).
The B<PSGConf::Action::Remove> class is derived from the
B<PSGConf::Action> class, but it defines/overrides the
following methods:
=over 4
=item check()
Checks to see if the file currently exists.
=item diff()
Prints a message indicating that the file needs to be removed.
=item do()
Removes the file, optionally saving it under a different name.
=back
In addition to the attributes supported by the B<PSGConf::Action>
class, the B<PSGConf::Action::Remove> class supports the following
attributes:
=over 4
=item I<backup>
A boolean flag to indicate whether a backup copy of the existing file
will be saved. If enabled, existing files will be saved under their
original name but with the prefix ".<backupext>". Default is no
backup.
=back
=head1 SEE ALSO
L<perl>
L<PSGConf>
L<PSGConf::Action>
=cut
syntax highlighted by Code2HTML, v. 0.9.1