###
### Copyright 2000-2007 University of Illinois Board of Trustees
### All rights reserved.
###
### PSGConf::Control - base class for psgconf control types
###
### Campus Information Technologies and Educational Services
### University of Illinois at Urbana-Champaign
###
package PSGConf::Control;
use strict;
use PSGConf::Util;
###############################################################################
### constructor
###############################################################################
sub new
{
my ($class, $psgconf, %opts) = @_;
my ($self, $caller, $directive);
$self = \%opts;
bless($self, $class);
if ((!exists($self->{name}) || $self->{name} eq '')
&& ! $self->{quiet})
{
$caller = (caller(1))[3]
if (!defined($caller));
die "PSGConf::Control->new(): no name attribute from caller $caller\n";
}
# Register all our data objects
$psgconf->register_data (
$self->{name} . '_enable' => PSGConf::Data::Boolean->new(),
$self->{name} . '_packages' => PSGConf::Data::List->new()
);
# Register all our policies
$psgconf->register_policy ($self,
$self->{name} . '_add_packages' => '_policy_add_packages'
);
return $self;
}
###############################################################################
### policy method
###############################################################################
sub _policy_add_packages
{
my ($self, $psgconf) = @_;
my ($enable, $packages);
$enable = $self->{name} . '_enable';
$packages = $self->{name} . '_packages';
PSGConf::Util::_add_packages(
$psgconf,
$psgconf->data_obj($enable)->equals('true'),
@{$psgconf->data_obj($packages)->get()}
);
}
1;
__END__
=head1 NAME
PSGConf::Control - base class for PSGConf control types
=head1 SYNOPSIS
use PSGConf::Control;
our @ISA = qw(PSGConf::Control);
sub new {
my ($class, $psgconf, %opts) = @_;
$self = \%opts;
bless($self, $class);
...
$self = PSGConf::Control->new($psgconf, %$self);
return $self;
}
=head1 DESCRIPTION
The B<PSGConf::Control> module provides a class that represents an control
in B<PSGConf>.
The B<PSGConf::Control> class is not intended to be used to directly
instantiate control objects, but it does support the following methods
for use in subclasses:
=over 4
=item new()
The constructor. It can be passed a hash to set the object's
attributes. The object will be created as a reference to this hash.
The following attributes are supported:
=over 4
=item I<name>
A B<PSGConf::Data::String> object to store the name of the subclass.
It will be used in naming all further data objects.
=item I<name_enable>
A B<PSGConf::Data::Boolean> object to determine whether or not the
control module is to do any work. In future revisions, this will
be defined to expicitly turn on or off the item it is controlling.
I<name> is to be replaced with the name that the subclass provides.
=item I<name_packages>
A B<PSGConf::Data::List> object of packages that may need to be installed
if this Control module is to be used. I<name> is to be replaced with the
name that the subclass provides.
=back
The constructor also registers the following policy method:
=over 4
=item I<name_add_package>
If I<name_enable> is defined, adds C<name_packages> to the
I<pkg_install_list> object, which is provided by the
B<PSGConf::Control::Packages> module.
=back
=back
=head1 SEE ALSO
L<perl>
L<PSGConf>
L<PSGConf::Action::File>
L<PSGConf::Action::MkDir>
L<PSGConf::Action::Symlink>
L<PSGConf::Action::TouchFile>
L<PSGConf::Data::Boolean>
L<PSGConf::Data::List>
L<PSGConf::Data::Hash>
L<PSGConf::Data::String>
L<PSGConf::Data::ConfigError>
=cut
syntax highlighted by Code2HTML, v. 0.9.1