| 1 | 6 | ▶ | use 5.008; # utf8 | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 6 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | package Git::Wrapper::Plus::Refs; | ||||||||||
| 7 | 6 | $Git::Wrapper::Plus::Refs::VERSION = '0.004010'; | |||||||||
| 8 | # ABSTRACT: Work with refs | ||||||||||
| 9 | |||||||||||
| 10 | 6 | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | |||||||||
| 11 | |||||||||||
| 12 | 6 | ▶ | use Moo qw( has ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | |||||||||||
| 30 | 6 | has 'git' => ( required => 1, is => ro => ); | |||||||||
| 31 | 6 | has 'support' => ( is => ro =>, lazy => 1, builder => 1 ); | |||||||||
| 32 | |||||||||||
| 33 | sub _build_support { | ||||||||||
| 34 | 4 | ▶ | my ( $self, ) = @_; | ||||||||
|
Subroutine
_build_support: called CC=1 SCAR=0.0
| |||||||||||
| 35 | 4 | require Git::Wrapper::Plus::Support; | |||||||||
| 36 | 4 | return Git::Wrapper::Plus::Support->new( git => $self->git ); | |||||||||
| 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 | sub _for_each_ref { | ||||||||||
| 63 | 12 | ▶ | my ( $self, $refspec, $callback ) = @_; | ||||||||
|
Subroutine
_for_each_ref: called CC=7 SCAR=25.2
| |||||||||||
| 64 | |||||||||||
| 65 | 12 | my $git_dir = $self->git->dir; | |||||||||
| 66 | |||||||||||
| 67 | # git for-each-ref refs/heads/** == | ||||||||||
| 68 | # for-each-ref refs/heads/* == | ||||||||||
| 69 | # ls-remote refs/heads/* + exclude refs/heads/*/* | ||||||||||
| 70 | # | ||||||||||
| 71 | # git for-each-refs refs/heads/ == | ||||||||||
| 72 | # ls-remote refs/heads/* | ||||||||||
| 73 | # | ||||||||||
| 74 | 12 | ▶ | if ( $self->support->supports_command('for-each-ref') ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | ## no critic (Compatibility::PerlMinimumVersionAndWhy) | ||||||||||
| 76 | 12 | ▶ | if ( $refspec =~ qr{\A(.*)/[*]{1,2}\z}msx ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | 11 | $refspec = $1; | |||||||||
| 78 | } | ||||||||||
| 79 | 12 | for my $line ( $self->git->for_each_ref($refspec) ) { | |||||||||
| 80 | 27 | ▶ | if ( $line =~ qr{ \A ([^ ]+) [^\t]+ \t ( .+ ) \z }msx ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 27 | $callback->( $1, $2 ); | |||||||||
| 82 | 27 | next; | |||||||||
| 83 | } | ||||||||||
| 84 | 0 | require Carp; | |||||||||
| 85 | 0 | Carp::confess( 'Regexp failed to parse a line from `git for-each-ref` :' . $line ); | |||||||||
| 86 | } | ||||||||||
| 87 | 12 | return; | |||||||||
| 88 | } | ||||||||||
| 89 | 0 | for my $line ( $self->git->ls_remote( $git_dir, $refspec ) ) { | |||||||||
| 90 | ## no critic (Compatibility::PerlMinimumVersionAndWhy) | ||||||||||
| 91 | 0 | ▶ | if ( $line =~ qr{ \A ([^\t]+) \t ( .+ ) \z }msx ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | 0 | $callback->( $1, $2 ); | |||||||||
| 93 | 0 | next; | |||||||||
| 94 | } | ||||||||||
| 95 | 0 | require Carp; | |||||||||
| 96 | 0 | Carp::confess( 'Regexp failed to parse a line from `git ls-remote` :' . $line ); | |||||||||
| 97 | } | ||||||||||
| 98 | 0 | return; | |||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | |||||||||||
| 102 | |||||||||||
| 103 | |||||||||||
| 104 | |||||||||||
| 105 | |||||||||||
| 106 | |||||||||||
| 107 | |||||||||||
| 108 | |||||||||||
| 109 | |||||||||||
| 110 | |||||||||||
| 111 | |||||||||||
| 112 | |||||||||||
| 113 | |||||||||||
| 114 | |||||||||||
| 115 | |||||||||||
| 116 | |||||||||||
| 117 | sub refs { | ||||||||||
| 118 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
refs: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 119 | 0 | return $self->get_ref('refs/**'); | |||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | |||||||||||
| 123 | |||||||||||
| 124 | |||||||||||
| 125 | |||||||||||
| 126 | |||||||||||
| 127 | |||||||||||
| 128 | |||||||||||
| 129 | |||||||||||
| 130 | |||||||||||
| 131 | |||||||||||
| 132 | |||||||||||
| 133 | |||||||||||
| 134 | sub get_ref { | ||||||||||
| 135 | 12 | ▶ | my ( $self, $refspec ) = @_; | ||||||||
|
Subroutine
get_ref: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 136 | 12 | my @out; | |||||||||
| 137 | $self->_for_each_ref( | ||||||||||
| 138 | $refspec => sub { | ||||||||||
| 139 | 27 | ▶ | my ( $sha_one, $refname ) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 140 | 27 | push @out, $self->_mk_ref( $sha_one, $refname ); | |||||||||
| 141 | }, | ||||||||||
| 142 | 12 | ); | |||||||||
| 143 | 12 | return @out; | |||||||||
| 144 | } | ||||||||||
| 145 | |||||||||||
| 146 | sub _mk_ref { | ||||||||||
| 147 | 27 | ▶ | my ( $self, undef, $name ) = @_; | ||||||||
|
Subroutine
_mk_ref: called CC=1 SCAR=0.0
| |||||||||||
| 148 | 27 | require Git::Wrapper::Plus::Ref; | |||||||||
| 149 | 27 | return Git::Wrapper::Plus::Ref->new( | |||||||||
| 150 | git => $self->git, | ||||||||||
| 151 | name => $name, | ||||||||||
| 152 | ); | ||||||||||
| 153 | } | ||||||||||
| 154 | 6 | ▶ | no Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 155 | |||||||||||
| 156 | 6 | 1; | |||||||||
| 157 | |||||||||||
| 158 | __END__ | ||||||||||