File Coverage

blib/lib/Git/Sub.pm
Criterion Covered Total %
statement 34 39 87.1
branch 4 8 50.0
condition 2 3 66.6
subroutine 8 8 100.0
pod n/a
total 48 58 82.7


line stmt bran cond sub pod time code
1 1     1   29065 use strict;
  1         1  
  1         21  
2 1     1   3 use warnings;
  1         1  
  1         36  
3             package Git::Sub;
4             # ABSTRACT: git commands imported as System::Sub subs in git:: namespace
5             $Git::Sub::VERSION = '0.162920';
6 1     1   366 use System::Sub ();
  1         27599  
  1         20  
7 1     1   5 use File::Which ();
  1         1  
  1         57  
8              
9             my $GIT;
10              
11             sub import
12             {
13 2 100   2   381 return if @_ <= 1;
14 1         1 shift;
15              
16 1 50       3 if ($_[0] eq 'git') {
17 0 0       0 unless (@_ > 2) {
18 0         0 require Carp;
19 0         0 Carp::croak('missing value for "git" parameter');
20             }
21 0         0 $GIT = $_[1];
22 0         0 splice @_, 0, 2;
23             }
24              
25             # The remaining arguments are names of subs
26 1     1   3 no strict 'refs';
  1         1  
  1         99  
27 1         4 while (@_) {
28 1         2 my $fq_name = 'git::'.shift;
29 1 50       1 next if defined *{$fq_name};
  1         10  
30             # TODO: check names: /[a-z_]/
31             # See subs.pm
32 1         2 *{$fq_name} = \&{$fq_name};
  1         1464  
  1         3  
33             }
34             }
35              
36             package # no indexing
37             git;
38              
39             use subs
40             # Common commands
41 1         5 qw(version
42             commit tag push add rm branch checkout clone fetch init log
43             mv notes pull push rebase reset revert status),
44             # Ancillary commands
45             qw(config filter_branch prune remote repack),
46             # Interrogator
47             qw(rev_parse),
48             # Plumbing: manipulation commands
49             qw(apply checkout_index commit_tree hash_object index_pack merge_file
50             merge_index mktag mktree pack_objects prune_packed read_tree
51             symbolic_ref unpack_objects update_index update_ref write_tree),
52             # Plumbing: interrogation commands
53             qw(cat_file diff_files diff_index diff_tree for_each_ref ls_files
54             ls_remote ls_tree merge_base name_rev pack_redundant rev_list
55             show_index show_ref tar_tree unpack_file var verify_pack),
56             # Plumbing: synching repositories
57             qw(fetch_pack send_pack update_server_info parse_remote receive_pack
58             upload_archive upload_pack)
59 1     1   422 ;
  1         16  
60              
61             sub AUTOLOAD
62             {
63 14     14   195581 my $git_cmd = our $AUTOLOAD;
64 14         69 $git_cmd = substr($git_cmd, 1+rindex($git_cmd, ':'));
65 14         39 $git_cmd =~ tr/_/-/; # Seems to the first time I use tr// in the last 2 years
66 14   66     66 $GIT ||= File::Which::which('git');
67              
68 14         366 System::Sub->import($AUTOLOAD, [
69             '$0' => $GIT,
70             '@ARGV' => [ $git_cmd ],
71             ]);
72 14         1243 goto &$AUTOLOAD
73             }
74              
75             1;
76             __END__