###
### Copyright 2000-2007 University of Illinois Board of Trustees
### All rights reserved.
###
### EnvFile - psgconf action class for environment files
###
### Campus Information Technologies and Educational Services
### University of Illinois at Urbana-Champaign
###
package PSGConf::Action::GenerateFile::EnvFile;
use strict;
use PSGConf::Action::GenerateFile;
our @ISA = qw(PSGConf::Action::GenerateFile);
###############################################################################
### generate method
###############################################################################
sub generate
{
my ($self, $fh, $psgconf) = @_;
my ($var, $value);
foreach $var (sort keys %{$self->{vars}})
{
$value = $self->{vars}->{$var};
$value = '"' . $value . '"'
if ($self->{quote_values});
print $fh $var;
print $fh $self->{seperator};
print $fh $value;
print $fh "\n";
}
return 1;
}
###############################################################################
### constructor
###############################################################################
sub new
{
my ($class, %opts) = @_;
$opts{quote_values} = 0
if (!exists($opts{quote_values}));
$opts{seperator} = '='
if (!exists($opts{seperator}));
return PSGConf::Action::GenerateFile::new($class, %opts);
}
###############################################################################
### documentation
###############################################################################
1;
__END__
=head1 NAME
PSGConf::Action::GenerateFile::EnvFile - generate environment files
=head1 SYNOPSIS
use PSGConf::Action::GenerateFile::EnvFile;
$psgconf->register_actions(
PSGConf::Action::GenerateFile::EnvFile->new(
'name' => '/path/to/file',
'vars' => {
'var1' => 'value1',
...
},
...
),
...
);
=head1 DESCRIPTION
The B<PSGConf::Action::GenerateFile::EnvFile>
module provides a B<PSGConf> action class for generating files
containing environment variable definitions.
The B<PSGConf::Action::GenerateFile::EnvFile> class
is derived from the B<PSGConf::Action::GenerateFile> class, but it
defines/overrides the following methods:
=over 4
=item generate()
Generates the environment file.
=back
In addition to the attributes supported by
the B<PSGConf::Action::GenerateFile> class, the
B<PSGConf::Action::GenerateFile::EnvFile> class supports the following
attributes:
=over 4
=item I<vars>
An anonymous hash containing environment variable definitions.
=item I<quote_values>
A boolean to determine if the values are quoted. Default is false.
=item I<seperator>
A string containing the seperator to use between variable and values.
Defaults to C<=>.
=back
=head1 SEE ALSO
L<perl>
L<PSGConf>
L<PSGConf::Action::GenerateFile>
=cut
syntax highlighted by Code2HTML, v. 0.9.1