File Coverage

blib/lib/Git/Sub.pm
Criterion Covered Total %
statement 35 40 87.5
branch 4 8 50.0
condition 2 3 66.6
subroutine 8 8 100.0
pod n/a
total 49 59 83.0


line stmt bran cond sub pod time code
1 1     1   36899 use strict;
  1         2  
  1         42  
2 1     1   5 use warnings;
  1         1  
  1         52  
3             package Git::Sub;
4             # ABSTRACT: git commands imported as System::Sub subs in git:: namespace
5             $Git::Sub::VERSION = '0.163320';
6 1     1   553 use System::Sub ();
  1         34916  
  1         21  
7 1     1   7 use File::Which ();
  1         1  
  1         70  
8              
9             my $GIT;
10              
11             sub import
12             {
13 2 100   2   511 return if @_ <= 1;
14 1         2 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   4 no strict 'refs';
  1         1  
  1         124  
27 1         5 while (@_) {
28 1         2 my $fq_name = 'git::'.shift;
29 1 50       2 next if defined *{$fq_name};
  1         15  
30             # TODO: check names: /[a-z_]/
31             # See subs.pm
32 1         1 *{$fq_name} = \&{$fq_name};
  1         1654  
  1         4  
33             }
34             }
35              
36             package # no indexing
37             git;
38              
39             use subs
40             # Common commands
41 1         6 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   566 ;
  1         21  
60              
61             sub AUTOLOAD
62             {
63 18     18   344529 my $git_cmd = our $AUTOLOAD;
64 18         86 my $git_sub = $git_cmd = substr($git_cmd, 1+rindex($git_cmd, ':'));
65 18         49 $git_cmd =~ tr/_/-/; # Seems to the first time I use tr// in the last 2 years
66 18   66     85 $GIT ||= File::Which::which('git');
67              
68 18         369 delete $git::{$git_sub};
69 18         235 System::Sub->import($AUTOLOAD, [
70             '$0' => $GIT,
71             '@ARGV' => [ $git_cmd ],
72             ]);
73 18         1710 goto &$AUTOLOAD
74             }
75              
76             1;
77             __END__