File Coverage

blib/lib/App/Git/Workflow/Repository.pm
Criterion Covered Total %
statement 27 55 49.0
branch 0 18 0.0
condition 0 13 0.0
subroutine 9 12 75.0
pod 2 2 100.0
total 38 100 38.0


line stmt bran cond sub pod time code
1             package App::Git::Workflow::Repository;
2              
3             # Created on: 2014-08-18 06:54:14
4             # Create by: Ivan Wills
5             # $Id$
6             # $Revision$, $HeadURL$, $Date$
7             # $Revision$, $Source$, $Date$
8              
9 23     23   166 use strict;
  23         48  
  23         716  
10 23     23   134 use warnings;
  23         41  
  23         681  
11 23     23   114 use version;
  23         42  
  23         157  
12 23     23   1593 use Carp;
  23         49  
  23         1325  
13 23     23   158 use Data::Dumper qw/Dumper/;
  23         62  
  23         1059  
14 23     23   219 use English qw/ -no_match_vars /;
  23         47  
  23         147  
15 23     23   20776 use Git;
  23         483745  
  23         1746  
16 23     23   237 use File::Spec;
  23         56  
  23         746  
17 23     23   135 use base qw/Exporter/;
  23         55  
  23         15228  
18              
19             our $VERSION = version->new(1.1.16);
20             our @EXPORT = qw/git/;
21             our @EXPORT_OK = qw//;
22             our %EXPORT_TAGS = ();
23             our $last;
24              
25             sub new {
26 0     0 1   my $class = shift;
27 0   0       my $self = { repository => @_ || undef };
28 0 0         if (!$self->{repository}) {
29 0           my @dir = File::Spec->splitdir( File::Spec->rel2abs( File::Spec->curdir ) );
30 0   0       while (
31             @dir > 1
32             && ! -d File::Spec->catdir(@dir, '.git')
33             ) {
34 0           pop @dir;
35             }
36 0   0       $self->{repository} = File::Spec->catdir(@dir) || '';
37 0 0         die "Couldn't find the git repository! '$self->{repository}'\n" if !-d $self->{repository};
38             }
39 0           $self->{git} = Git->repository(Directory => $self->{repository});
40              
41 0           bless $self, $class;
42              
43 0           return $last = $self;
44             }
45              
46             sub git {
47 0   0 0 1   return $last || App::Git::Workflow::Repository->new;
48             }
49              
50             our $AUTOLOAD;
51             sub AUTOLOAD {
52 0     0     my $self = shift;
53              
54 0           my $called = $AUTOLOAD;
55 0           $called =~ s/.*:://;
56 0           $called =~ s/_/-/g;
57              
58 0 0         if ($ENV{REPO_RECORD}) {
59 0           open my $fh, '>>', '/tmp/repo-record.txt';
60 0           my ($result, @result);
61 0 0         if (wantarray) {
62 0           @result = $self->{git}->command($called, @_);
63             }
64             else {
65 0           $result = $self->{git}->command($called, @_);
66             }
67 0           print {$fh} Dumper [$called, \@_, { scalar => $result, array => \@result }];
  0            
68 0 0         return wantarray ? @result : $result;
69             }
70              
71 0 0 0       return if !$self || !$self->{git};
72              
73             warn "running : " . (
74             $self->{git}->can($called)
75             ? "git->$called(@_)"
76             : "git->command($called, @_)"
77 0 0         ) . "\n" if $ENV{GW_VERBOSE};
    0          
78              
79             return $self->{git}->can($called)
80             ? $self->{git}->$called(@_)
81 0 0         : $self->{git}->command($called, @_);
82             }
83              
84             1;
85              
86             __END__
87              
88             =head1 NAME
89              
90             App::Git::Workflow::Repository - A basic wrapper around GIT
91              
92             =head1 VERSION
93              
94             This documentation refers to App::Git::Workflow::Repository version 1.1.16
95              
96             =head1 SYNOPSIS
97              
98             use App::Git::Workflow::Repository qw/git/;
99              
100             # get the git object based on the current directory
101             my $git = git();
102              
103             # call git sub commands
104             $git->log('--oneline');
105             $git->show('123ABC');
106             $git->status();
107              
108             =head1 DESCRIPTION
109              
110             This is a thin wrapper around L<Git> that will default to using the current
111             directory for C<git>, adds a simple way of calling git sub-commands
112             as methods.
113              
114             =head1 SUBROUTINES/METHODS
115              
116             =head3 C<new (%options)>
117              
118             Returns a new App::Git::Workflow::Repository
119              
120             =head2 C<git ()>
121              
122             Singleton to get the last created C<App::Git::Workflow::Repository> object or
123             create a new one.
124              
125             =head1 DIAGNOSTICS
126              
127             =head1 CONFIGURATION AND ENVIRONMENT
128              
129             =head1 DEPENDENCIES
130              
131             =head1 INCOMPATIBILITIES
132              
133             =head1 BUGS AND LIMITATIONS
134              
135             There are no known bugs in this module.
136              
137             Please report problems to Ivan Wills (ivan.wills@gmail.com).
138              
139             Patches are welcome.
140              
141             =head1 AUTHOR
142              
143             Ivan Wills - (ivan.wills@gmail.com)
144              
145             =head1 LICENSE AND COPYRIGHT
146              
147             Copyright (c) 2014 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077).
148             All rights reserved.
149              
150             This module is free software; you can redistribute it and/or modify it under
151             the same terms as Perl itself. See L<perlartistic>. This program is
152             distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
153             without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
154             PARTICULAR PURPOSE.
155              
156             =cut