| 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::Branches; | ||||||||||
| 7 | 3 | $Git::Wrapper::Plus::Branches::VERSION = '0.004010'; | |||||||||
| 8 | # ABSTRACT: Extract branches from Git | ||||||||||
| 9 | |||||||||||
| 10 | 3 | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | |||||||||
| 11 | |||||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 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 | 3 | ▶ | use Moo qw( has ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 55 | 3 | ▶ | use Git::Wrapper::Plus::Util qw(exit_status_handler); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 56 | |||||||||||
| 57 | |||||||||||
| 58 | |||||||||||
| 59 | |||||||||||
| 60 | |||||||||||
| 61 | |||||||||||
| 62 | |||||||||||
| 63 | |||||||||||
| 64 | |||||||||||
| 65 | |||||||||||
| 66 | |||||||||||
| 67 | 3 | has 'git' => ( is => ro =>, required => 1 ); | |||||||||
| 68 | 3 | has 'refs' => ( is => ro =>, lazy => 1, builder => 1 ); | |||||||||
| 69 | |||||||||||
| 70 | sub _build_refs { | ||||||||||
| 71 | 1 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_build_refs: called CC=1 SCAR=0.0
| |||||||||||
| 72 | 1 | require Git::Wrapper::Plus::Refs; | |||||||||
| 73 | 1 | return Git::Wrapper::Plus::Refs->new( git => $self->git ); | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | sub _to_branch { | ||||||||||
| 77 | 7 | ▶ | my ( undef, $ref ) = @_; | ||||||||
|
Subroutine
_to_branch: called CC=1 SCAR=0.0
| |||||||||||
| 78 | 7 | require Git::Wrapper::Plus::Ref::Branch; | |||||||||
| 79 | 7 | return Git::Wrapper::Plus::Ref::Branch->new_from_Ref($ref); | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | sub _to_branches { | ||||||||||
| 83 | 3 | ▶ | my ( $self, @refs ) = @_; | ||||||||
|
Subroutine
_to_branches: called CC=1 SCAR=0.0
| |||||||||||
| 84 | 3 | return map { $self->_to_branch($_) } @refs; | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | |||||||||||
| 88 | |||||||||||
| 89 | |||||||||||
| 90 | |||||||||||
| 91 | |||||||||||
| 92 | |||||||||||
| 93 | |||||||||||
| 94 | |||||||||||
| 95 | |||||||||||
| 96 | |||||||||||
| 97 | sub branches { | ||||||||||
| 98 | 2 | ▶ | my ( $self, ) = @_; | ||||||||
|
Subroutine
branches: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 99 | 2 | return $self->get_branch(q[**]); | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | |||||||||||
| 103 | |||||||||||
| 104 | |||||||||||
| 105 | |||||||||||
| 106 | |||||||||||
| 107 | |||||||||||
| 108 | |||||||||||
| 109 | |||||||||||
| 110 | |||||||||||
| 111 | |||||||||||
| 112 | |||||||||||
| 113 | |||||||||||
| 114 | |||||||||||
| 115 | |||||||||||
| 116 | |||||||||||
| 117 | |||||||||||
| 118 | |||||||||||
| 119 | |||||||||||
| 120 | |||||||||||
| 121 | |||||||||||
| 122 | sub get_branch { | ||||||||||
| 123 | 3 | ▶ | my ( $self, $name ) = @_; | ||||||||
|
Subroutine
get_branch: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 124 | 3 | return $self->_to_branches( $self->refs->get_ref( 'refs/heads/' . $name ) ); | |||||||||
| 125 | } | ||||||||||
| 126 | |||||||||||
| 127 | sub _current_branch_name { | ||||||||||
| 128 | 2 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_current_branch_name: called CC=3 SCAR=11.0
| |||||||||||
| 129 | 2 | my (@current_names); | |||||||||
| 130 | return unless exit_status_handler( | ||||||||||
| 131 | sub { | ||||||||||
| 132 | 2 | ▶ | (@current_names) = $self->git->symbolic_ref('HEAD'); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 133 | }, | ||||||||||
| 134 | { | ||||||||||
| 135 | 1 | ▶ | 128 => sub { return }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 136 | }, | ||||||||||
| 137 | 2 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 138 | 1 | for (@current_names) { | |||||||||
| 139 | 1 | $_ =~ s{\A refs/heads/ }{}msx; | |||||||||
| 140 | } | ||||||||||
| 141 | 1 | return @current_names; | |||||||||
| 142 | |||||||||||
| 143 | } | ||||||||||
| 144 | |||||||||||
| 145 | |||||||||||
| 146 | |||||||||||
| 147 | |||||||||||
| 148 | |||||||||||
| 149 | |||||||||||
| 150 | |||||||||||
| 151 | |||||||||||
| 152 | |||||||||||
| 153 | |||||||||||
| 154 | |||||||||||
| 155 | |||||||||||
| 156 | |||||||||||
| 157 | |||||||||||
| 158 | sub current_branch { | ||||||||||
| 159 | 2 | ▶ | my ( $self, ) = @_; | ||||||||
|
Subroutine
current_branch: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||
| 160 | 2 | my ($ref) = $self->_current_branch_name; | |||||||||
| 161 | 2 | ▶ | return if not $ref; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 162 | 1 | my (@items) = $self->get_branch($ref); | |||||||||
| 163 | 1 | ▶ | return shift @items if 1 == @items; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 164 | 0 | require Carp; | |||||||||
| 165 | 0 | Carp::confess( 'get_branch(' . $ref . ') returned multiple values. Cannot determine current branch' ); | |||||||||
| 166 | } | ||||||||||
| 167 | |||||||||||
| 168 | 3 | ▶ | no Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 169 | |||||||||||
| 170 | 3 | 1; | |||||||||
| 171 | |||||||||||
| 172 | __END__ | ||||||||||