Gitosis::Config::Writer - A class to output a valid gitosis.conf file


Gitosis-Config documentation Contained in the Gitosis-Config distribution.

Index


Code Index:

NAME

Top

Gitosis::Config::Writer - A class to output a valid gitosis.conf file

SYNOPSIS

Top

	use Gitosis::Config::Writer;
	Gitosis::Config::Writer->write_string( $cfg );

DESCRIPTION

Top

The Gitosis::Config::Writer class extends Config::INI::Writer

METHODS

Top

All methods are exactly the same as Config::INI::Writer except as documented below.

validate_input ($input)

preprocess_input ($input)

DEPENDENCIES

Top

Moose, Config::INI::Writer

BUGS AND LIMITATIONS

Top

None known currently, please email the author if you find any.

AUTHOR

Top

Chris Prather (chris@prather.org)

LICENCE

Top

Copyright 2009 by Chris Prather.

This software is free. It is licensed under the same terms as Perl itself.


Gitosis-Config documentation Contained in the Gitosis-Config distribution.

package Gitosis::Config::Writer;
use Moose;
extends qw(Config::INI::Writer);

around preprocess_input => sub {
    my ( $next, $self, $input ) = @_;

    # let's go ahead and maintain backwards compat
    return $self->$next($input) unless blessed $input;

    confess q[Can't output non Gitosis::Config object]
      unless $input->isa('Gitosis::Config');

    my @output;

    push @output, 'gitosis' =>
      [ map { $_ => $input->$_ } qw(gitweb daemon loglevel repositories) ];

    for my $group ( $input->groups ) {
        push @output, 'group '
          . $group->name => [
            map { $_ => join ' ', @{ $group->$_ } }
              grep { $_ ne 'name' } keys %$group
          ];
    }

    for my $repo ( $input->repos ) {
        push @output, "repo $repo->{name}" =>
          [ map { $_ => $repo->{$_} } grep { $_ ne 'name' } keys %$repo ];
    }

    return \@output;
};

sub validate_input {
    my ( $self, $input ) = @_;

    my %seen;
    for ( my $i = 0 ; $i < $#$input ; $i += 2 ) {
        my ( $name, $props ) = @$input[ $i, $i + 1 ];
        $seen{$name} ||= {};

        Carp::croak "illegal section name '$name'"
          if $name =~ /(?:\n|\s;|^\s|\s$)/;

        for ( my $j = 0 ; $j < $#$props ; $j += 2 ) {
            my $property = $props->[$j];
            my $value    = $props->[ $j + 1 ];

            Carp::croak "property name '$property' contains illegal character"
              if $property =~ /(?:\n|\s;|^\s|=$)/;

            Carp::croak "value for $name.$property contains illegal character"
              if defined $value and $value =~ /(?:\n|\s;|^\s|\s$)/;

            if ( $seen{$name}{$property}++ ) {
                Carp::croak "multiple assignments found for $name.$property";
            }
        }
    }
}

no Moose;
1;
__END__

__END__