lib/Git/Wrapper/Plus/Tags.pm

filter: Statementstmt 96.6% 58 / 60 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 100% 4 / 4 totaltotal 94.1% 81 / 86 SCAR 19.5
CC
7
Cov
93%
tags_for_rev
3.2
_grep_commit_pointers
3.0
tag_sha1_map
3.0
CRAP 7.0
« lib/Git/Wrapper/Plus.pm ↑ Summary lib/Git/Wrapper/Plus/Branches.pm »
1 3 ▶use 5.008; # utf8
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Git::Wrapper::Plus::Tags;
7 3 $Git::Wrapper::Plus::Tags::VERSION = '0.004010';
8 # ABSTRACT: Extract all tags from a repository
9  
10 3 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24 3 ▶use Moo qw( has );
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65 3 has 'git' => ( is => ro =>, required => 1 );
66  
67  
68  
69  
70  
71  
72  
73 3 has 'refs' => ( is => ro =>, lazy => 1, builder => 1 );
74  
75 sub _build_refs {
76 1 ▶ my ($self) = @_;
Subroutine _build_refs: called CC=1 SCAR=0.0
77 1 require Git::Wrapper::Plus::Refs;
78 1 return Git::Wrapper::Plus::Refs->new( git => $self->git );
79 }
80  
81 sub _to_tag {
82 10 ▶ my ( undef, $ref ) = @_;
Subroutine _to_tag: called CC=1 SCAR=0.0
83 10 require Git::Wrapper::Plus::Ref::Tag;
84 10 return Git::Wrapper::Plus::Ref::Tag->new_from_Ref($ref);
85 }
86  
87 sub _to_tags {
88 5 ▶ my ( $self, @refs ) = @_;
Subroutine _to_tags: called CC=1 SCAR=0.0
89 5 return map { $self->_to_tag($_) } @refs;
90 }
91  
92 # There's 2 types of results that come back from git ls-remote
93 #
94 # tags, and heavy tags ( usually annotations )
95 #
96 # puretags look like
97 #
98 # abffab foo # pointer to the commit
99 #
100 # While heavy tags come in pairs
101 #
102 # fabfab foo # heavy tag pointer
103 # abffab foo^{} # pointer to the actual commit
104 #
105 # However, we don't really care about the second half of the latter kind.
106 #
107 sub _grep_commit_pointers {
108 5 ▶ my ( undef, @refs ) = @_;
Subroutine _grep_commit_pointers: called CC=3 SCAR=11.0
109 5 my (@out);
110 5 for my $ref (@refs) {
111 10 ▶ next if $ref->name =~ /[^][{][}]\z/msx;
Branch: 1 branch
BranchTrueFalseTotal
if $ref->name =~ /[^][{][}]\z/msx 0 10 10
112 10 push @out, $ref;
113 }
114 5 return @out;
115 }
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127 sub tags {
128 5 ▶ my ($self) = @_;
Subroutine tags: called CC=1 SCAR=0.0
Pod documented
129 5 return $self->get_tag(q[**]);
130 }
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156 sub get_tag {
157 5 ▶ my ( $self, $name ) = @_;
Subroutine get_tag: called CC=1 SCAR=0.0
Pod documented
158 5 return $self->_to_tags( $self->_grep_commit_pointers( $self->refs->get_ref( 'refs/tags/' . $name ) ) );
159 }
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173 sub tag_sha1_map {
174 3 ▶ my ($self) = @_;
Subroutine tag_sha1_map: called CC=3 SCAR=11.0
Pod documented
175  
176 3 my %hash;
177 3 for my $tag ( $self->tags ) {
178 6 my $sha_one = $tag->sha1;
179 6 ▶ if ( not exists $hash{$sha_one} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $hash{$sha_one}) 3 3 6
180 3 $hash{$sha_one} = [];
181 }
182 6 push @{ $hash{$sha_one} }, $tag;
183 }
184 3 return \%hash;
185 }
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199 sub tags_for_rev {
200 2 ▶ my ( $self, $rev ) = @_;
Subroutine tags_for_rev: called CC=3 SCAR=11.7
Pod documented
201 2 my (@shas) = $self->git->rev_parse($rev);
202 2 ▶ if ( scalar @shas != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @shas != 1) 0 2 2
203 0 require Carp;
204 0 Carp::croak("Could not resolve a SHA1 from rev $rev");
205 }
206 2 my ($sha) = shift @shas;
207 2 my $map = $self->tag_sha1_map;
208 2 ▶ return unless exists $map->{$sha};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $map->{$sha} 0 2 2
209 2 return @{ $map->{$sha} };
210 }
211  
212 3 ▶no Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
213  
214 3 1;
215  
216 __END__
« lib/Git/Wrapper/Plus.pm ↑ Summary lib/Git/Wrapper/Plus/Branches.pm »