###
### Copyright 2000-2007 University of Illinois Board of Trustees
### All rights reserved.
###
### PSGConf::Action::CopyFile - canned file action type for psgconf
###
### Campus Information Technologies and Educational Services
### University of Illinois at Urbana-Champaign
###
package PSGConf::Action::CopyFile;
use strict;
use File::Copy;
use PSGConf::Action::File;
our @ISA = qw(PSGConf::Action::File);
###############################################################################
### check method
###############################################################################
sub check
{
my ($self, $psgconf) = @_;
my ($srcfile);
$self->_set_tmpfile($psgconf);
$srcfile = "$psgconf->{files_dir}/"
if (substr($self->{copy_from}, 0, 1) ne '/');
$srcfile .= $self->{copy_from};
if (!copy($srcfile, $self->{tmpfile}))
{
warn "\n\t!!! can't copy '$srcfile' to tempfile.\n";
return -1;
}
### check for changes
return $self->_file_changed($psgconf);
}
###############################################################################
### documentation
###############################################################################
1;
__END__
=head1 NAME
PSGConf::Action::CopyFile - file-copy action class for PSGConf
=head1 SYNOPSIS
use PSGConf::Action::CopyFile;
$psgconf->register_actions(
PSGConf::Action::CopyFile->new(
'name' => '/path/to/dest',
'copy_from' => '/path/to/src',
...
),
...
);
=head1 DESCRIPTION
The B<PSGConf::Action::CopyFile> module provides a B<PSGConf> action class
for creating a file as a copy of another file.
The B<PSGConf::Action::CopyFile> class is derived from the
B<PSGConf::Action::File> class, but it defines/overrides the
following methods:
=over 4
=item check()
Generates a tmpfile with the contents of the file to be copied.
If the tmpfile differs from the existing file, or if the existing file's
permissions or ownership needs to be changed, returns 1. Returns 0 if
no changes are needed, or -1 on error.
=back
In addition to the attributes supported by the B<PSGConf::Action::File>
class, the B<PSGConf::Action::CopyFile> class supports the following
attributes:
=over 4
=item I<copy_from>
Path to file to be copied. If not an absolute path, it will be searched
for in the directory named by the B<PSGConf> object's I<files_dir>
attribute.
=back
=head1 SEE ALSO
L<perl>
L<PSGConf>
L<PSGConf::Action::File>
=cut
syntax highlighted by Code2HTML, v. 0.9.1