Group-Git

 view release on metacpan or  search on metacpan

lib/Group/Git.pm  view on Meta::CPAN

}

sub _repos {
    my ($self) = @_;
    my %repos;
    my @files = path('.')->children;
    my %tags;
    for my $tag ( keys %{ $self->conf->{tags} } ) {
        $tags{$tag} = { map { $_ => 1 } @{ $self->conf->{tags}{$tag} } };
    }

    while ( my $file = shift @files ) {
        next unless -d $file;
        my $config = $file->path('.git', 'config');

        if ( !-f $config ) {
            if ( $self->recurse && $file->basename ne '.git' ) {
                push @files, $file->children;
            }
            next;
        }

        my ($url) = grep {/^\s*url\s*=\s*/} $config->slurp;
        if ($url) {
            chomp $url;
            $url =~ s/^\s*url\s*=\s*//;
        }
        else {
            $url = '';
        }

        my $glob = "$file/.*.tag";
        $glob =~ s/\s/?/g;

        $repos{$file} = Group::Git::Repo->new(
            name => $file,
            git  => $url,
            tags => {
                map { m{/[.](.*?)[.]tag$}; $1 => 1 }
                glob $glob
            },
        );

        for my $tag (keys %{ $repos{$file}->tags } ) {
            $tags{$tag}{$file} = 1;
        }
    }

    for my $tag (keys %tags) {
        $self->conf->{tags}{$tag} = [ sort keys %{ $tags{$tag} } ];
    }

    return \%repos;
}

sub cmd {
    my ($self, $type, $command, $project) = @_;
    return if !$project || !-d $project;

    local $CWD = $project;
    local @ARGV = @ARGV;
    my $cmd = join ' ', map { $self->shell_quote }
        grep { defined $_ && $_ ne '' }
        $type, $command, @ARGV;

    return scalar `$cmd`;
}

sub shell_quote {
    s{ ( [^\w\-./?*+] ) }{\\$1}gxms;
    return $_;
}

sub AUTOLOAD {

    # ignore the method if it is the DESTROY method
    return if $AUTOLOAD =~ /DESTROY$/;

    # make sure that this is being called as a method
    croak( "AUTOLOAD(): This function is not being called by a ref: $AUTOLOAD( ".join (', ', @_)." )\n" ) unless ref $_[0];

    # get the object
    my $self = shift;

    # get the function name sans package name
    my ($method) = $AUTOLOAD =~ /::([^:]+)$/;

    return $self->cmd($method, @_);
}

1;

__END__

=head1 NAME

Group::Git - Base module for group of git repository operations.

=head1 VERSION

This documentation refers to Group::Git version 0.7.7.

=head1 SYNOPSIS

   use Group::Git;

   my $group = Group::Git->new( conf => {...} );

   # pull remote versions for all repositories
   $group->pull();

   # any other arbitary command
   $group->log;

=head1 DESCRIPTION

This is the base module it will try to use all roles in the C<Group::Git::Cmd::*>
namespace. This allows the creation of new command by just putting a role in that
namespace. Classes may extend this class to implement their own methods for
finding repositories (eg L<Group::Git::Github>, L<Group::Git::Bitbucket>,
L<Group::Git::Gitosis> and L<Group::Git::Stash>)



( run in 2.628 seconds using v1.01-cache-2.11-cpan-5735350b133 )