package HH::Unispool::Config; use 5.006; use strict; use warnings; use AutoLoader qw(AUTOLOAD); use Error qw(:try); use HH::Unispool::Config::Scope; # Used by _value_is_allowed our %ALLOW_ISA = ( 'filter' => [ 'HH::Unispool::Config::Entry::Filter' ], 'scope' => [ 'HH::Unispool::Config::Scope' ], 'system' => [ 'HH::Unispool::Config::Entry::System' ], ); # Used by _value_is_allowed our %ALLOW_REF = ( ); # Used by _value_is_allowed our %ALLOW_RX = ( 'host' => [ '^.+$' ], 'time' => [ '^\d+$' ], 'version' => [ '^.+$' ], ); # Used by _value_is_allowed our %ALLOW_VALUE = ( ); # Used by _initialize our %DEFAULT_VALUE = ( 'diff_host' => 0, 'diff_number' => 0, 'diff_time' => 0, 'diff_version' => 0, # See _initialize for 'host' default value 'scope' => HH::Unispool::Config::Scope->new(), # See _initialize for 'time' default value # See _initialize for 'version' default value ); # Package version our ($VERSION) = '$Revision: 0.3 $' =~ /\$Revision:\s+([^\s]+)/; 1; __END__ =head1 NAME HH::Unispool::Config - HollandHouse' UNISPOOL configuration =head1 SYNOPSIS use strict; use HH::Unispool::Config; use HH::Unispool::Config::OS; use HH::Unispool::Config::Entry::Filter; use HH::Unispool::Config::Entry::System; use HH::Unispool::Config::Entry::Device::5; use HH::Unispool::Config::Entry::Device::6; use HH::Unispool::Config::Entry::RemoteSystem::8; # Read and write config my $conf1 = HH::Unispool::Config->new_from_file('t/config.sample'); $conf1->write('t/config.sample.1.out'); # Read again, modify a little and diff config my $conf2 = HH::Unispool::Config->new_from_file('t/config.sample'); $conf2->delete_system('foobar.bar.org'); my $diff = $conf1->diff($conf2); if ($diff) { print STDERR "\nTHIS OUTPUT IS EXPECTED\n"; print STDERR "DIFFERENCES\n"; print STDERR $diff; print STDERR "\nTHIS OUTPUT WAS EXPECTED\n"; } # Create a config from scratch my $conf3 = HH::Unispool::Config->new(); # Create a filter and add it to the configuration my $flt = HH::Unispool::Config::Entry::Filter->new( { name => 'cat', file => '/usr/bin/cat', } ); $conf3->add_filter($flt); # Create the _Network_ system and add it to the configuration my $sysn = HH::Unispool::Config::Entry::System->new( { name => '_Network_', } ); $conf3->add_system($sysn); # Add a type 8 remote system to _Network_ my $rsys = HH::Unispool::Config::Entry::RemoteSystem::8->new( { name => 'foo', os => HH::Unispool::Config::OS->new( { os => 'Solaris' } ), remote_node_name => 'foo.bar.org', } ); $sysn->add_remote_system($rsys); # Add a type 5 device to _Network_ my $dev = HH::Unispool::Config::Entry::Device::5->new( { name => 'lp', filter_name => 'cat', remote_device_name => 'lp', remote_system_name => 'foo', description => 'lp', } ); $sysn->add_device($dev); # Create the foo.bar.org system and add it to the configuration my $sysf = HH::Unispool::Config::Entry::System->new( { name => 'foo.bar.org', local_system_name => 'foo', network_name => 'foo.bar.org', os => HH::Unispool::Config::OS->new( { os => 'Solaris' } ), type => 'cs', } ); $conf3->add_system($sysf); # Add a type 6 device to foo.bar.org $dev = HH::Unispool::Config::Entry::Device::6->new( { name => 'lp1', filter_name => 'cat', remote_node_name => 'lp1.foo.bar.org', description => 'lp1', } ); $sysf->add_device($dev); # Add another type 6 device to foo.bar.org $dev = HH::Unispool::Config::Entry::Device::6->new( { name => 'lp2', filter_name => 'cat', remote_node_name => 'lp2.foo.bar.org', description => 'lp2', } ); $sysf->add_device($dev); # Add another type 3 device to foo.bar.org $dev = HH::Unispool::Config::Entry::Device::3->new( { name => 'lp', filter_name => 'cat', member_device_name => [ qw( lp1 lp2 ) ], description => 'lp', } ); $sysf->add_device($dev); # Write the configuration $conf3->write('t/config.sample.3.out'); =head1 ABSTRACT HollandHouse' UNISPOOL configuration =head1 DESCRIPTION C manages HollandHouse' UNISPOOL configuration files. Files can be read, written, generated from scratch and C-ed. =head1 CONSTRUCTOR =over =item new( [ OPT_HASH_REF ] ) Creates a new C object. C is a hash reference used to pass initialization options. On error an exception C is thrown. Options for C may include: =over =item B> Passed to L. Defaults to B<0>. =item B> Passed to L. Defaults to B<0>. =item B> Passed to L. Defaults to B<0>. =item B> Passed to L. Defaults to B<0>. =item B> Passed to L. Must be an C reference. =item B> Passed to L. Defaults to the first part of C<&Sys::Hostname::hostname()>. =item B> Passed to L. Defaults to Bnew()>. =item B> Passed to L. Must be an C reference. =item B> Passed to L. Defaults to B<'time()'>. =item B> Passed to L. Defaults to the version number of the installed UNISPOOL instance or C<0>. =back =item new_from_file(FILE) Constructs a new C object using a file. C is either a file name or an C reference. On error an exception C is thrown. =item new_from_unispool() Dumps the configuration of the UNISPOOL instance running on this machine into a temporary file, creates a new C object using the temporary file and cleans up the temporary file. On error an exception C is thrown. =back =head1 METHODS =over =item add_filter( [ VALUE ... ] ) Add additional values on the list of filters. Each C is an object out of which the id is obtained through method C. The obtained B is used to store the value and may be used for deletion and to fetch the value. 0 or more values may be supplied. Multiple occurrences of the same key yield in the last occurring key to be inserted and the rest to be ignored. Each key of the specified values is allowed to occur only once. On error an exception C is thrown. =over =item The values in C must be a (sub)class of: =over =item HH::Unispool::Config::Entry::Filter =back =back =item add_system( [ VALUE ... ] ) Add additional values on the list of systems. Each C is an object out of which the id is obtained through method C. The obtained B is used to store the value and may be used for deletion and to fetch the value. 0 or more values may be supplied. Multiple occurrences of the same key yield in the last occurring key to be inserted and the rest to be ignored. Each key of the specified values is allowed to occur only once. On error an exception C is thrown. =over =item The values in C must be a (sub)class of: =over =item HH::Unispool::Config::Entry::System =back =back =item delete_filter(ARRAY) Delete elements from the list of filters. Returns the number of deleted elements. On error an exception C is thrown. =item delete_system(ARRAY) Delete elements from the list of systems. Returns the number of deleted elements. On error an exception C is thrown. =item diff(TO) Finds differences between two objects. In C terms, the object is the B object and the specified C parameter the B object. C is a reference to an identical object class. Returns an empty string if no difference found and a difference descritpion string otherwise. On error an exception C is thrown. =item exists_filter(ARRAY) Returns the count of items in C that are in the list of filters. =item exists_system(ARRAY) Returns the count of items in C that are in the list of systems. =item get_host() Returns the host in the comment. =item get_scope() Returns not described option. =item get_time() Returns the date in the comment in Unix time. =item get_version() Returns the version in the comment. =item is_diff_host() Returns whether L should consider the C attribtute or not. =item is_diff_number() Returns whether L should consider the C attribtutes of devices and remote systems or not. =item is_diff_time() Returns whether L should consider the C