Arepa

 view release on metacpan or  search on metacpan

lib/Arepa/Config.pm  view on Meta::CPAN

    my ($self, $builder_name) = @_;

    my $builder_config = $self->{config}->{builders};
    my @matching_builders = grep { $_->{name} eq $builder_name }
                                 @$builder_config;
    scalar(@matching_builders) == 0 and
        croak "Don't know builder '$builder_name'";
    scalar(@matching_builders) >  1 and
        croak "There is more than one builder called '$builder_name'";
    return %{$matching_builders[0]};
}

sub get_builder_config_key {
    my ($self, $builder_name, $config_key) = @_;

    my %builder_config = $self->get_builder_config($builder_name);
    defined($builder_config{$config_key}) or
        croak "'$builder_name' doesn't have a configuration key $config_key";
    return $builder_config{$config_key};
}

1;

__END__

=head1 NAME

Arepa::Config - Arepa package database API

=head1 SYNOPSIS

 my $config = Arepa::Config->new('path/to/config.yml');
 my $config = Arepa::Config->new('path/to/config.yml',
                                 builder_config_dir => 'path/to/builderconf');

 my $pdb_path = $config->get_key('package_db');
 my $repo_path = $config->get_key('repository:path');
 if ($config->key_exists('optional:key')) {
     $value = $config->get_key('optional:key');
 }

 my @builder_names = $config->get_builders;
 my %builder_config = $config->get_builder_config('some-builder');
 my $value = $config->get_builder_config_key('some-builder', $key);

=head1 DESCRIPTION

This class allows easy access to the Arepa configuration. The configuration is
divided in two parts: the basic configuration (a single YAML file) and the
configuration for the builders (a YAML file for each builder). Typically you
would pass a single path for the main configuration, and the builder
configuration would be loaded from the directory C<builders> inside the same
parent directory as the main configuration file. However, if you want you can
specify a custom directory to load the builder configuration from.

This is an excerpt of an example configuration file:

 ---
 repository:
   path: /home/zoso/src/apt-web/test-repo/
 upload_queue:
   path: /home/zoso/src/apt-web/incoming
 package_db: /home/zoso/src/apt-web/package.db
 web_ui:
   base_url: http://localhost
   user_file: /home/zoso/src/apt-web/repo-tools-web/users.yml

This is an example of a builder configuration file (say, C<squeeze32.yaml>):

 ---
 type: sbuild
 architecture: i386
 distribution: my-squeeze
 other_distributions: [squeeze, unstable]

Usually this class is not used directly, but internally in C<Arepa::Repository>
or C<Arepa::BuilderFarm>.

=head1 METHODS

=over 4

=item new($path)

=item new($path, %options)

It creates a new configuration access object for the configuration file in the
given C<$path>. The only valid option is C<builder_config_dir>, the path where
the builder configuration files are located.

=item key_exists($key)

Return true/false if the given configuration key is defined or not.

=item get_key($key)

Returns the value of the given C<$key> in the configuration file. If it's not a
top-level key, the subkeys must be separated by a colon ("C<:>"). If the key
cannot be found, an exception is thrown.

=item get_builders

Returns an array of names of the defined builders.

=item get_builder_config($builder_name)

Returns a hash with the configuration of the given C<$builder_name>. If no
builder (or more than one) is found by that name, an exception is thrown.

=item get_builder_config_key($builder_name, $key)

Returns the value for the given configuration C<$key> for the given
C<$builder_name>.

=back

=head1 SEE ALSO

C<Arepa::BuilderFarm>, C<Arepa::Repository>.

=head1 AUTHOR



( run in 1.074 second using v1.01-cache-2.11-cpan-b16cb0d3907 )